diff --git a/eclipse-language-servers/org.springsource.ide.eclipse.commons.livexp/src/org/springsource/ide/eclipse/commons/livexp/ui/ChooseOneSection.java b/eclipse-language-servers/org.springsource.ide.eclipse.commons.livexp/src/org/springsource/ide/eclipse/commons/livexp/ui/ChooseOneSection.java index 940cb4f84..e46eb5433 100644 --- a/eclipse-language-servers/org.springsource.ide.eclipse.commons.livexp/src/org/springsource/ide/eclipse/commons/livexp/ui/ChooseOneSection.java +++ b/eclipse-language-servers/org.springsource.ide.eclipse.commons.livexp/src/org/springsource/ide/eclipse/commons/livexp/ui/ChooseOneSection.java @@ -29,6 +29,7 @@ import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Label; 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.ValueListener; @@ -37,24 +38,32 @@ public class ChooseOneSection extends WizardPageSection { private static final boolean DEBUG = (""+Platform.getLocation()).contains("kdvolder"); private String labelText; - private Ilabelable[] validChoices; + private LiveExpression validChoices; private LiveVariable chosen; private LiveExpression validator; private boolean vertical = false; - + + private Integer heightHint = null; + public ChooseOneSection(IPageWithSections owner, String labelText, T[] validChoices, LiveVariable chosen, LiveExpression validator ) { - super(owner); - this.labelText = labelText; - this.validChoices = validChoices; - this.chosen = chosen; - this.validator = validator; + this(owner, labelText, LiveExpression.constant(validChoices), chosen, validator); } + + public ChooseOneSection(IPageWithSections owner, String labelText, LiveExpression validChoices, + LiveVariable chosen, LiveExpression validator) { + super(owner); + this.labelText = labelText; + this.validChoices = validChoices; + this.chosen = chosen; + this.validator = validator; + + } @Override public LiveExpression getValidator() { @@ -80,7 +89,10 @@ public class ChooseOneSection extends WizardPageSection { layout.numColumns = (labelText==null||vertical)?1:2; layout.marginWidth = 0; composite.setLayout(layout); - GridDataFactory grab = GridDataFactory.fillDefaults().grab(true, true);//.hint(SWT.DEFAULT, 150); + GridDataFactory grab = GridDataFactory.fillDefaults().grab(true, true); + if (heightHint != null) { + grab = grab.hint(SWT.DEFAULT, heightHint); + } grab.applyTo(composite); composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); @@ -100,6 +112,11 @@ public class ChooseOneSection extends WizardPageSection { tv.setContentProvider(new ContentProvider()); tv.setLabelProvider(new SimpleLabelProvider()); tv.setInput(validChoices); + + validChoices.onChange(UIValueListener.from((e, v) -> { + tv.refresh(true); + })); + chosen.addListener(new ValueListener() { public void gotValue(LiveExpression exp, T value) { if (value==null) { @@ -140,7 +157,8 @@ public class ChooseOneSection extends WizardPageSection { public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { } public Object[] getElements(Object inputElement) { - return validChoices; + T[] value = validChoices.getValue(); + return value == null ? new Object[0] : value; } } @@ -148,4 +166,9 @@ public class ChooseOneSection extends WizardPageSection { vertical = true; return this; } + + public void setHeightHint(int heightHint) { + this.heightHint = heightHint; + } + } diff --git a/eclipse-language-servers/org.springsource.ide.eclipse.commons.livexp/src/org/springsource/ide/eclipse/commons/livexp/ui/DescriptionSection.java b/eclipse-language-servers/org.springsource.ide.eclipse.commons.livexp/src/org/springsource/ide/eclipse/commons/livexp/ui/DescriptionSection.java index da1335c4b..fccb7be76 100644 --- a/eclipse-language-servers/org.springsource.ide.eclipse.commons.livexp/src/org/springsource/ide/eclipse/commons/livexp/ui/DescriptionSection.java +++ b/eclipse-language-servers/org.springsource.ide.eclipse.commons.livexp/src/org/springsource/ide/eclipse/commons/livexp/ui/DescriptionSection.java @@ -28,9 +28,6 @@ import org.springsource.ide.eclipse.commons.livexp.core.LiveVariable; 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; -import org.springsource.ide.eclipse.commons.livexp.ui.IPageWithSections; -import org.springsource.ide.eclipse.commons.livexp.ui.UIConstants; -import org.springsource.ide.eclipse.commons.livexp.ui.WizardPageSection; /** * Displays a short textual desciption. @@ -91,7 +88,9 @@ public class DescriptionSection extends WizardPageSection { public void modifyText(ModifyEvent e) { //Cast should succeed because readOnly option can only be disabled //if model is a variable. - ((LiveVariable)model).setValue(text.getText()); + if (model instanceof LiveVariable) { + ((LiveVariable)model).setValue(text.getText()); + } } }); }