Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bei Änderungen des Inhalts eines Textfeldes werden diese zwischengesp… #383

Open
wants to merge 1 commit into
base: WollMux_18.2
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -140,7 +143,11 @@ public void focusGained(FocusEvent event)
processUIElementEvents = true;
}
};

private Timer setValueTimer;
private boolean isInSetValueTimer = false;

private List<Pair<String,String>> setValueList = new ArrayList<>();
/**
* Create a new controller and the gui of the form.
*
Expand Down Expand Up @@ -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);

}

Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -242,6 +254,7 @@ private void initController(TextDocumentController documentController)
}

unregisterListener();
initDone = true;
}

private void scanExecCommands()
Expand Down Expand Up @@ -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<Pair<String,String>> 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.
Expand Down