SwtConnect utilities moved to commons.livexp

This commit is contained in:
Kris De Volder
2017-11-10 09:44:36 -08:00
parent aa96122d5c
commit fae25af3eb
2 changed files with 1 additions and 68 deletions

View File

@@ -43,9 +43,9 @@ import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.ui.texteditor.ITextEditor;
import org.springframework.tooling.ls.eclipse.gotosymbol.GotoSymbolPlugin;
import org.springframework.tooling.ls.eclipse.gotosymbol.util.SwtConnect;
import org.springsource.ide.eclipse.commons.livexp.core.UIValueListener;
import org.springsource.ide.eclipse.commons.livexp.ui.Disposable;
import org.springsource.ide.eclipse.commons.livexp.ui.util.SwtConnect;
@SuppressWarnings("restriction")
public class GotoSymbolDialog extends PopupDialog {

View File

@@ -1,67 +0,0 @@
/*******************************************************************************
* Copyright (c) 2017 Pivotal, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Pivotal, Inc. - initial API and implementation
*******************************************************************************/
package org.springframework.tooling.ls.eclipse.gotosymbol.util;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.springsource.ide.eclipse.commons.livexp.core.LiveExpression;
import org.springsource.ide.eclipse.commons.livexp.core.LiveVariable;
import org.springsource.ide.eclipse.commons.livexp.core.UIValueListener;
import org.springsource.ide.eclipse.commons.livexp.core.ValueListener;
/**
* Static helper methods for attaching LiveExps to SWT widgets.
*/
public class SwtConnect {
public static void connect(Text widget, LiveVariable<String> model) {
ModifyListener widgetListener = (ModifyEvent e) -> {
model.setValue(widget.getText());
};
ValueListener<String> modelListener = new UIValueListener<String>() {
@Override
protected void uiGotValue(LiveExpression<String> exp, String value) {
String newText = model.getValue();
if (newText==null) {
newText = "";
}
String oldText = widget.getText();
if (!newText.equals(oldText)) {
widget.setText(newText);
}
}
};
widget.addModifyListener(widgetListener);
model.addListener(modelListener);
widget.addDisposeListener(e -> {
model.removeListener(modelListener);
});
}
public static void connect(Label widget, LiveExpression<String> model) {
ValueListener<String> modelListener = new UIValueListener<String>() {
@Override
protected void uiGotValue(LiveExpression<String> exp, String value) {
String newText = model.getValue();
if (newText==null) {
newText = "";
}
widget.setText(newText);
}
};
model.addListener(modelListener);
widget.addDisposeListener(xx -> model.removeListener(modelListener));
}
}