Adjustments for wizard sections
This commit is contained in:
@@ -19,6 +19,8 @@ import org.eclipse.swt.events.SelectionListener;
|
||||
import org.eclipse.swt.widgets.Button;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.springsource.ide.eclipse.commons.livexp.Activator;
|
||||
import org.springsource.ide.eclipse.commons.livexp.core.LiveExpression;
|
||||
import org.springsource.ide.eclipse.commons.livexp.ui.util.SwtConnect;
|
||||
|
||||
/**
|
||||
* A section containing a single clickable button.
|
||||
@@ -30,6 +32,7 @@ public class ButtonSection extends WizardPageSection {
|
||||
private String label;
|
||||
private String tooltip;
|
||||
private Callable<Void> clickHandler;
|
||||
private LiveExpression<Boolean> enabler = LiveExpression.constant(true);
|
||||
|
||||
public ButtonSection(IPageWithSections owner, String label, Runnable clickHandler) {
|
||||
this(owner, label, () -> {
|
||||
@@ -67,6 +70,8 @@ public class ButtonSection extends WizardPageSection {
|
||||
widgetSelected(arg0);
|
||||
}
|
||||
});
|
||||
|
||||
SwtConnect.connectEnablement(button, enabler);
|
||||
}
|
||||
|
||||
public ButtonSection tooltip(String tooltip) {
|
||||
@@ -82,4 +87,8 @@ public class ButtonSection extends WizardPageSection {
|
||||
GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(button);
|
||||
}
|
||||
|
||||
public ButtonSection setEnabler(LiveExpression<Boolean> enabler) {
|
||||
this.enabler = enabler;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,8 +117,8 @@ public class ChooseOneSection<T extends Ilabelable> extends WizardPageSection {
|
||||
tv.refresh(true);
|
||||
}));
|
||||
|
||||
chosen.addListener(new ValueListener<T>() {
|
||||
public void gotValue(LiveExpression<T> exp, T value) {
|
||||
chosen.addListener(new UIValueListener<T>() {
|
||||
public void uiGotValue(LiveExpression<T> exp, T value) {
|
||||
if (value==null) {
|
||||
tv.setSelection(StructuredSelection.EMPTY);
|
||||
} else {
|
||||
|
||||
@@ -14,6 +14,7 @@ import org.eclipse.core.runtime.Assert;
|
||||
import org.eclipse.jface.layout.GridDataFactory;
|
||||
import org.eclipse.jface.layout.GridLayoutFactory;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.custom.StyledText;
|
||||
import org.eclipse.swt.events.ModifyEvent;
|
||||
import org.eclipse.swt.events.ModifyListener;
|
||||
import org.eclipse.swt.graphics.FontMetrics;
|
||||
@@ -22,12 +23,11 @@ import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
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.ValidationResult;
|
||||
import org.springsource.ide.eclipse.commons.livexp.core.Validator;
|
||||
import org.springsource.ide.eclipse.commons.livexp.core.ValueListener;
|
||||
|
||||
/**
|
||||
* Displays a short textual desciption.
|
||||
@@ -80,7 +80,7 @@ public class DescriptionSection extends WizardPageSection {
|
||||
if (isReadOnly) {
|
||||
swtStyle |= SWT.READ_ONLY;
|
||||
}
|
||||
final Text text = new Text(composite, swtStyle);
|
||||
final StyledText text = new StyledText(composite, swtStyle);
|
||||
configureTextWidget(text);
|
||||
if (!isReadOnly) {
|
||||
text.addModifyListener(new ModifyListener() {
|
||||
@@ -115,8 +115,8 @@ public class DescriptionSection extends WizardPageSection {
|
||||
|
||||
// GridDataFactory.fillDefaults().align(SWT.BEGINNING, SWT.BEGINNING).applyTo(fieldNameLabel);
|
||||
|
||||
this.model.addListener(new ValueListener<String>() {
|
||||
public void gotValue(LiveExpression<String> exp, String value) {
|
||||
this.model.addListener(new UIValueListener<String>() {
|
||||
public void uiGotValue(LiveExpression<String> exp, String value) {
|
||||
if (!text.isDisposed()) {
|
||||
String oldText = text.getText();
|
||||
if (!oldText.equals(value)) {
|
||||
@@ -129,7 +129,7 @@ public class DescriptionSection extends WizardPageSection {
|
||||
});
|
||||
}
|
||||
|
||||
protected void configureTextWidget(Text text) {
|
||||
protected void configureTextWidget(StyledText text) {
|
||||
}
|
||||
|
||||
protected int preferredNumberOfLines() {
|
||||
|
||||
@@ -28,6 +28,7 @@ import org.eclipse.swt.events.SelectionAdapter;
|
||||
import org.eclipse.swt.events.SelectionEvent;
|
||||
import org.eclipse.swt.events.SelectionListener;
|
||||
import org.eclipse.swt.widgets.Button;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
import org.eclipse.swt.widgets.Label;
|
||||
import org.eclipse.swt.widgets.Text;
|
||||
import org.springsource.ide.eclipse.commons.livexp.core.HighlightedText;
|
||||
@@ -80,6 +81,18 @@ public class SwtConnect {
|
||||
}
|
||||
}
|
||||
|
||||
public static void connectEnablement(Control control, LiveExpression<Boolean> enabler) {
|
||||
if (!control.isDisposed()) {
|
||||
control.setEnabled(enabler.getValue());
|
||||
control.addDisposeListener(de -> enabler.dispose());
|
||||
Disposable disconnect = enabler.onChange(UIValueListener.from((e,v) -> {
|
||||
control.setEnabled(e.getValue());
|
||||
System.out.println("Apply enablement changed: " + e.getValue());
|
||||
}));
|
||||
control.addDisposeListener(de -> disconnect.dispose());
|
||||
}
|
||||
}
|
||||
|
||||
public static void connect(Text text, LiveVariable<String> model) {
|
||||
connect(text, model, false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user