|
29 | 29 | import java.util.Map;
|
30 | 30 | import java.util.concurrent.ConcurrentHashMap;
|
31 | 31 |
|
| 32 | +import javax.swing.Timer; |
| 33 | + |
| 34 | +import org.apache.commons.lang3.tuple.Pair; |
32 | 35 | import org.slf4j.Logger;
|
33 | 36 | import org.slf4j.LoggerFactory;
|
34 | 37 |
|
@@ -140,7 +143,11 @@ public void focusGained(FocusEvent event)
|
140 | 143 | processUIElementEvents = true;
|
141 | 144 | }
|
142 | 145 | };
|
| 146 | + |
| 147 | + private Timer setValueTimer; |
| 148 | + private boolean isInSetValueTimer = false; |
143 | 149 |
|
| 150 | + private List<Pair<String,String>> setValueList = new ArrayList<>(); |
144 | 151 | /**
|
145 | 152 | * Create a new controller and the gui of the form.
|
146 | 153 | *
|
@@ -170,6 +177,9 @@ public FormSidebarController(String resourceUrl, XComponentContext context, XWin
|
170 | 177 | isUnregistered = false;
|
171 | 178 | WollMuxEventHandler.getInstance().registerListener(this);
|
172 | 179 | }
|
| 180 | + setValueTimer = new Timer(250, e -> setValue()); |
| 181 | + setValueTimer.setCoalesce(true); |
| 182 | + setValueTimer.setRepeats(false); |
173 | 183 |
|
174 | 184 | }
|
175 | 185 |
|
@@ -202,8 +212,10 @@ public void onTextDocumentControllerInitialized(OnTextDocumentControllerInitiali
|
202 | 212 | initController(docController);
|
203 | 213 | }
|
204 | 214 |
|
| 215 | + private boolean initDone = false; |
205 | 216 | private void initController(TextDocumentController documentController)
|
206 | 217 | {
|
| 218 | + initDone = false; |
207 | 219 | if (documentController == null)
|
208 | 220 | {
|
209 | 221 | LOGGER.trace("{} notify(): documentController is NULL.", this.getClass().getSimpleName());
|
@@ -242,6 +254,7 @@ private void initController(TextDocumentController documentController)
|
242 | 254 | }
|
243 | 255 |
|
244 | 256 | unregisterListener();
|
| 257 | + initDone = true; |
245 | 258 | }
|
246 | 259 |
|
247 | 260 | private void scanExecCommands()
|
@@ -346,13 +359,46 @@ public void textChanged(TextEvent event)
|
346 | 359 | XControl txtField = UNO.XControl(event.Source);
|
347 | 360 | String id = (String) UnoProperty.getProperty(txtField.getModel(), UnoProperty.DEFAULT_CONTROL);
|
348 | 361 | String text = (String) UnoProperty.getProperty(txtField.getModel(), UnoProperty.TEXT);
|
349 |
| - setDocFormModelValue(id, text); |
| 362 | + if(initDone) |
| 363 | + { |
| 364 | + setValueList.add(Pair.of(id,text)); |
| 365 | + setValueTimer.restart(); |
| 366 | + } |
| 367 | + else |
| 368 | + { |
| 369 | + setDocFormModelValue(id, text); |
| 370 | + } |
350 | 371 | } catch (UnoHelperException e)
|
351 | 372 | {
|
352 | 373 | LOGGER.error("", e);
|
353 | 374 | }
|
354 | 375 | }
|
| 376 | + private void setValue() |
| 377 | + { |
| 378 | + isInSetValueTimer = true; |
| 379 | + List<Pair<String,String>> setValueListH = new ArrayList<>(); |
| 380 | + setValueListH.addAll(setValueList); |
| 381 | + setValueList.clear(); |
355 | 382 |
|
| 383 | + String id="", value="", idH = "", valueH; |
| 384 | + for (int i = 0; i < setValueListH.size(); i++) |
| 385 | + { |
| 386 | + valueH = setValueListH.get(i).getValue(); |
| 387 | + idH = setValueListH.get(i).getKey(); |
| 388 | + if(!id.equals(idH)) |
| 389 | + { |
| 390 | + if(!id.equals("")) |
| 391 | + setDocFormModelValue(id, value); |
| 392 | + id = idH; |
| 393 | + } |
| 394 | + value = valueH; |
| 395 | + } |
| 396 | + if(!id.equals("")) |
| 397 | + setDocFormModelValue(id, value); |
| 398 | + isInSetValueTimer = false; |
| 399 | + if(setValueList.size()>0) |
| 400 | + setValueTimer.restart(); |
| 401 | + } |
356 | 402 | /**
|
357 | 403 | * Update the form model with a new value. Don't handle value changes on the control which
|
358 | 404 | * triggered this action.
|
|
0 commit comments