Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMélanie Bats2016-09-06 08:44:21 +0000
committerMélanie Bats2016-09-29 13:37:15 +0000
commitefa5ed85bf4a038c35f769f579290cb1bc5094f3 (patch)
treeadb16b89519edd281bca33f76abf00f589c3175a
parent8c252b45cba09fcb11666b23944e16a9d8c0b91a (diff)
downloadorg.eclipse.eef-efa5ed85bf4a038c35f769f579290cb1bc5094f3.tar.gz
org.eclipse.eef-efa5ed85bf4a038c35f769f579290cb1bc5094f3.tar.xz
org.eclipse.eef-efa5ed85bf4a038c35f769f579290cb1bc5094f3.zip
[496011] Defer the evaluation of select candidates
The computation of the candidates available for a select is deferred until the user clicks on the combo box. Bug: 496011 Change-Id: I5174df1d864e1a69b72d552b236ac1fe7daa0e77 Signed-off-by: Mélanie Bats <melanie.bats@obeo.fr>
-rw-r--r--plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/api/controllers/IEEFSelectController.java5
-rw-r--r--plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/controllers/EEFSelectController.java24
-rw-r--r--plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/EEFSelectLifecycleManager.java40
-rw-r--r--tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/controllers/AbstractEEFControllerTests.java25
-rw-r--r--tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/controllers/EEFSelectControllerTests.java3
5 files changed, 88 insertions, 9 deletions
diff --git a/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/api/controllers/IEEFSelectController.java b/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/api/controllers/IEEFSelectController.java
index 5fb5ae7ce..9cb8f790f 100644
--- a/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/api/controllers/IEEFSelectController.java
+++ b/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/api/controllers/IEEFSelectController.java
@@ -54,4 +54,9 @@ public interface IEEFSelectController extends IEEFWidgetController {
*/
void removeNewCandidatesConsumer();
+ /**
+ * Compute the candidates.
+ */
+ void computeCandidates();
+
}
diff --git a/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/controllers/EEFSelectController.java b/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/controllers/EEFSelectController.java
index 7b997ffa5..837381f00 100644
--- a/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/controllers/EEFSelectController.java
+++ b/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/controllers/EEFSelectController.java
@@ -99,6 +99,27 @@ public class EEFSelectController extends AbstractEEFWidgetController implements
public void refresh() {
super.refresh();
+ // Evaluate the value expression
+ String valueExpression = this.description.getValueExpression();
+ Object value = this.newEval().evaluate(valueExpression);
+
+ // By default only the selected value is available in the candidates list
+ // The items list must contain at least one element else the widget is not enabled
+ List<Object> candidates = new ArrayList<Object>();
+ candidates.add(value);
+ EEFSelectController.this.newCandidatesConsumer.apply(candidates);
+
+ // Set the value
+ EEFSelectController.this.newValueConsumer.apply(value);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.eef.core.api.controllers.IEEFSelectController#computeCandidates()
+ */
+ @Override
+ public void computeCandidates() {
String candidatesExpression = this.description.getCandidatesExpression();
EAttribute candidatesExpressionEAttribute = EefPackage.Literals.EEF_SELECT_DESCRIPTION__CANDIDATES_EXPRESSION;
@@ -114,9 +135,6 @@ public class EEFSelectController extends AbstractEEFWidgetController implements
}
}
});
-
- String valueExpression = this.description.getValueExpression();
- this.newEval().call(valueExpression, this.newValueConsumer);
}
/**
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 90eb0d457..c028fec0e 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
@@ -38,12 +38,16 @@ import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.sirius.common.interpreter.api.IInterpreter;
import org.eclipse.sirius.common.interpreter.api.IVariableManager;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Cursor;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.forms.widgets.FormToolkit;
/**
@@ -89,6 +93,11 @@ public class EEFSelectLifecycleManager extends AbstractEEFWidgetLifecycleManager
private SelectionListener selectionListener;
/**
+ * The mouse listener on the combo.
+ */
+ private MouseListener mouseListener;
+
+ /**
* The constructor.
*
* @param description
@@ -190,6 +199,27 @@ public class EEFSelectLifecycleManager extends AbstractEEFWidgetLifecycleManager
};
this.combo.addSelectionListener(this.selectionListener);
+ this.mouseListener = new MouseListener() {
+
+ @Override
+ public void mouseDoubleClick(MouseEvent e) {
+ // Nothing to do
+ }
+
+ @Override
+ public void mouseDown(MouseEvent e) {
+ // Delay the computation of the candidates until the user click on the combo
+ controller.computeCandidates();
+ }
+
+ @Override
+ public void mouseUp(MouseEvent e) {
+ // Nothing to do
+ }
+
+ };
+ this.combo.addMouseListener(this.mouseListener);
+
// Set combo value
this.controller.onNewValue(new IConsumer<Object>() {
@Override
@@ -201,7 +231,7 @@ public class EEFSelectLifecycleManager extends AbstractEEFWidgetLifecycleManager
} else {
selection = null;
}
- comboViewer.setSelection(selection);
+ comboViewer.setSelection(selection, true);
if (!combo.isEnabled()) {
combo.setEnabled(true);
}
@@ -212,7 +242,8 @@ public class EEFSelectLifecycleManager extends AbstractEEFWidgetLifecycleManager
// Set combo items
this.controller.onNewCandidates(new IConsumer<List<Object>>() {
@Override
- public void apply(List<Object> value) {
+ public void apply(final List<Object> value) {
+ ISelection selection = comboViewer.getSelection();
if (!combo.isDisposed()) {
if (value != null) {
Object[] candidates = value.toArray();
@@ -225,12 +256,16 @@ public class EEFSelectLifecycleManager extends AbstractEEFWidgetLifecycleManager
} else {
comboViewer.setInput(null);
}
+ comboViewer.setSelection(selection, true);
if (!combo.isEnabled()) {
combo.setEnabled(true);
}
}
+
+ combo.setCursor(new Cursor(Display.getCurrent(), SWT.CURSOR_ARROW));
}
});
+
}
/**
@@ -244,6 +279,7 @@ public class EEFSelectLifecycleManager extends AbstractEEFWidgetLifecycleManager
if (!combo.isDisposed()) {
this.combo.removeSelectionListener(this.selectionListener);
+ this.combo.removeMouseListener(this.mouseListener);
}
this.controller.removeNewValueConsumer();
this.controller.removeNewCandidatesConsumer();
diff --git a/tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/controllers/AbstractEEFControllerTests.java b/tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/controllers/AbstractEEFControllerTests.java
index 4963e35d6..051fabc06 100644
--- a/tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/controllers/AbstractEEFControllerTests.java
+++ b/tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/controllers/AbstractEEFControllerTests.java
@@ -10,6 +10,10 @@
*******************************************************************************/
package org.eclipse.eef.tests.internal.controllers;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.notNullValue;
+
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;
@@ -21,6 +25,7 @@ import org.eclipse.eef.EEFWidgetDescription;
import org.eclipse.eef.EefPackage;
import org.eclipse.eef.core.api.EEFExpressionUtils;
import org.eclipse.eef.core.api.EditingContextAdapter;
+import org.eclipse.eef.core.api.controllers.IEEFSelectController;
import org.eclipse.eef.core.api.controllers.IEEFWidgetController;
import org.eclipse.eef.tests.internal.AQLInterpreter;
import org.eclipse.eef.tests.internal.EEFDataTests;
@@ -36,10 +41,6 @@ import org.eclipse.sirius.common.interpreter.api.IVariableManager;
import org.eclipse.sirius.common.interpreter.api.VariableManagerFactory;
import org.junit.Before;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.core.Is.is;
-import static org.hamcrest.core.IsNull.notNullValue;
-
import static org.junit.Assert.assertTrue;
/**
@@ -125,6 +126,14 @@ public abstract class AbstractEEFControllerTests {
assertThat(label, is(expectedLabel));
atomicBoolean.set(true);
});
+ if (controller instanceof IEEFSelectController) {
+ ((IEEFSelectController) controller).onNewCandidates(candidates -> {
+ // do nothing
+ });
+ ((IEEFSelectController) controller).onNewValue(value -> {
+ // do nothing
+ });
+ }
controller.refresh();
assertTrue(atomicBoolean.get());
}
@@ -136,6 +145,14 @@ public abstract class AbstractEEFControllerTests {
atomicBoolean.set(true);
});
controller.computeHelp();
+ if (controller instanceof IEEFSelectController) {
+ ((IEEFSelectController) controller).onNewCandidates(candidates -> {
+ // do nothing
+ });
+ ((IEEFSelectController) controller).onNewValue(value -> {
+ // do nothing
+ });
+ }
controller.refresh();
assertTrue(atomicBoolean.get());
}
diff --git a/tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/controllers/EEFSelectControllerTests.java b/tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/controllers/EEFSelectControllerTests.java
index 78e0a22bf..c51151977 100644
--- a/tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/controllers/EEFSelectControllerTests.java
+++ b/tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/controllers/EEFSelectControllerTests.java
@@ -56,6 +56,9 @@ public class EEFSelectControllerTests extends AbstractEEFControllerTests {
public void testValue() {
AtomicBoolean atomicBoolean = new AtomicBoolean(false);
IEEFSelectController controller = this.selectController(EEFDataTests.EEFSELECTCONTROLLERTESTS_VALUE);
+ controller.onNewCandidates(candidates -> {
+ // do nothing
+ });
controller.onNewValue(value -> {
assertThat(value, is("public")); //$NON-NLS-1$
atomicBoolean.set(true);

Back to the top