Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPierre-Charles David2016-04-29 11:20:28 +0000
committerStephane Begaudeau2016-05-03 15:41:49 +0000
commitcee1cf082b5f96e59e1bc19aa8f32f23735fa32b (patch)
treefd37efdcd8b948ebbbcec5bf0eb9f3c2f2b1b3f8
parentbfd397498306db8b66de44c711914451a289ccd1 (diff)
downloadorg.eclipse.eef-cee1cf082b5f96e59e1bc19aa8f32f23735fa32b.tar.gz
org.eclipse.eef-cee1cf082b5f96e59e1bc19aa8f32f23735fa32b.tar.xz
org.eclipse.eef-cee1cf082b5f96e59e1bc19aa8f32f23735fa32b.zip
Add support for null values in combos
JFace ComboViewers do not like null values in their possible choices, but null is a legitimate choice for optional references (meaning "unset"). Replace nulls with a special value (with no risk of conflict with anything elese) when filling the combo, and convert it back to null when passing it to the controller if the users chooses it. Also avoid triggering the controller's updateValue() callback during refresh when we configure the combo to show the current value. Change-Id: Ic3d4f53f8c7f5c11a6aee02ef59708024bd63154 Signed-off-by: Pierre-Charles David <pierre-charles.david@obeo.fr>
-rw-r--r--plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/EEFSelectLifecycleManager.java30
1 files changed, 26 insertions, 4 deletions
diff --git a/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/EEFSelectLifecycleManager.java b/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/EEFSelectLifecycleManager.java
index 1b1d86610..3da8eaebf 100644
--- a/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/EEFSelectLifecycleManager.java
+++ b/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/EEFSelectLifecycleManager.java
@@ -55,6 +55,17 @@ import org.eclipse.ui.forms.widgets.FormToolkit;
* @author mbats
*/
public class EEFSelectLifecycleManager extends AbstractEEFWidgetLifecycleManager {
+
+ /**
+ * Special value to replace "null" as a combo value.
+ */
+ private static final Object NO_VALUE = new Object() {
+ @Override
+ public String toString() {
+ return "<null>"; //$NON-NLS-1$
+ }
+ };
+
/**
* The description.
*/
@@ -197,9 +208,14 @@ public class EEFSelectLifecycleManager extends AbstractEEFWidgetLifecycleManager
this.selectionListener = new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
- IStructuredSelection selection = getStructuredSelection(comboViewer);
- Object newValue = selection.getFirstElement();
- controller.updateValue(newValue);
+ if (!EEFSelectLifecycleManager.this.container.isRenderingInProgress()) {
+ IStructuredSelection selection = getStructuredSelection(comboViewer);
+ Object newValue = selection.getFirstElement();
+ if (newValue == NO_VALUE) {
+ newValue = null;
+ }
+ controller.updateValue(newValue);
+ }
}
@Override
@@ -234,7 +250,13 @@ public class EEFSelectLifecycleManager extends AbstractEEFWidgetLifecycleManager
public void apply(List<Object> value) {
if (!combo.isDisposed()) {
if (value != null) {
- comboViewer.setInput(value.toArray());
+ Object[] candidates = value.toArray();
+ for (int i = 0; i < candidates.length; i++) {
+ if (candidates[i] == null) {
+ candidates[i] = NO_VALUE;
+ }
+ }
+ comboViewer.setInput(candidates);
} else {
comboViewer.setInput(null);
}

Back to the top