use of org.springsource.ide.eclipse.commons.livexp.core.LiveVariable in project eclipse-integration-commons by spring-projects.
the class SwtConnect method connect.
public static void connect(Text text, LiveVariable<String> model) {
if (!text.isDisposed()) {
text.addDisposeListener(de -> model.dispose());
ModifyListener widgetListener = (me) -> {
if (!text.isDisposed()) {
model.setValue(text.getText());
}
};
text.addModifyListener(widgetListener);
Disposable disconnect = model.onChange(UIValueListener.from((e, v) -> {
String oldText = text.getText();
String newText = model.getValue();
if (newText == null) {
newText = "";
}
if (!oldText.equals(newText)) {
text.setText(newText);
}
}));
text.addDisposeListener(de -> disconnect.dispose());
model.onDispose(de -> text.removeModifyListener(widgetListener));
}
}
Aggregations