Search in sources :

Example 1 with LiveVariable

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));
    }
}
Also used : Disposable(org.springsource.ide.eclipse.commons.livexp.ui.Disposable) Text(org.eclipse.swt.widgets.Text) StyledString(org.eclipse.jface.viewers.StyledString) Stylers(org.springsource.ide.eclipse.commons.livexp.ui.Stylers) Assert(org.eclipse.core.runtime.Assert) Filter(org.springsource.ide.eclipse.commons.livexp.util.Filter) UIValueListener(org.springsource.ide.eclipse.commons.livexp.core.UIValueListener) ILabelProvider(org.eclipse.jface.viewers.ILabelProvider) StyledCellLabelProvider(org.eclipse.jface.viewers.StyledCellLabelProvider) Styler(org.eclipse.jface.viewers.StyledString.Styler) LiveExpression(org.springsource.ide.eclipse.commons.livexp.core.LiveExpression) ViewerCell(org.eclipse.jface.viewers.ViewerCell) ModifyListener(org.eclipse.swt.events.ModifyListener) Duration(java.time.Duration) TreeViewer(org.eclipse.jface.viewers.TreeViewer) Filters(org.springsource.ide.eclipse.commons.livexp.util.Filters) ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) ValueListener(org.springsource.ide.eclipse.commons.livexp.core.ValueListener) Label(org.eclipse.swt.widgets.Label) LabelProvider(org.eclipse.jface.viewers.LabelProvider) LiveVariable(org.springsource.ide.eclipse.commons.livexp.core.LiveVariable) IRegion(org.eclipse.jface.text.IRegion) Disposable(org.springsource.ide.eclipse.commons.livexp.ui.Disposable) ModifyListener(org.eclipse.swt.events.ModifyListener) StyledString(org.eclipse.jface.viewers.StyledString)

Aggregations

Duration (java.time.Duration)1 Assert (org.eclipse.core.runtime.Assert)1 IRegion (org.eclipse.jface.text.IRegion)1 ILabelProvider (org.eclipse.jface.viewers.ILabelProvider)1 ITreeContentProvider (org.eclipse.jface.viewers.ITreeContentProvider)1 LabelProvider (org.eclipse.jface.viewers.LabelProvider)1 StyledCellLabelProvider (org.eclipse.jface.viewers.StyledCellLabelProvider)1 StyledString (org.eclipse.jface.viewers.StyledString)1 Styler (org.eclipse.jface.viewers.StyledString.Styler)1 TreeViewer (org.eclipse.jface.viewers.TreeViewer)1 ViewerCell (org.eclipse.jface.viewers.ViewerCell)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1 Label (org.eclipse.swt.widgets.Label)1 Text (org.eclipse.swt.widgets.Text)1 LiveExpression (org.springsource.ide.eclipse.commons.livexp.core.LiveExpression)1 LiveVariable (org.springsource.ide.eclipse.commons.livexp.core.LiveVariable)1 UIValueListener (org.springsource.ide.eclipse.commons.livexp.core.UIValueListener)1 ValueListener (org.springsource.ide.eclipse.commons.livexp.core.ValueListener)1 Disposable (org.springsource.ide.eclipse.commons.livexp.ui.Disposable)1 Stylers (org.springsource.ide.eclipse.commons.livexp.ui.Stylers)1