From ef851f017c5fb02170a8fc0159128c6472dadf3f Mon Sep 17 00:00:00 2001 From: Ilhan Yesil Date: Thu, 18 Aug 2022 15:03:57 +0200 Subject: [PATCH] =?UTF-8?q?Bei=20=C3=84nderungen=20des=20Inhalts=20eines?= =?UTF-8?q?=20Textfeldes=20werden=20diese=20zwischengespeichert=20und=20?= =?UTF-8?q?=C3=BCber=20einen=20Timer=20ausgelesen=20und=20weiter=20verarbe?= =?UTF-8?q?itet.=20So=20wird=20verhindert,=20dass=20jeder=20einzelne=20Buc?= =?UTF-8?q?hstabe=20zu=20einer=20Berechnung=20des=20Gruppensichtbarkeiten?= =?UTF-8?q?=20f=C3=BChrt,=20sondern=20erst=20bei=20m=C3=B6glichst=20langen?= =?UTF-8?q?=20Texten,=20im=20Idealfall=20wenn=20der=20Text=20fertiggestell?= =?UTF-8?q?t=20wurde.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../form/sidebar/FormSidebarController.java | 48 ++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/de/muenchen/allg/itd51/wollmux/form/sidebar/FormSidebarController.java b/core/src/main/java/de/muenchen/allg/itd51/wollmux/form/sidebar/FormSidebarController.java index 4ba6098b1..e0270893e 100644 --- a/core/src/main/java/de/muenchen/allg/itd51/wollmux/form/sidebar/FormSidebarController.java +++ b/core/src/main/java/de/muenchen/allg/itd51/wollmux/form/sidebar/FormSidebarController.java @@ -29,6 +29,9 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import javax.swing.Timer; + +import org.apache.commons.lang3.tuple.Pair; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -140,7 +143,11 @@ public void focusGained(FocusEvent event) processUIElementEvents = true; } }; + + private Timer setValueTimer; + private boolean isInSetValueTimer = false; + private List> setValueList = new ArrayList<>(); /** * Create a new controller and the gui of the form. * @@ -170,6 +177,9 @@ public FormSidebarController(String resourceUrl, XComponentContext context, XWin isUnregistered = false; WollMuxEventHandler.getInstance().registerListener(this); } + setValueTimer = new Timer(50, e -> setValue()); + setValueTimer.setCoalesce(true); + setValueTimer.setRepeats(false); } @@ -202,8 +212,10 @@ public void onTextDocumentControllerInitialized(OnTextDocumentControllerInitiali initController(docController); } + private boolean initDone = false; private void initController(TextDocumentController documentController) { + initDone = false; if (documentController == null) { LOGGER.trace("{} notify(): documentController is NULL.", this.getClass().getSimpleName()); @@ -242,6 +254,7 @@ private void initController(TextDocumentController documentController) } unregisterListener(); + initDone = true; } private void scanExecCommands() @@ -346,13 +359,46 @@ public void textChanged(TextEvent event) XControl txtField = UNO.XControl(event.Source); String id = (String) UnoProperty.getProperty(txtField.getModel(), UnoProperty.DEFAULT_CONTROL); String text = (String) UnoProperty.getProperty(txtField.getModel(), UnoProperty.TEXT); - setDocFormModelValue(id, text); + if(initDone) + { + setValueList.add(Pair.of(id,text)); + setValueTimer.restart(); + } + else + { + setDocFormModelValue(id, text); + } } catch (UnoHelperException e) { LOGGER.error("", e); } } + private void setValue() + { + isInSetValueTimer = true; + List> setValueListH = new ArrayList<>(); + setValueListH.addAll(setValueList); + setValueList.clear(); + String id="", value="", idH = "", valueH; + for (int i = 0; i < setValueListH.size(); i++) + { + valueH = setValueListH.get(i).getValue(); + idH = setValueListH.get(i).getKey(); + if(!id.equals(idH)) + { + if(!id.equals("")) + setDocFormModelValue(id, value); + id = idH; + } + value = valueH; + } + if(!id.equals("")) + setDocFormModelValue(id, value); + isInSetValueTimer = false; + if(setValueList.size()>0) + setValueTimer.restart(); + } /** * Update the form model with a new value. Don't handle value changes on the control which * triggered this action.