Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStéphane Bégaudeau2016-05-03 08:35:30 +0000
committerStéphane Bégaudeau2016-05-04 12:00:50 +0000
commitb9d3994e3c5a0489e85f2abe28d4e7561abd6e25 (patch)
tree1b52a7736d7862e06c5e0b4d570d89ef3dc4bb14
parent6c83556399d91f3925425db6942f28490a0b5f7e (diff)
downloadorg.eclipse.eef-b9d3994e3c5a0489e85f2abe28d4e7561abd6e25.tar.gz
org.eclipse.eef-b9d3994e3c5a0489e85f2abe28d4e7561abd6e25.tar.xz
org.eclipse.eef-b9d3994e3c5a0489e85f2abe28d4e7561abd6e25.zip
Improve the API of Eval
1) The API of Eval has been modified in order to simplify its use by reducing the number of methods with a similar signature that can be called. The new methods have also a much more explicit name. 2) Simplify some usage of Eval in order to reduce the number of message logged for the end users. If the absence of an expression does not prevent the proper execution of the code, nothing is logged Change-Id: I67566cdb1c56c0e1505d64cb36a0d81b4df63908 Signed-off-by: Stéphane Bégaudeau <stephane.begaudeau@obeo.fr>
-rw-r--r--plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/api/controllers/AbstractEEFController.java17
-rw-r--r--plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/api/controllers/AbstractEEFCustomWidgetController.java2
-rw-r--r--plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/api/controllers/AbstractEEFWidgetController.java6
-rw-r--r--plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/api/utils/Eval.java244
-rw-r--r--plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/api/utils/EvalFactory.java257
-rw-r--r--plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/EEFPageImpl.java12
-rw-r--r--plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/EEFViewImpl.java27
-rw-r--r--plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/controllers/EEFButtonController.java7
-rw-r--r--plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/controllers/EEFCheckboxController.java8
-rw-r--r--plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/controllers/EEFGroupController.java5
-rw-r--r--plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/controllers/EEFHyperlinkController.java8
-rw-r--r--plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/controllers/EEFLabelController.java7
-rw-r--r--plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/controllers/EEFRadioController.java10
-rw-r--r--plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/controllers/EEFReferenceController.java10
-rw-r--r--plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/controllers/EEFSelectController.java10
-rw-r--r--plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/controllers/EEFTextController.java11
-rw-r--r--plugins/org.eclipse.eef.ide.ui.properties/src/org/eclipse/eef/ide/ui/properties/api/EEFTabDescriptor.java5
-rw-r--r--plugins/org.eclipse.eef.ide.ui/.settings/org.eclipse.jdt.ui.prefs2
-rw-r--r--plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/api/EEFTab.java12
-rw-r--r--plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/api/widgets/AbstractEEFWidgetLifecycleManager.java143
-rw-r--r--plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/ActionButton.java10
-rw-r--r--plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/EEFControlSwitch.java10
-rw-r--r--plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/EEFGroupLifecycleManager.java25
-rw-r--r--plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/EEFHyperlinkLifecycleManager.java15
-rw-r--r--plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/EEFLabelLifecycleManager.java19
-rw-r--r--plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/EEFRadioLifecycleManager.java5
-rw-r--r--plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/EEFReferenceLifecycleManager.java10
-rw-r--r--plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/EEFSectionLifecycleManager.java6
-rw-r--r--plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/EEFSelectLifecycleManager.java5
-rw-r--r--plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/EEFTextLifecycleManager.java12
-rw-r--r--plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/quickfix/EEFQuickFixPage.java10
-rw-r--r--plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/quickfix/EEFQuickFixWizard.java10
-rw-r--r--samples/org.eclipse.eef.sample.custom.widget.colorpicker/src/org/eclipse/eef/sample/custom/widget/colorpicker/ColorPickerController.java11
-rw-r--r--tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/AllTests.java5
-rw-r--r--tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/core/EvalTests.java98
35 files changed, 516 insertions, 538 deletions
diff --git a/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/api/controllers/AbstractEEFController.java b/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/api/controllers/AbstractEEFController.java
index f087cf7b0..fccf165b6 100644
--- a/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/api/controllers/AbstractEEFController.java
+++ b/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/api/controllers/AbstractEEFController.java
@@ -16,7 +16,8 @@ import java.util.List;
import org.eclipse.eef.EEFRuleAuditDescription;
import org.eclipse.eef.EEFValidationRuleDescription;
import org.eclipse.eef.EefPackage;
-import org.eclipse.eef.core.api.utils.Eval;
+import org.eclipse.eef.core.api.utils.EvalFactory;
+import org.eclipse.eef.core.api.utils.EvalFactory.Eval;
import org.eclipse.eef.core.internal.controllers.InvalidValidationRuleResult;
import org.eclipse.eef.core.internal.controllers.ValidationRuleResult;
import org.eclipse.emf.ecore.EAttribute;
@@ -64,8 +65,8 @@ public abstract class AbstractEEFController implements IEEFController {
*
* @return a new Eval.
*/
- protected Eval newEval() {
- return new Eval(this.interpreter, this.variableManager);
+ protected Eval<Object> newEval() {
+ return EvalFactory.of(this.interpreter, this.variableManager);
}
/**
@@ -146,7 +147,7 @@ public abstract class AbstractEEFController implements IEEFController {
for (EEFRuleAuditDescription audit : validationRule.getAudits()) {
String auditExpression = audit.getAuditExpression();
- Boolean result = this.newEval().get(auditEAttribute, auditExpression, Boolean.class);
+ Boolean result = this.newEval().logIfBlank(auditEAttribute).logIfInvalidType(Boolean.class).evaluate(auditExpression);
isValid = isValid && (result != null && result.booleanValue());
if (!isValid) {
@@ -157,10 +158,12 @@ public abstract class AbstractEEFController implements IEEFController {
if (isValid) {
validationRuleResults.add(new ValidationRuleResult(validationRule));
} else {
- Eval eval = this.newEval();
+ Eval<Object> eval = this.newEval();
String messageExpression = validationRule.getMessageExpression();
- String message = eval.get(messageEAttribute, messageExpression, String.class);
- validationRuleResults.add(new InvalidValidationRuleResult(validationRule, message, eval, validationRule.getSeverity().getValue()));
+ String message = eval.logIfBlank(messageEAttribute).logIfInvalidType(String.class).evaluate(messageExpression);
+
+ validationRuleResults.add(new InvalidValidationRuleResult(validationRule, message, this.newEval(), validationRule.getSeverity()
+ .getValue()));
}
}
diff --git a/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/api/controllers/AbstractEEFCustomWidgetController.java b/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/api/controllers/AbstractEEFCustomWidgetController.java
index d9005c43c..5f5cdbfae 100644
--- a/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/api/controllers/AbstractEEFCustomWidgetController.java
+++ b/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/api/controllers/AbstractEEFCustomWidgetController.java
@@ -100,7 +100,7 @@ public abstract class AbstractEEFCustomWidgetController extends AbstractEEFWidge
public void run() {
String pushExpression = getCustomExpression(customExpressionId);
EAttribute attr = EefPackage.Literals.EEF_CUSTOM_EXPRESSION__CUSTOM_EXPRESSION;
- AbstractEEFCustomWidgetController.this.newEval().call(attr, pushExpression);
+ AbstractEEFCustomWidgetController.this.newEval().logIfBlank(attr).call(pushExpression);
}
});
}
diff --git a/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/api/controllers/AbstractEEFWidgetController.java b/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/api/controllers/AbstractEEFWidgetController.java
index 3dad1298d..8f56e3083 100644
--- a/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/api/controllers/AbstractEEFWidgetController.java
+++ b/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/api/controllers/AbstractEEFWidgetController.java
@@ -12,7 +12,6 @@ package org.eclipse.eef.core.api.controllers;
import org.eclipse.eef.EEFWidgetDescription;
import org.eclipse.eef.EefPackage;
-import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.sirius.common.interpreter.api.IInterpreter;
@@ -124,11 +123,10 @@ public abstract class AbstractEEFWidgetController extends AbstractEEFController
super.refresh();
String labelExpression = this.getDescription().getLabelExpression();
- EAttribute labelEAttribute = EefPackage.Literals.EEF_WIDGET_DESCRIPTION__LABEL_EXPRESSION;
- this.newEval().call(labelEAttribute, labelExpression, String.class, AbstractEEFWidgetController.this.newLabelConsumer);
+ this.newEval().logIfInvalidType(String.class).call(labelExpression, AbstractEEFWidgetController.this.newLabelConsumer);
String helpExpression = this.getDescription().getHelpExpression();
- this.newEval().call(helpExpression, String.class, AbstractEEFWidgetController.this.newHelpConsumer);
+ this.newEval().logIfInvalidType(String.class).call(helpExpression, AbstractEEFWidgetController.this.newHelpConsumer);
}
}
diff --git a/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/api/utils/Eval.java b/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/api/utils/Eval.java
deleted file mode 100644
index 813b91117..000000000
--- a/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/api/utils/Eval.java
+++ /dev/null
@@ -1,244 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2016 Obeo.
- * 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:
- * Obeo - initial API and implementation
- *******************************************************************************/
-package org.eclipse.eef.core.api.utils;
-
-import java.text.MessageFormat;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.eclipse.eef.common.api.utils.Util;
-import org.eclipse.eef.core.api.controllers.IConsumer;
-import org.eclipse.eef.core.internal.EEFCorePlugin;
-import org.eclipse.eef.core.internal.Messages;
-import org.eclipse.emf.ecore.EAttribute;
-import org.eclipse.sirius.common.interpreter.api.IEvaluationResult;
-import org.eclipse.sirius.common.interpreter.api.IInterpreter;
-import org.eclipse.sirius.common.interpreter.api.IVariableManager;
-
-/**
- * Utility class used to evaluate expression and log potential errors.
- *
- * @author sbegaudeau
- */
-public final class Eval {
- /**
- * The interpreter.
- */
- private IInterpreter interpreter;
-
- /**
- * The variables.
- */
- private Map<String, Object> variables = new HashMap<String, Object>();
-
- /**
- * The constructor.
- *
- * @param interpreter
- * The interpreter
- * @param variables
- * The variables
- */
- public Eval(IInterpreter interpreter, Map<String, Object> variables) {
- this.interpreter = interpreter;
- this.variables.putAll(variables);
- }
-
- /**
- * The constructor.
- *
- * @param interpreter
- * The interpreter
- * @param variableManager
- * The variable manager
- */
- public Eval(IInterpreter interpreter, IVariableManager variableManager) {
- this(interpreter, variableManager.getVariables());
- }
-
- /**
- * Verifies that the expression is not blank, evaluates it, verify the type of the result and logs any potential
- * error.
- *
- * @param expressionEAttribute
- * The EAttribute containing the expression
- * @param expression
- * The expression to evaluate
- * @param expectedResultType
- * The expected type of the result
- * @param consumer
- * The consumer which will receive the result
- * @param <T>
- * The type of the result expected
- */
- public <T> void call(EAttribute expressionEAttribute, String expression, Class<T> expectedResultType, IConsumer<T> consumer) {
- if (!Util.isBlank(expression)) {
- this.call(expression, expectedResultType, consumer);
- } else if (EEFCorePlugin.getPlugin() != null) {
- EEFCorePlugin.getPlugin().blank(expressionEAttribute);
- }
- }
-
- /**
- * Evaluates the expression, verify the type of the result and logs any potential error.
- *
- * @param expression
- * The expression to evaluate
- * @param expectedResultType
- * The expected type of the result
- * @param consumer
- * The consumer which will receive the result
- * @param <T>
- * The type of the result expected
- */
- public <T> void call(String expression, Class<T> expectedResultType, IConsumer<T> consumer) {
- if (Util.isBlank(expression)) {
- return;
- }
-
- IEvaluationResult evaluationResult = this.interpreter.evaluateExpression(this.variables, expression);
- if (evaluationResult.success()) {
- Object value = evaluationResult.getValue();
- if (expectedResultType.isInstance(value) || (value == null && !expectedResultType.isPrimitive())) {
- T castValue = expectedResultType.cast(value);
- consumer.apply(castValue);
- } else if (EEFCorePlugin.getPlugin() != null) {
- String message = MessageFormat.format(Messages.AbstractEEFWidgetController_InvalidValueForExpression, expression,
- expectedResultType.getName(), value);
- EEFCorePlugin.getPlugin().error(message);
- }
- } else if (EEFCorePlugin.getPlugin() != null) {
- EEFCorePlugin.getPlugin().diagnostic(expression, evaluationResult.getDiagnostic());
- }
- }
-
- /**
- * Verifies that the expression is not blank, evaluates it and logs any potential error.
- *
- * @param expressionEAttribute
- * The EAttribute containing the expression
- * @param expression
- * The expression to evaluate
- * @param consumer
- * The consumer which will receive the result
- */
- public void call(EAttribute expressionEAttribute, String expression, IConsumer<Object> consumer) {
- if (!Util.isBlank(expression)) {
- this.call(expression, consumer);
- } else if (EEFCorePlugin.getPlugin() != null) {
- EEFCorePlugin.getPlugin().blank(expressionEAttribute);
- }
- }
-
- /**
- * Verifies that the expression is not blank, evaluates it and logs any potential error.
- *
- * @param expression
- * The expression to evaluate
- * @param consumer
- * The consumer which will receive the result
- */
- public void call(String expression, IConsumer<Object> consumer) {
- IEvaluationResult evaluationResult = this.interpreter.evaluateExpression(this.variables, expression);
- if (evaluationResult.success()) {
- Object value = evaluationResult.getValue();
- consumer.apply(value);
- } else if (EEFCorePlugin.getPlugin() != null) {
- EEFCorePlugin.getPlugin().diagnostic(expression, evaluationResult.getDiagnostic());
- }
- }
-
- /**
- * Verifies that the expression is not blank, evaluates it and logs any potential error.
- *
- * @param expressionEAttribute
- * The EAttribute containing the expression
- * @param expression
- * The expression to evaluate
- */
- public void call(EAttribute expressionEAttribute, String expression) {
- if (!Util.isBlank(expression)) {
- IEvaluationResult evaluationResult = this.interpreter.evaluateExpression(this.variables, expression);
- if (!evaluationResult.success()) {
- EEFCorePlugin.getPlugin().diagnostic(expression, evaluationResult.getDiagnostic());
- }
- } else if (EEFCorePlugin.getPlugin() != null) {
- EEFCorePlugin.getPlugin().blank(expressionEAttribute);
- }
- }
-
- /**
- * Verifies that the expression is not blank, evaluates it and returns its result if its matches the given result
- * type.
- *
- * @param expressionEAttribute
- * The EAttribute containing the expression
- * @param expression
- * The expression
- * @param expectedResultType
- * The expected result type
- * @param <T>
- * The type expected
- * @return The result of the expression
- */
- public <T> T get(EAttribute expressionEAttribute, String expression, Class<T> expectedResultType) {
- if (!Util.isBlank(expression)) {
- IEvaluationResult evaluationResult = this.interpreter.evaluateExpression(this.variables, expression);
- if (evaluationResult.success()) {
- Object value = evaluationResult.getValue();
- if (expectedResultType.isInstance(value) || (value == null && !expectedResultType.isPrimitive())) {
- T castValue = expectedResultType.cast(value);
- return castValue;
- } else if (EEFCorePlugin.getPlugin() != null) {
- String message = MessageFormat.format(Messages.AbstractEEFWidgetController_InvalidValueForExpression, expression,
- expectedResultType.getName(), value);
- EEFCorePlugin.getPlugin().error(message);
- }
- } else if (EEFCorePlugin.getPlugin() != null) {
- EEFCorePlugin.getPlugin().diagnostic(expression, evaluationResult.getDiagnostic());
- }
- } else if (EEFCorePlugin.getPlugin() != null) {
- EEFCorePlugin.getPlugin().blank(expressionEAttribute);
- }
- return null;
- }
-
- /**
- * Evaluates the expression and returns its result if its matches the given result type.
- *
- * @param expression
- * The expression
- * @param expectedResultType
- * The expected result type
- * @param <T>
- * The type expected
- * @return The result of the expression
- */
- public <T> T get(String expression, Class<T> expectedResultType) {
- if (!Util.isBlank(expression)) {
- IEvaluationResult evaluationResult = this.interpreter.evaluateExpression(this.variables, expression);
- if (evaluationResult.success()) {
- Object value = evaluationResult.getValue();
- if (expectedResultType.isInstance(value) || (value == null && !expectedResultType.isPrimitive())) {
- T castValue = expectedResultType.cast(value);
- return castValue;
- } else if (EEFCorePlugin.getPlugin() != null) {
- String message = MessageFormat.format(Messages.AbstractEEFWidgetController_InvalidValueForExpression, expression,
- expectedResultType.getName(), value);
- EEFCorePlugin.getPlugin().error(message);
- }
- } else if (EEFCorePlugin.getPlugin() != null) {
- EEFCorePlugin.getPlugin().diagnostic(expression, evaluationResult.getDiagnostic());
- }
- }
- return null;
- }
-}
diff --git a/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/api/utils/EvalFactory.java b/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/api/utils/EvalFactory.java
new file mode 100644
index 000000000..8fd6a4a0a
--- /dev/null
+++ b/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/api/utils/EvalFactory.java
@@ -0,0 +1,257 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Obeo.
+ * 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:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.eef.core.api.utils;
+
+import java.text.MessageFormat;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.eef.common.api.utils.Util;
+import org.eclipse.eef.core.api.controllers.IConsumer;
+import org.eclipse.eef.core.internal.EEFCorePlugin;
+import org.eclipse.eef.core.internal.Messages;
+import org.eclipse.emf.ecore.EAttribute;
+import org.eclipse.sirius.common.interpreter.api.IEvaluationResult;
+import org.eclipse.sirius.common.interpreter.api.IInterpreter;
+import org.eclipse.sirius.common.interpreter.api.IVariableManager;
+
+/**
+ * Utility class used to create the {@link Eval}.
+ *
+ * @author sbegaudeau
+ */
+public final class EvalFactory {
+
+ /**
+ * The constructor.
+ */
+ private EvalFactory() {
+ // Prevent the instantiation
+ }
+
+ /**
+ * Creates a new {@link Eval} with the given interpreter and variables.
+ *
+ * @param interpreter
+ * The interpreter
+ * @param variables
+ * The variables
+ * @return The new {@link Eval} builder
+ */
+ public static Eval<Object> of(IInterpreter interpreter, Map<String, Object> variables) {
+ return new Eval<Object>(interpreter, variables, Object.class);
+ }
+
+ /**
+ * Creates a new {@link Eval} with the given interpreter and variable manager.
+ *
+ * @param interpreter
+ * The interpreter
+ * @param variableManager
+ * The variable manager
+ * @return The new {@link Eval}
+ */
+ public static Eval<Object> of(IInterpreter interpreter, IVariableManager variableManager) {
+ return new Eval<Object>(interpreter, variableManager, Object.class);
+ }
+
+ /**
+ * This class will be used to evaluate the expression.
+ *
+ * @author sbegaudeau
+ *
+ * @param <TYPE>
+ * The type of the result returned by the execution of the expression
+ */
+ public static final class Eval<TYPE> {
+ /**
+ * The interpreter.
+ */
+ private IInterpreter interpreter;
+
+ /**
+ * The variables.
+ */
+ private Map<String, Object> variables = new HashMap<String, Object>();
+
+ /**
+ * The EAttribute containing the expression. It will be used, if not null, to log an error if the expression is
+ * blank.
+ */
+ private EAttribute eAttribute;
+
+ /**
+ * The value to use by default if the evaluation of the expression returns null.
+ */
+ private TYPE defaultValue;
+
+ /**
+ * The expected type of the result.
+ */
+ private Class<TYPE> type;
+
+ /**
+ * The constructor.
+ *
+ * @param interpreter
+ * The interpreter
+ * @param variables
+ * The variables
+ * @param type
+ * The expected type of the result
+ */
+ private Eval(IInterpreter interpreter, Map<String, Object> variables, Class<TYPE> type) {
+ this.interpreter = interpreter;
+ this.variables.putAll(variables);
+ this.type = type;
+ }
+
+ /**
+ * The constructor.
+ *
+ * @param interpreter
+ * The interpreter
+ * @param variableManager
+ * The variable manager
+ * @param type
+ * The expected type of the result
+ */
+ private Eval(IInterpreter interpreter, IVariableManager variableManager, Class<TYPE> type) {
+ this(interpreter, variableManager.getVariables(), type);
+ }
+
+ /**
+ * Indicates that an error should be logged using the given EAttribute if the expression to execute is blank.
+ *
+ * @param attribute
+ * The EAttribute containing the expression to execute
+ * @return The current {@link Eval}
+ */
+ public Eval<TYPE> logIfBlank(EAttribute attribute) {
+ this.eAttribute = attribute;
+ return this;
+ }
+
+ /**
+ * Indicates that the result should have the same type as the given class. It will log an error if the type of
+ * the result does not match the given type.
+ *
+ * @param expectedType
+ * The expected type
+ * @param <E>
+ * The expected type of the execution of the expression
+ * @return The current {@link Eval}
+ *
+ */
+ public <E> Eval<E> logIfInvalidType(Class<E> expectedType) {
+ E value = null;
+ if (expectedType.isInstance(this.defaultValue)) {
+ value = expectedType.cast(this.defaultValue);
+ }
+ return new Eval<E>(this.interpreter, this.variables, expectedType).logIfBlank(this.eAttribute).defaultValue(value);
+ }
+
+ /**
+ * Indicates the value to use by default if the result of the evaluation of the expression is null.
+ *
+ * @param value
+ * The default value
+ * @return The current {@link Eval}
+ */
+ public Eval<TYPE> defaultValue(TYPE value) {
+ this.defaultValue = value;
+ return this;
+ }
+
+ /**
+ * Executes the given expression and process its result using the given consumer.
+ *
+ * @param expression
+ * The expression
+ */
+ public void call(String expression) {
+ this.call(expression, null);
+ }
+
+ /**
+ * Executes the given expression and process its result using the given consumer.
+ *
+ * @param expression
+ * The expression
+ * @param consumer
+ * The consumer
+ */
+ public void call(String expression, IConsumer<TYPE> consumer) {
+ if (Util.isBlank(expression)) {
+ if (this.eAttribute != null && EEFCorePlugin.getPlugin() != null) {
+ EEFCorePlugin.getPlugin().blank(this.eAttribute);
+ }
+
+ if (this.defaultValue != null) {
+ consumer.apply(this.defaultValue);
+ }
+ return;
+ }
+
+ IEvaluationResult evaluationResult = this.interpreter.evaluateExpression(this.variables, expression);
+ if (evaluationResult.success()) {
+ if (consumer != null) {
+ TYPE returnValue = this.defaultValue;
+ Object value = evaluationResult.getValue();
+ if (value != null && this.type.isInstance(value)) {
+ returnValue = this.type.cast(value);
+ } else if (value != null && EEFCorePlugin.getPlugin() != null) {
+ String message = MessageFormat.format(Messages.AbstractEEFWidgetController_InvalidValueForExpression, expression,
+ this.type.getName(), value);
+ EEFCorePlugin.getPlugin().error(message);
+ }
+ consumer.apply(returnValue);
+ }
+ } else if (EEFCorePlugin.getPlugin() != null) {
+ EEFCorePlugin.getPlugin().diagnostic(expression, evaluationResult.getDiagnostic());
+ }
+ }
+
+ /**
+ * Executes the given expression.
+ *
+ * @param expression
+ * The expression
+ * @return The result of the expression
+ */
+ public TYPE evaluate(String expression) {
+ if (Util.isBlank(expression)) {
+ if (this.eAttribute != null && EEFCorePlugin.getPlugin() != null) {
+ EEFCorePlugin.getPlugin().blank(this.eAttribute);
+ }
+
+ return this.defaultValue;
+ }
+
+ TYPE result = this.defaultValue;
+ IEvaluationResult evaluationResult = this.interpreter.evaluateExpression(this.variables, expression);
+ if (evaluationResult.success()) {
+ Object value = evaluationResult.getValue();
+ if (value != null && this.type.isInstance(value)) {
+ TYPE castValue = this.type.cast(value);
+ result = castValue;
+ } else if (value != null && EEFCorePlugin.getPlugin() != null) {
+ String message = MessageFormat.format(Messages.AbstractEEFWidgetController_InvalidValueForExpression, expression,
+ this.type.getName(), value);
+ EEFCorePlugin.getPlugin().error(message);
+ }
+ } else if (EEFCorePlugin.getPlugin() != null) {
+ EEFCorePlugin.getPlugin().diagnostic(expression, evaluationResult.getDiagnostic());
+ }
+ return result;
+ }
+ }
+}
diff --git a/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/EEFPageImpl.java b/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/EEFPageImpl.java
index 8b3faa569..d4d4f9ec9 100644
--- a/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/EEFPageImpl.java
+++ b/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/EEFPageImpl.java
@@ -24,7 +24,7 @@ import org.eclipse.eef.core.api.EEFPage;
import org.eclipse.eef.core.api.EEFView;
import org.eclipse.eef.core.api.IEEFDomainClassTester;
import org.eclipse.eef.core.api.controllers.IConsumer;
-import org.eclipse.eef.core.api.utils.Eval;
+import org.eclipse.eef.core.api.utils.EvalFactory;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.sirius.common.interpreter.api.IInterpreter;
import org.eclipse.sirius.common.interpreter.api.IVariableManager;
@@ -103,7 +103,8 @@ public class EEFPageImpl implements EEFPage {
EEFCorePlugin.getPlugin().debug("EEFPageImpl#initialize()"); //$NON-NLS-1$
for (final EEFGroupDescription eefGroupDescription : eefPageDescription.getGroups()) {
String preconditionExpression = eefGroupDescription.getPreconditionExpression();
- Boolean preconditionValid = new Eval(this.interpreter, this.variableManager).get(preconditionExpression, Boolean.class);
+ Boolean preconditionValid = EvalFactory.of(this.interpreter, this.variableManager).logIfInvalidType(Boolean.class)
+ .evaluate(preconditionExpression);
if (preconditionValid == null || preconditionValid.booleanValue()) {
IConsumer<Object> consumer = new IConsumer<Object>() {
@Override
@@ -120,12 +121,9 @@ public class EEFPageImpl implements EEFPage {
}
};
+ Object self = this.variableManager.getVariables().get(EEFExpressionUtils.SELF);
String groupSemanticCandidateExpression = eefGroupDescription.getSemanticCandidateExpression();
- if (!Util.isBlank(groupSemanticCandidateExpression)) {
- new Eval(this.interpreter, this.variableManager).call(groupSemanticCandidateExpression, consumer);
- } else if (this.variableManager.getVariables().get(EEFExpressionUtils.SELF) != null) {
- consumer.apply(this.variableManager.getVariables().get(EEFExpressionUtils.SELF));
- }
+ EvalFactory.of(this.interpreter, this.variableManager).defaultValue(self).call(groupSemanticCandidateExpression, consumer);
}
}
}
diff --git a/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/EEFViewImpl.java b/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/EEFViewImpl.java
index 5062e51a9..b86cda918 100644
--- a/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/EEFViewImpl.java
+++ b/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/EEFViewImpl.java
@@ -27,7 +27,7 @@ import org.eclipse.eef.core.api.EditingContextAdapter;
import org.eclipse.eef.core.api.IEEFDomainClassTester;
import org.eclipse.eef.core.api.InputDescriptor;
import org.eclipse.eef.core.api.controllers.IConsumer;
-import org.eclipse.eef.core.api.utils.Eval;
+import org.eclipse.eef.core.api.utils.EvalFactory;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.sirius.common.interpreter.api.IInterpreter;
import org.eclipse.sirius.common.interpreter.api.IVariableManager;
@@ -101,7 +101,8 @@ public class EEFViewImpl implements EEFView {
EEFCorePlugin.getPlugin().debug("EEFViewImpl#initialize()"); //$NON-NLS-1$
for (final EEFPageDescription eefPageDescription : this.getDescription().getPages()) {
String preconditionExpression = eefPageDescription.getPreconditionExpression();
- Boolean preconditionValid = new Eval(this.interpreter, this.variableManager).get(preconditionExpression, Boolean.class);
+ Boolean preconditionValid = EvalFactory.of(this.interpreter, this.variableManager).logIfInvalidType(Boolean.class)
+ .evaluate(preconditionExpression);
if (preconditionValid == null || preconditionValid.booleanValue()) {
IConsumer<Object> consumer = new IConsumer<Object>() {
@Override
@@ -126,12 +127,9 @@ public class EEFViewImpl implements EEFView {
};
// If we do not have a semantic candidate expression, we will reuse self by default if it exists
+ Object self = this.variableManager.getVariables().get(EEFExpressionUtils.SELF);
String pageSemanticCandidateExpression = eefPageDescription.getSemanticCandidateExpression();
- if (!Util.isBlank(pageSemanticCandidateExpression)) {
- new Eval(this.interpreter, this.variableManager).call(pageSemanticCandidateExpression, consumer);
- } else if (this.variableManager.getVariables().get(EEFExpressionUtils.SELF) != null) {
- consumer.apply(this.variableManager.getVariables().get(EEFExpressionUtils.SELF));
- }
+ EvalFactory.of(this.interpreter, this.variableManager).defaultValue(self).call(pageSemanticCandidateExpression, consumer);
}
}
@@ -201,12 +199,9 @@ public class EEFViewImpl implements EEFView {
};
// If the semantic candidate expression is blank, we will use the variable self of the view
+ Object viewSelf = this.variableManager.getVariables().get(EEFExpressionUtils.SELF);
String pageSemanticCandidateExpression = eefPage.getDescription().getSemanticCandidateExpression();
- if (!Util.isBlank(pageSemanticCandidateExpression)) {
- new Eval(this.interpreter, this.variableManager).call(pageSemanticCandidateExpression, pageConsumer);
- } else {
- pageConsumer.apply(this.variableManager.getVariables().get(EEFExpressionUtils.SELF));
- }
+ EvalFactory.of(this.interpreter, this.variableManager).defaultValue(viewSelf).call(pageSemanticCandidateExpression, pageConsumer);
List<EEFGroup> groups = eefPage.getGroups();
for (final EEFGroup eefGroup : groups) {
@@ -218,12 +213,10 @@ public class EEFViewImpl implements EEFView {
};
// If the semantic candidate expression is blank, we will use the variable self of the page
+ Object pageSelf = eefPage.getVariableManager().getVariables().get(EEFExpressionUtils.SELF);
String groupSemanticCandidateExpression = eefGroup.getDescription().getSemanticCandidateExpression();
- if (!Util.isBlank(groupSemanticCandidateExpression)) {
- new Eval(this.interpreter, eefPage.getVariableManager()).call(groupSemanticCandidateExpression, groupConsumer);
- } else if (eefPage.getVariableManager().getVariables().get(EEFExpressionUtils.SELF) != null) {
- groupConsumer.apply(eefPage.getVariableManager().getVariables().get(EEFExpressionUtils.SELF));
- }
+ EvalFactory.of(this.interpreter, eefPage.getVariableManager()).defaultValue(pageSelf)
+ .call(groupSemanticCandidateExpression, groupConsumer);
}
}
}
diff --git a/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/controllers/EEFButtonController.java b/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/controllers/EEFButtonController.java
index 96ce715bd..401640758 100644
--- a/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/controllers/EEFButtonController.java
+++ b/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/controllers/EEFButtonController.java
@@ -79,10 +79,9 @@ public class EEFButtonController extends AbstractEEFWidgetController implements
@Override
public void refresh() {
super.refresh();
- String buttonLabelExpression = this.description.getButtonLabelExpression();
- EAttribute eAttribute = EefPackage.Literals.EEF_BUTTON_DESCRIPTION__BUTTON_LABEL_EXPRESSION;
- this.newEval().call(eAttribute, buttonLabelExpression, String.class, EEFButtonController.this.newButtonLabelConsumer);
+ String buttonLabelExpression = this.description.getButtonLabelExpression();
+ this.newEval().logIfInvalidType(String.class).call(buttonLabelExpression, this.newButtonLabelConsumer);
}
@Override
@@ -92,7 +91,7 @@ public class EEFButtonController extends AbstractEEFWidgetController implements
public void run() {
String pushExpression = EEFButtonController.this.description.getPushExpression();
EAttribute attr = EefPackage.Literals.EEF_BUTTON_DESCRIPTION__PUSH_EXPRESSION;
- EEFButtonController.this.newEval().call(attr, pushExpression);
+ EEFButtonController.this.newEval().logIfBlank(attr).call(pushExpression);
}
});
}
diff --git a/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/controllers/EEFCheckboxController.java b/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/controllers/EEFCheckboxController.java
index d161566a8..ed6aa2e61 100644
--- a/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/controllers/EEFCheckboxController.java
+++ b/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/controllers/EEFCheckboxController.java
@@ -21,7 +21,7 @@ import org.eclipse.eef.core.api.EditingContextAdapter;
import org.eclipse.eef.core.api.controllers.AbstractEEFWidgetController;
import org.eclipse.eef.core.api.controllers.IConsumer;
import org.eclipse.eef.core.api.controllers.IEEFCheckboxController;
-import org.eclipse.eef.core.api.utils.Eval;
+import org.eclipse.eef.core.api.utils.EvalFactory;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.sirius.common.interpreter.api.IInterpreter;
import org.eclipse.sirius.common.interpreter.api.IVariableManager;
@@ -78,7 +78,7 @@ public class EEFCheckboxController extends AbstractEEFWidgetController implement
variables.putAll(EEFCheckboxController.this.variableManager.getVariables());
variables.put(EEFExpressionUtils.EEFCheckbox.NEW_VALUE, Boolean.valueOf(checkbox));
- new Eval(EEFCheckboxController.this.interpreter, variables).call(eAttribute, editExpression);
+ EvalFactory.of(EEFCheckboxController.this.interpreter, variables).logIfBlank(eAttribute).call(editExpression);
}
});
}
@@ -93,9 +93,7 @@ public class EEFCheckboxController extends AbstractEEFWidgetController implement
super.refresh();
String valueExpression = this.description.getValueExpression();
- EAttribute eAttribute = EefPackage.Literals.EEF_CHECKBOX_DESCRIPTION__VALUE_EXPRESSION;
-
- this.newEval().call(eAttribute, valueExpression, Boolean.class, EEFCheckboxController.this.newValueConsumer);
+ this.newEval().logIfInvalidType(Boolean.class).call(valueExpression, this.newValueConsumer);
}
/**
diff --git a/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/controllers/EEFGroupController.java b/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/controllers/EEFGroupController.java
index 8ab5f7b36..3d30efd5e 100644
--- a/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/controllers/EEFGroupController.java
+++ b/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/controllers/EEFGroupController.java
@@ -15,7 +15,6 @@ import org.eclipse.eef.EefPackage;
import org.eclipse.eef.core.api.controllers.AbstractEEFController;
import org.eclipse.eef.core.api.controllers.IConsumer;
import org.eclipse.eef.core.api.controllers.IEEFGroupController;
-import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.sirius.common.interpreter.api.IInterpreter;
@@ -103,8 +102,6 @@ public class EEFGroupController extends AbstractEEFController implements IEEFGro
super.refresh();
String labelExpression = this.description.getLabelExpression();
- EAttribute eAttribute = EefPackage.Literals.EEF_WIDGET_DESCRIPTION__LABEL_EXPRESSION;
-
- this.newEval().call(eAttribute, labelExpression, String.class, EEFGroupController.this.newLabelConsumer);
+ this.newEval().logIfInvalidType(String.class).call(labelExpression, this.newLabelConsumer);
}
}
diff --git a/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/controllers/EEFHyperlinkController.java b/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/controllers/EEFHyperlinkController.java
index eb745713f..3d3cc5d0c 100644
--- a/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/controllers/EEFHyperlinkController.java
+++ b/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/controllers/EEFHyperlinkController.java
@@ -21,7 +21,7 @@ import org.eclipse.eef.core.api.EditingContextAdapter;
import org.eclipse.eef.core.api.controllers.AbstractEEFWidgetController;
import org.eclipse.eef.core.api.controllers.IConsumer;
import org.eclipse.eef.core.api.controllers.IEEFHyperlinkController;
-import org.eclipse.eef.core.api.utils.Eval;
+import org.eclipse.eef.core.api.utils.EvalFactory;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.sirius.common.interpreter.api.IInterpreter;
import org.eclipse.sirius.common.interpreter.api.IVariableManager;
@@ -76,9 +76,7 @@ public class EEFHyperlinkController extends AbstractEEFWidgetController implemen
super.refresh();
String valueExpression = this.description.getValueExpression();
- EAttribute eAttribute = EefPackage.Literals.EEF_TEXT_DESCRIPTION__VALUE_EXPRESSION;
-
- this.newEval().call(eAttribute, valueExpression, String.class, EEFHyperlinkController.this.newValueConsumer);
+ this.newEval().logIfInvalidType(String.class).call(valueExpression, this.newValueConsumer);
}
/**
@@ -98,7 +96,7 @@ public class EEFHyperlinkController extends AbstractEEFWidgetController implemen
variables.putAll(EEFHyperlinkController.this.variableManager.getVariables());
variables.put(EEFExpressionUtils.EEFHyperlink.SELECTION, element);
- new Eval(EEFHyperlinkController.this.interpreter, variables).call(attr, expression);
+ EvalFactory.of(EEFHyperlinkController.this.interpreter, variables).logIfBlank(attr).call(expression);
}
});
}
diff --git a/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/controllers/EEFLabelController.java b/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/controllers/EEFLabelController.java
index 76efd31a6..f9adfc062 100644
--- a/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/controllers/EEFLabelController.java
+++ b/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/controllers/EEFLabelController.java
@@ -12,11 +12,9 @@ package org.eclipse.eef.core.internal.controllers;
import org.eclipse.eef.EEFLabelDescription;
import org.eclipse.eef.EEFWidgetDescription;
-import org.eclipse.eef.EefPackage;
import org.eclipse.eef.core.api.controllers.AbstractEEFWidgetController;
import org.eclipse.eef.core.api.controllers.IConsumer;
import org.eclipse.eef.core.api.controllers.IEEFLabelController;
-import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.sirius.common.interpreter.api.IInterpreter;
import org.eclipse.sirius.common.interpreter.api.IVariableManager;
@@ -60,10 +58,9 @@ public class EEFLabelController extends AbstractEEFWidgetController implements I
@Override
public void refresh() {
super.refresh();
- String bodyExpression = this.description.getBodyExpression();
- EAttribute eAttribute = EefPackage.Literals.EEF_LABEL_DESCRIPTION__BODY_EXPRESSION;
- this.newEval().call(eAttribute, bodyExpression, String.class, EEFLabelController.this.newBodyConsumer);
+ String bodyExpression = this.description.getBodyExpression();
+ this.newEval().logIfInvalidType(String.class).call(bodyExpression, this.newBodyConsumer);
}
/**
diff --git a/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/controllers/EEFRadioController.java b/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/controllers/EEFRadioController.java
index 0213f7461..abe4dccb5 100644
--- a/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/controllers/EEFRadioController.java
+++ b/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/controllers/EEFRadioController.java
@@ -23,7 +23,7 @@ import org.eclipse.eef.core.api.EditingContextAdapter;
import org.eclipse.eef.core.api.controllers.AbstractEEFWidgetController;
import org.eclipse.eef.core.api.controllers.IConsumer;
import org.eclipse.eef.core.api.controllers.IEEFRadioController;
-import org.eclipse.eef.core.api.utils.Eval;
+import org.eclipse.eef.core.api.utils.EvalFactory;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.sirius.common.interpreter.api.IInterpreter;
import org.eclipse.sirius.common.interpreter.api.IVariableManager;
@@ -85,7 +85,7 @@ public class EEFRadioController extends AbstractEEFWidgetController implements I
variables.putAll(EEFRadioController.this.variableManager.getVariables());
variables.put(EEFExpressionUtils.EEFText.NEW_VALUE, text);
- new Eval(EEFRadioController.this.interpreter, variables).call(eAttribute, editExpression);
+ EvalFactory.of(EEFRadioController.this.interpreter, variables).logIfBlank(eAttribute).call(editExpression);
}
});
}
@@ -101,7 +101,7 @@ public class EEFRadioController extends AbstractEEFWidgetController implements I
String candidatesExpression = this.description.getCandidatesExpression();
EAttribute candidatesExpressionEAttribute = EefPackage.Literals.EEF_RADIO_DESCRIPTION__CANDIDATES_EXPRESSION;
- this.newEval().call(candidatesExpressionEAttribute, candidatesExpression, new IConsumer<Object>() {
+ this.newEval().logIfBlank(candidatesExpressionEAttribute).call(candidatesExpression, new IConsumer<Object>() {
@Override
public void apply(Object value) {
if (value instanceof Iterable<?>) {
@@ -115,9 +115,7 @@ public class EEFRadioController extends AbstractEEFWidgetController implements I
});
String valueExpression = this.description.getValueExpression();
- EAttribute valueExpressionEAttribute = EefPackage.Literals.EEF_RADIO_DESCRIPTION__VALUE_EXPRESSION;
-
- this.newEval().call(valueExpressionEAttribute, valueExpression, EEFRadioController.this.newValueConsumer);
+ this.newEval().call(valueExpression, EEFRadioController.this.newValueConsumer);
}
/**
diff --git a/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/controllers/EEFReferenceController.java b/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/controllers/EEFReferenceController.java
index 556f5a82f..2d66449ad 100644
--- a/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/controllers/EEFReferenceController.java
+++ b/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/controllers/EEFReferenceController.java
@@ -23,7 +23,7 @@ import org.eclipse.eef.core.api.EditingContextAdapter;
import org.eclipse.eef.core.api.controllers.AbstractEEFWidgetController;
import org.eclipse.eef.core.api.controllers.IConsumer;
import org.eclipse.eef.core.api.controllers.IEEFReferenceController;
-import org.eclipse.eef.core.api.utils.Eval;
+import org.eclipse.eef.core.api.utils.EvalFactory;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.sirius.common.interpreter.api.IInterpreter;
import org.eclipse.sirius.common.interpreter.api.IVariableManager;
@@ -78,9 +78,7 @@ public class EEFReferenceController extends AbstractEEFWidgetController implemen
super.refresh();
String valueExpression = this.description.getValueExpression();
- EAttribute eAttribute = EefPackage.Literals.EEF_REFERENCE_DESCRIPTION__VALUE_EXPRESSION;
-
- this.newEval().call(eAttribute, valueExpression, Object.class, EEFReferenceController.this.newValueConsumer);
+ this.newEval().call(valueExpression, this.newValueConsumer);
}
@Override
@@ -105,7 +103,7 @@ public class EEFReferenceController extends AbstractEEFWidgetController implemen
variables.putAll(EEFReferenceController.this.variableManager.getVariables());
variables.put(EEFExpressionUtils.EEFReference.SELECTION, element);
- new Eval(EEFReferenceController.this.interpreter, variables).call(attr, expression);
+ EvalFactory.of(EEFReferenceController.this.interpreter, variables).logIfBlank(attr).call(expression);
}
});
}
@@ -134,7 +132,7 @@ public class EEFReferenceController extends AbstractEEFWidgetController implemen
variables.putAll(EEFReferenceController.this.variableManager.getVariables());
variables.put(EEFExpressionUtils.EEFReference.SELECTION, elements);
- new Eval(EEFReferenceController.this.interpreter, variables).call(eAttribute, expression);
+ EvalFactory.of(EEFReferenceController.this.interpreter, variables).logIfBlank(eAttribute).call(expression);
}
});
}
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 a04df3b7d..7b997ffa5 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
@@ -23,7 +23,7 @@ import org.eclipse.eef.core.api.EditingContextAdapter;
import org.eclipse.eef.core.api.controllers.AbstractEEFWidgetController;
import org.eclipse.eef.core.api.controllers.IConsumer;
import org.eclipse.eef.core.api.controllers.IEEFSelectController;
-import org.eclipse.eef.core.api.utils.Eval;
+import org.eclipse.eef.core.api.utils.EvalFactory;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.sirius.common.interpreter.api.IInterpreter;
import org.eclipse.sirius.common.interpreter.api.IVariableManager;
@@ -85,7 +85,7 @@ public class EEFSelectController extends AbstractEEFWidgetController implements
variables.putAll(EEFSelectController.this.variableManager.getVariables());
variables.put(EEFExpressionUtils.EEFText.NEW_VALUE, text);
- new Eval(EEFSelectController.this.interpreter, variables).call(eAttribute, editExpression);
+ EvalFactory.of(EEFSelectController.this.interpreter, variables).logIfBlank(eAttribute).call(editExpression);
}
});
}
@@ -102,7 +102,7 @@ public class EEFSelectController extends AbstractEEFWidgetController implements
String candidatesExpression = this.description.getCandidatesExpression();
EAttribute candidatesExpressionEAttribute = EefPackage.Literals.EEF_SELECT_DESCRIPTION__CANDIDATES_EXPRESSION;
- this.newEval().call(candidatesExpressionEAttribute, candidatesExpression, new IConsumer<Object>() {
+ this.newEval().logIfBlank(candidatesExpressionEAttribute).call(candidatesExpression, new IConsumer<Object>() {
@Override
public void apply(Object value) {
if (value instanceof Iterable<?>) {
@@ -116,9 +116,7 @@ public class EEFSelectController extends AbstractEEFWidgetController implements
});
String valueExpression = this.description.getValueExpression();
- EAttribute valueExpressionEAttribute = EefPackage.Literals.EEF_SELECT_DESCRIPTION__VALUE_EXPRESSION;
-
- this.newEval().call(valueExpressionEAttribute, valueExpression, EEFSelectController.this.newValueConsumer);
+ this.newEval().call(valueExpression, this.newValueConsumer);
}
/**
diff --git a/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/controllers/EEFTextController.java b/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/controllers/EEFTextController.java
index b636462fb..ffd968896 100644
--- a/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/controllers/EEFTextController.java
+++ b/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/controllers/EEFTextController.java
@@ -25,7 +25,7 @@ import org.eclipse.eef.core.api.EditingContextAdapter;
import org.eclipse.eef.core.api.controllers.AbstractEEFWidgetController;
import org.eclipse.eef.core.api.controllers.IConsumer;
import org.eclipse.eef.core.api.controllers.IEEFTextController;
-import org.eclipse.eef.core.api.utils.Eval;
+import org.eclipse.eef.core.api.utils.EvalFactory;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.sirius.common.interpreter.api.IInterpreter;
import org.eclipse.sirius.common.interpreter.api.IVariableManager;
@@ -73,7 +73,8 @@ public class EEFTextController extends AbstractEEFWidgetController implements IE
* @param contextAdapter
* The editing context adapter
*/
- public EEFTextController(EEFTextDescription description, IVariableManager variableManager, IInterpreter interpreter, EditingContextAdapter contextAdapter) {
+ public EEFTextController(EEFTextDescription description, IVariableManager variableManager, IInterpreter interpreter,
+ EditingContextAdapter contextAdapter) {
super(variableManager, interpreter);
this.description = description;
this.contextAdapter = contextAdapter;
@@ -98,7 +99,7 @@ public class EEFTextController extends AbstractEEFWidgetController implements IE
variables.putAll(EEFTextController.this.variableManager.getVariables());
variables.put(EEFExpressionUtils.EEFText.NEW_VALUE, text);
- new Eval(EEFTextController.this.interpreter, variables).call(eAttribute, editExpression);
+ EvalFactory.of(EEFTextController.this.interpreter, variables).logIfBlank(eAttribute).call(editExpression);
}
});
}
@@ -117,9 +118,7 @@ public class EEFTextController extends AbstractEEFWidgetController implements IE
super.refresh();
String valueExpression = this.description.getValueExpression();
- EAttribute eAttribute = EefPackage.Literals.EEF_TEXT_DESCRIPTION__VALUE_EXPRESSION;
-
- this.newEval().call(eAttribute, valueExpression, Object.class, EEFTextController.this.newValueConsumer);
+ this.newEval().call(valueExpression, this.newValueConsumer);
}
/**
diff --git a/plugins/org.eclipse.eef.ide.ui.properties/src/org/eclipse/eef/ide/ui/properties/api/EEFTabDescriptor.java b/plugins/org.eclipse.eef.ide.ui.properties/src/org/eclipse/eef/ide/ui/properties/api/EEFTabDescriptor.java
index 0d8bf1a59..9568f62ee 100644
--- a/plugins/org.eclipse.eef.ide.ui.properties/src/org/eclipse/eef/ide/ui/properties/api/EEFTabDescriptor.java
+++ b/plugins/org.eclipse.eef.ide.ui.properties/src/org/eclipse/eef/ide/ui/properties/api/EEFTabDescriptor.java
@@ -15,7 +15,7 @@ import java.util.List;
import org.eclipse.eef.EefPackage;
import org.eclipse.eef.core.api.EEFPage;
-import org.eclipse.eef.core.api.utils.Eval;
+import org.eclipse.eef.core.api.utils.EvalFactory;
import org.eclipse.eef.properties.ui.api.AbstractEEFTabDescriptor;
import org.eclipse.eef.properties.ui.api.IEEFSectionDescriptor;
import org.eclipse.emf.ecore.EAttribute;
@@ -70,7 +70,8 @@ public class EEFTabDescriptor extends AbstractEEFTabDescriptor {
String labelExpression = this.eefPage.getDescription().getLabelExpression();
EAttribute eAttribute = EefPackage.Literals.EEF_PAGE_DESCRIPTION__LABEL_EXPRESSION;
- return new Eval(this.eefPage.getInterpreter(), this.eefPage.getVariableManager()).get(eAttribute, labelExpression, String.class);
+ return EvalFactory.of(this.eefPage.getInterpreter(), this.eefPage.getVariableManager()).logIfBlank(eAttribute).logIfInvalidType(String.class)
+ .evaluate(labelExpression);
}
/**
diff --git a/plugins/org.eclipse.eef.ide.ui/.settings/org.eclipse.jdt.ui.prefs b/plugins/org.eclipse.eef.ide.ui/.settings/org.eclipse.jdt.ui.prefs
index 2c1f856f0..18d37d076 100644
--- a/plugins/org.eclipse.eef.ide.ui/.settings/org.eclipse.jdt.ui.prefs
+++ b/plugins/org.eclipse.eef.ide.ui/.settings/org.eclipse.jdt.ui.prefs
@@ -45,7 +45,7 @@ sp_cleanup.remove_redundant_type_arguments=false
sp_cleanup.remove_trailing_whitespaces=true
sp_cleanup.remove_trailing_whitespaces_all=true
sp_cleanup.remove_trailing_whitespaces_ignore_empty=false
-sp_cleanup.remove_unnecessary_casts=true
+sp_cleanup.remove_unnecessary_casts=false
sp_cleanup.remove_unnecessary_nls_tags=true
sp_cleanup.remove_unused_imports=true
sp_cleanup.remove_unused_local_variables=false
diff --git a/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/api/EEFTab.java b/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/api/EEFTab.java
index 9dec6c4e4..c3296b32b 100644
--- a/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/api/EEFTab.java
+++ b/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/api/EEFTab.java
@@ -13,17 +13,15 @@ package org.eclipse.eef.ide.ui.api;
import java.net.URL;
import org.eclipse.core.runtime.Platform;
-import org.eclipse.eef.EefPackage;
import org.eclipse.eef.common.api.utils.Util;
import org.eclipse.eef.common.ui.api.IEEFFormContainer;
import org.eclipse.eef.core.api.EEFPage;
import org.eclipse.eef.core.api.EEFView;
import org.eclipse.eef.core.api.InputDescriptor;
-import org.eclipse.eef.core.api.utils.Eval;
+import org.eclipse.eef.core.api.utils.EvalFactory;
import org.eclipse.eef.ide.ui.internal.EEFIdeUiPlugin;
import org.eclipse.eef.ide.ui.internal.Updater;
import org.eclipse.eef.ide.ui.internal.widgets.EEFSectionLifecycleManager;
-import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.graphics.Image;
@@ -129,17 +127,15 @@ public class EEFTab {
EEFView eefView = this.eefPage.getView();
- EAttribute labelExpressionEAttribute = EefPackage.Literals.EEF_VIEW_DESCRIPTION__LABEL_EXPRESSION;
String labelExpression = eefView.getDescription().getLabelExpression();
- String title = new Eval(eefView.getInterpreter(), eefView.getVariableManager()).get(labelExpressionEAttribute, labelExpression, String.class);
+ String title = EvalFactory.of(eefView.getInterpreter(), eefView.getVariableManager()).logIfInvalidType(String.class)
+ .evaluate(labelExpression);
if (!Util.isBlank(title)) {
this.formContainer.getForm().setText(title);
}
- EAttribute imageExpressionEAttribute = EefPackage.Literals.EEF_VIEW_DESCRIPTION__IMAGE_EXPRESSION;
String imageExpression = eefView.getDescription().getImageExpression();
- Object object = new Eval(eefView.getInterpreter(), eefView.getVariableManager())
- .get(imageExpressionEAttribute, imageExpression, Object.class);
+ Object object = EvalFactory.of(eefView.getInterpreter(), eefView.getVariableManager()).evaluate(imageExpression);
if (object instanceof URL) {
Image image = EEFIdeUiPlugin.getPlugin().getImage((URL) object);
this.formContainer.getForm().setImage(image);
diff --git a/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/api/widgets/AbstractEEFWidgetLifecycleManager.java b/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/api/widgets/AbstractEEFWidgetLifecycleManager.java
index ec4b6d611..219ef9067 100644
--- a/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/api/widgets/AbstractEEFWidgetLifecycleManager.java
+++ b/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/api/widgets/AbstractEEFWidgetLifecycleManager.java
@@ -18,23 +18,20 @@ import org.eclipse.eef.EEFConditionalStyle;
import org.eclipse.eef.EEFDynamicMappingFor;
import org.eclipse.eef.EEFDynamicMappingIf;
import org.eclipse.eef.EEFGroupDescription;
-import org.eclipse.eef.EEFTextStyle;
import org.eclipse.eef.EEFWidgetDescription;
import org.eclipse.eef.EEFWidgetStyle;
-import org.eclipse.eef.EefPackage;
import org.eclipse.eef.common.api.utils.Util;
import org.eclipse.eef.common.ui.api.EEFWidgetFactory;
import org.eclipse.eef.common.ui.api.IEEFFormContainer;
import org.eclipse.eef.core.api.EditingContextAdapter;
import org.eclipse.eef.core.api.controllers.IConsumer;
import org.eclipse.eef.core.api.controllers.IEEFWidgetController;
-import org.eclipse.eef.core.api.utils.Eval;
+import org.eclipse.eef.core.api.utils.EvalFactory;
import org.eclipse.eef.ide.ui.internal.EEFIdeUiPlugin;
import org.eclipse.eef.ide.ui.internal.Icons;
import org.eclipse.eef.ide.ui.internal.Messages;
import org.eclipse.eef.ide.ui.internal.widgets.styles.EEFColor;
import org.eclipse.eef.ide.ui.internal.widgets.styles.EEFFont;
-import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
@@ -300,16 +297,9 @@ public abstract class AbstractEEFWidgetLifecycleManager extends AbstractEEFLifec
* Label style
*/
private void setLabelFontStyle(EEFWidgetStyle style) {
- // Set font
- setFont(style.getLabelFontNameExpression(), EefPackage.Literals.EEF_WIDGET_STYLE__LABEL_FONT_NAME_EXPRESSION,
- style.getLabelFontSizeExpression(), EefPackage.Literals.EEF_WIDGET_STYLE__LABEL_FONT_SIZE_EXPRESSION,
- style.getLabelFontStyleExpression(), EefPackage.Literals.EEF_WIDGET_STYLE__LABEL_FONT_STYLE_EXPRESSION, label);
-
- // Set background color
- setBackgroundColor(style.getLabelBackgroundColorExpression(), EefPackage.Literals.EEF_WIDGET_STYLE__LABEL_BACKGROUND_COLOR_EXPRESSION, label);
-
- // Set foreground color
- setForegroundColor(style.getLabelForegroundColorExpression(), EefPackage.Literals.EEF_WIDGET_STYLE__LABEL_FOREGROUND_COLOR_EXPRESSION, label);
+ this.setFont(style.getLabelFontNameExpression(), style.getLabelFontSizeExpression(), style.getLabelFontStyleExpression(), label);
+ this.setBackgroundColor(style.getLabelBackgroundColorExpression(), label);
+ this.setForegroundColor(style.getLabelForegroundColorExpression(), label);
}
/**
@@ -325,7 +315,7 @@ public abstract class AbstractEEFWidgetLifecycleManager extends AbstractEEFLifec
EEFWidgetStyle style = defaultStyle;
for (EEFConditionalStyle eefConditionalStyle : conditionalStyles) {
String preconditionExpression = eefConditionalStyle.getPreconditionExpression();
- Boolean preconditionValid = new Eval(interpreter, variableManager).get(preconditionExpression, Boolean.class);
+ Boolean preconditionValid = EvalFactory.of(interpreter, variableManager).logIfInvalidType(Boolean.class).evaluate(preconditionExpression);
if (preconditionValid != null && preconditionValid.booleanValue()) {
style = this.getWidgetStyle(eefConditionalStyle);
}
@@ -356,41 +346,15 @@ public abstract class AbstractEEFWidgetLifecycleManager extends AbstractEEFLifec
}
/**
- * Set the text style.
- *
- * @param style
- * Style
- * @param text
- * The text
- */
- protected void setTextStyle(EEFTextStyle style, StyledText text) {
- if (style != null) {
- // Set font
- setFont(style.getFontNameExpression(), EefPackage.Literals.EEF_TEXT_STYLE__FONT_NAME_EXPRESSION, style.getFontSizeExpression(),
- EefPackage.Literals.EEF_TEXT_STYLE__FONT_SIZE_EXPRESSION, style.getFontStyleExpression(),
- EefPackage.Literals.EEF_TEXT_STYLE__FONT_STYLE_EXPRESSION, text);
-
- // Set background color
- setBackgroundColor(style.getBackgroundColorExpression(), EefPackage.Literals.EEF_TEXT_STYLE__BACKGROUND_COLOR_EXPRESSION, text);
-
- // Set foreground color
- setForegroundColor(style.getForegroundColorExpression(), EefPackage.Literals.EEF_TEXT_STYLE__FOREGROUND_COLOR_EXPRESSION, text);
- }
- }
-
- /**
* Set the foreground color.
*
* @param foregroundColorExpression
* Foreground color expression
- * @param eAttribute
- * The eAttribute
* @param text
* The text
*/
- protected void setForegroundColor(String foregroundColorExpression, EAttribute eAttribute, StyledText text) {
- Eval eval = new Eval(interpreter, variableManager);
- String foregroundColorCode = eval.get(eAttribute, foregroundColorExpression, String.class);
+ protected void setForegroundColor(String foregroundColorExpression, StyledText text) {
+ String foregroundColorCode = EvalFactory.of(interpreter, variableManager).logIfInvalidType(String.class).evaluate(foregroundColorExpression);
if (foregroundColorCode != null && !foregroundColorCode.isEmpty()) {
EEFColor foregroundColor = new EEFColor(foregroundColorCode);
text.setForeground(foregroundColor.getColor());
@@ -401,15 +365,12 @@ public abstract class AbstractEEFWidgetLifecycleManager extends AbstractEEFLifec
* Set the background color.
*
* @param backgroundColorExpression
- * Style
- * @param eAttribute
- * The eAttribute
+ * Background color expression
* @param text
* Text
*/
- protected void setBackgroundColor(String backgroundColorExpression, EAttribute eAttribute, StyledText text) {
- Eval eval = new Eval(interpreter, variableManager);
- String backgroundColorCode = eval.get(eAttribute, backgroundColorExpression, String.class);
+ protected void setBackgroundColor(String backgroundColorExpression, StyledText text) {
+ String backgroundColorCode = EvalFactory.of(interpreter, variableManager).logIfInvalidType(String.class).evaluate(backgroundColorExpression);
if (backgroundColorCode != null && !backgroundColorCode.isEmpty()) {
EEFColor backgroundColor = new EEFColor(backgroundColorCode);
text.setBackground(backgroundColor.getColor());
@@ -421,77 +382,26 @@ public abstract class AbstractEEFWidgetLifecycleManager extends AbstractEEFLifec
*
* @param fontNameExpression
* Font name expression
- * @param fontNameAttribute
- * Font name attribute
* @param fontSizeExpression
* Font size expression
- * @param fontSizeAttribute
- * Font size attribute
* @param fontStyleExpression
* Font style expression
- * @param fontStyleAttribute
- * Font style attribute
* @param text
* Text
- * @param text
*/
- protected void setFont(String fontNameExpression, EAttribute fontNameAttribute, String fontSizeExpression, EAttribute fontSizeAttribute,
- String fontStyleExpression, EAttribute fontStyleAttribute, StyledText text) {
+ protected void setFont(String fontNameExpression, String fontSizeExpression, String fontStyleExpression, StyledText text) {
// Get default font
Font defaultFont = text.getFont();
FontData defaultFontData = defaultFont.getFontData()[0];
- String fontName = getFontName(fontNameExpression, fontNameAttribute, defaultFontData);
- int fontSize = getFontSize(fontSizeExpression, fontSizeAttribute, defaultFontData);
- int fontStyle = getFontStyle(fontStyleExpression, fontStyleAttribute, defaultFontData, text);
- EEFFont font = new EEFFont(fontName, fontSize, fontStyle);
- text.setFont(font.getFont());
- }
- /**
- * Get the font name.
- *
- * @param fontNameExpression
- * Font name expression
- * @param eAttribute
- * The eAttribute
- * @param defaultFontData
- * Default font data
- * @return Font name
- */
- private String getFontName(String fontNameExpression, EAttribute eAttribute, FontData defaultFontData) {
- String fontName = defaultFontData.getName();
- Eval eval = new Eval(interpreter, variableManager);
- if (fontNameExpression != null && !fontNameExpression.isEmpty()) {
- String fontNameValue = eval.get(eAttribute, fontNameExpression, String.class);
- if (fontNameValue != null) {
- // Get font name
- fontName = fontNameValue;
- }
- }
- return fontName;
- }
+ String fontName = EvalFactory.of(interpreter, variableManager).logIfInvalidType(String.class).defaultValue(defaultFontData.getName())
+ .evaluate(fontNameExpression);
+ int fontSize = EvalFactory.of(interpreter, variableManager).logIfInvalidType(Integer.class)
+ .defaultValue(Integer.valueOf(defaultFontData.getHeight())).evaluate(fontSizeExpression).intValue();
- /**
- * Get the font size.
- *
- * @param fontSizeExpression
- * Font size expression
- * @param eAttribute
- * The eAttribute
- * @param defaultFontData
- * Default font data
- * @return Font size
- */
- private int getFontSize(String fontSizeExpression, EAttribute eAttribute, FontData defaultFontData) {
- int fontSize = defaultFontData.getHeight();
- if (fontSizeExpression != null && !fontSizeExpression.isEmpty()) {
- Eval eval = new Eval(interpreter, variableManager);
- Integer fontSizeValue = eval.get(eAttribute, fontSizeExpression, Integer.class);
- if (fontSizeValue != null && fontSizeValue.intValue() != fontSize) {
- fontSize = fontSizeValue.intValue();
- }
- }
- return fontSize;
+ int fontStyle = getFontStyle(fontStyleExpression, defaultFontData, text);
+ EEFFont font = new EEFFont(fontName, fontSize, fontStyle);
+ text.setFont(font.getFont());
}
/**
@@ -499,19 +409,16 @@ public abstract class AbstractEEFWidgetLifecycleManager extends AbstractEEFLifec
*
* @param fontStyleExpression
* Font style expression
- * @param eAttribute
- * The eAttribute
* @param defaultFontData
* Default font data
* @param text
* The text
* @return Font style
*/
- private int getFontStyle(String fontStyleExpression, EAttribute eAttribute, FontData defaultFontData, StyledText text) {
+ private int getFontStyle(String fontStyleExpression, FontData defaultFontData, StyledText text) {
int fontStyle = defaultFontData.getStyle();
if (fontStyleExpression != null && !fontStyleExpression.isEmpty()) {
- Eval eval = new Eval(interpreter, variableManager);
- String fontStyleValue = eval.get(eAttribute, fontStyleExpression, String.class);
+ String fontStyleValue = EvalFactory.of(interpreter, variableManager).logIfInvalidType(String.class).evaluate(fontStyleExpression);
fontStyle = getFontStyle(fontStyleValue, fontStyle, text);
}
return fontStyle;
@@ -582,12 +489,8 @@ public abstract class AbstractEEFWidgetLifecycleManager extends AbstractEEFLifec
* @return True if the widget should be enabled otherwise false.
*/
protected boolean isEnabled() {
- Eval eval = new Eval(interpreter, variableManager);
- Boolean result = eval.get(EefPackage.Literals.EEF_WIDGET_DESCRIPTION__IS_ENABLED_EXPRESSION, getWidgetDescription().getIsEnabledExpression(),
- Boolean.class);
- if (result != null) {
- return result.booleanValue();
- }
- return true;
+ Boolean result = EvalFactory.of(interpreter, variableManager).logIfInvalidType(Boolean.class).defaultValue(Boolean.TRUE)
+ .evaluate(getWidgetDescription().getIsEnabledExpression());
+ return result.booleanValue();
}
}
diff --git a/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/ActionButton.java b/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/ActionButton.java
index 2acbe4200..689516f21 100644
--- a/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/ActionButton.java
+++ b/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/ActionButton.java
@@ -10,13 +10,9 @@
*******************************************************************************/
package org.eclipse.eef.ide.ui.internal.widgets;
-import com.google.common.base.Objects;
-
import org.eclipse.eef.EEFWidgetAction;
-import org.eclipse.eef.EefPackage;
import org.eclipse.eef.common.ui.api.EEFWidgetFactory;
-import org.eclipse.eef.core.api.utils.Eval;
-import org.eclipse.emf.ecore.EAttribute;
+import org.eclipse.eef.core.api.utils.EvalFactory;
import org.eclipse.sirius.common.interpreter.api.IInterpreter;
import org.eclipse.sirius.common.interpreter.api.IVariableManager;
import org.eclipse.swt.SWT;
@@ -65,9 +61,9 @@ public class ActionButton {
IVariableManager variableManager) {
this.action = action;
this.button = widgetFactory.createButton(parent, "", SWT.NONE); //$NON-NLS-1$
+
String expression = action.getLabelExpression();
- EAttribute eAttribute = EefPackage.Literals.EEF_WIDGET_ACTION__LABEL_EXPRESSION;
- String buttonLabel = Objects.firstNonNull(new Eval(interpreter, variableManager).get(eAttribute, expression, String.class), "..."); //$NON-NLS-1$
+ String buttonLabel = EvalFactory.of(interpreter, variableManager).logIfInvalidType(String.class).defaultValue("...").evaluate(expression); //$NON-NLS-1$
button.setText(buttonLabel);
}
diff --git a/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/EEFControlSwitch.java b/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/EEFControlSwitch.java
index 6d95c2a6b..55d2e7e13 100644
--- a/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/EEFControlSwitch.java
+++ b/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/EEFControlSwitch.java
@@ -35,7 +35,7 @@ import org.eclipse.eef.common.api.utils.Util;
import org.eclipse.eef.common.ui.api.IEEFFormContainer;
import org.eclipse.eef.core.api.EEFExpressionUtils;
import org.eclipse.eef.core.api.EditingContextAdapter;
-import org.eclipse.eef.core.api.utils.Eval;
+import org.eclipse.eef.core.api.utils.EvalFactory;
import org.eclipse.eef.ide.ui.api.widgets.IEEFLifecycleManager;
import org.eclipse.eef.ide.ui.api.widgets.IEEFLifecycleManagerProvider;
import org.eclipse.eef.ide.ui.internal.EEFIdeUiPlugin;
@@ -240,8 +240,8 @@ public class EEFControlSwitch {
EAttribute ifExpressionEAttribute = EefPackage.Literals.EEF_DYNAMIC_MAPPING_IF__PREDICATE_EXPRESSION;
- Object domainClassExpressionResult = new Eval(this.interpreter, variableManager).get(domainClassEAttribute, domainClassExpression,
- Object.class);
+ Object domainClassExpressionResult = EvalFactory.of(this.interpreter, variableManager).logIfBlank(domainClassEAttribute)
+ .evaluate(domainClassExpression);
for (Object object : Util.asIterable(domainClassExpressionResult, Object.class)) {
Map<String, Object> switchExpressionVariables = new HashMap<String, Object>();
switchExpressionVariables.put(EEFExpressionUtils.SELF, variableManager.getVariables().get(EEFExpressionUtils.SELF));
@@ -250,8 +250,8 @@ public class EEFControlSwitch {
EEFWidgetDescription eefWidgetDescription = null;
List<EEFDynamicMappingIf> dynamicMappingIfs = dynamicMappingFor.getIfs();
for (EEFDynamicMappingIf dynamicMappingIf : dynamicMappingIfs) {
- Boolean isValid = new Eval(this.interpreter, switchExpressionVariables).get(ifExpressionEAttribute,
- dynamicMappingIf.getPredicateExpression(), Boolean.class);
+ Boolean isValid = EvalFactory.of(this.interpreter, switchExpressionVariables).logIfInvalidType(Boolean.class)
+ .logIfBlank(ifExpressionEAttribute).evaluate(dynamicMappingIf.getPredicateExpression());
if (isValid != null && isValid.booleanValue()) {
eefWidgetDescription = dynamicMappingIf.getWidget();
break;
diff --git a/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/EEFGroupLifecycleManager.java b/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/EEFGroupLifecycleManager.java
index 1516e928d..b9b69220a 100644
--- a/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/EEFGroupLifecycleManager.java
+++ b/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/EEFGroupLifecycleManager.java
@@ -21,7 +21,6 @@ import org.eclipse.eef.EEFGroupDescription;
import org.eclipse.eef.EEFGroupStyle;
import org.eclipse.eef.EEF_TITLE_BAR_STYLE;
import org.eclipse.eef.EEF_TOGGLE_STYLE;
-import org.eclipse.eef.EefPackage;
import org.eclipse.eef.common.ui.api.EEFWidgetFactory;
import org.eclipse.eef.common.ui.api.IEEFFormContainer;
import org.eclipse.eef.core.api.EditingContextAdapter;
@@ -29,7 +28,7 @@ import org.eclipse.eef.core.api.controllers.EEFControllersFactory;
import org.eclipse.eef.core.api.controllers.IConsumer;
import org.eclipse.eef.core.api.controllers.IEEFController;
import org.eclipse.eef.core.api.controllers.IEEFGroupController;
-import org.eclipse.eef.core.api.utils.Eval;
+import org.eclipse.eef.core.api.utils.EvalFactory;
import org.eclipse.eef.ide.ui.api.widgets.AbstractEEFLifecycleManager;
import org.eclipse.eef.ide.ui.api.widgets.IEEFLifecycleManager;
import org.eclipse.eef.ide.ui.internal.widgets.styles.EEFColor;
@@ -127,7 +126,8 @@ public class EEFGroupLifecycleManager extends AbstractEEFLifecycleManager {
if (conditionalStyles != null) {
for (EEFGroupConditionalStyle eefGroupConditionalStyle : conditionalStyles) {
String preconditionExpression = eefGroupConditionalStyle.getPreconditionExpression();
- Boolean preconditionValid = new Eval(interpreter, variableManager).get(preconditionExpression, Boolean.class);
+ Boolean preconditionValid = EvalFactory.of(interpreter, variableManager).logIfInvalidType(Boolean.class)
+ .evaluate(preconditionExpression);
if (preconditionValid != null && preconditionValid.booleanValue()) {
styleDescription = eefGroupConditionalStyle.getStyle();
break;
@@ -151,7 +151,7 @@ public class EEFGroupLifecycleManager extends AbstractEEFLifecycleManager {
this.section.setText(""); //$NON-NLS-1$
String labelExpression = this.description.getLabelExpression();
- new Eval(this.interpreter, this.variableManager).call(labelExpression, String.class, new IConsumer<String>() {
+ EvalFactory.of(this.interpreter, this.variableManager).logIfInvalidType(String.class).call(labelExpression, new IConsumer<String>() {
@Override
public void apply(String value) {
EEFGroupLifecycleManager.this.section.setText(Objects.firstNonNull(value, "")); //$NON-NLS-1$
@@ -170,9 +170,8 @@ public class EEFGroupLifecycleManager extends AbstractEEFLifecycleManager {
if (styleDescription != null) {
// Get background color from expression
- Eval eval = new Eval(interpreter, variableManager);
- String backgroundValue = eval.get(EefPackage.Literals.EEF_GROUP_STYLE__BACKGROUND_COLOR_EXPRESSION,
- styleDescription.getBackgroundColorExpression(), String.class);
+ String backgroundValue = EvalFactory.of(interpreter, variableManager).logIfInvalidType(String.class)
+ .evaluate(styleDescription.getBackgroundColorExpression());
if (backgroundValue != null) {
Color backgroundColor = new EEFColor(backgroundValue).getColor();
this.section.setBackground(backgroundColor);
@@ -180,8 +179,8 @@ public class EEFGroupLifecycleManager extends AbstractEEFLifecycleManager {
}
// Get foreground color from expression
- String foregroundValue = eval.get(EefPackage.Literals.EEF_GROUP_STYLE__FOREGROUND_COLOR_EXPRESSION,
- styleDescription.getForegroundColorExpression(), String.class);
+ String foregroundValue = EvalFactory.of(interpreter, variableManager).logIfInvalidType(String.class)
+ .evaluate(styleDescription.getForegroundColorExpression());
if (foregroundValue != null) {
Color foregroundColor = new EEFColor(foregroundValue).getColor();
groupComposite.setForeground(foregroundColor);
@@ -192,10 +191,10 @@ public class EEFGroupLifecycleManager extends AbstractEEFLifecycleManager {
}
// Get font name and size from expression
- String fontName = eval.get(EefPackage.Literals.EEF_GROUP_STYLE__FONT_NAME_EXPRESSION, styleDescription.getFontNameExpression(),
- String.class);
- Integer fontSize = eval.get(EefPackage.Literals.EEF_GROUP_STYLE__FONT_SIZE_EXPRESSION, styleDescription.getFontSizeExpression(),
- Integer.class);
+ String fontName = EvalFactory.of(interpreter, variableManager).logIfInvalidType(String.class)
+ .evaluate(styleDescription.getFontNameExpression());
+ Integer fontSize = EvalFactory.of(interpreter, variableManager).logIfInvalidType(Integer.class)
+ .evaluate(styleDescription.getFontSizeExpression());
if (fontSize == null) {
fontSize = Integer.valueOf(0);
}
diff --git a/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/EEFHyperlinkLifecycleManager.java b/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/EEFHyperlinkLifecycleManager.java
index 022579512..e146aced7 100644
--- a/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/EEFHyperlinkLifecycleManager.java
+++ b/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/EEFHyperlinkLifecycleManager.java
@@ -21,7 +21,6 @@ import org.eclipse.eef.EEFHyperlinkDescription;
import org.eclipse.eef.EEFHyperlinkStyle;
import org.eclipse.eef.EEFWidgetDescription;
import org.eclipse.eef.EEFWidgetStyle;
-import org.eclipse.eef.EefPackage;
import org.eclipse.eef.common.ui.api.EEFWidgetFactory;
import org.eclipse.eef.common.ui.api.IEEFFormContainer;
import org.eclipse.eef.core.api.EEFExpressionUtils;
@@ -30,7 +29,7 @@ import org.eclipse.eef.core.api.controllers.EEFControllersFactory;
import org.eclipse.eef.core.api.controllers.IConsumer;
import org.eclipse.eef.core.api.controllers.IEEFHyperlinkController;
import org.eclipse.eef.core.api.controllers.IEEFWidgetController;
-import org.eclipse.eef.core.api.utils.Eval;
+import org.eclipse.eef.core.api.utils.EvalFactory;
import org.eclipse.eef.ide.ui.api.widgets.AbstractEEFWidgetLifecycleManager;
import org.eclipse.sirius.common.interpreter.api.IInterpreter;
import org.eclipse.sirius.common.interpreter.api.IVariableManager;
@@ -225,7 +224,8 @@ public class EEFHyperlinkLifecycleManager extends AbstractEEFWidgetLifecycleMana
if (conditionalStyles != null) {
for (EEFHyperlinkConditionalStyle eefHyperlinkConditionalStyle : conditionalStyles) {
String preconditionExpression = eefHyperlinkConditionalStyle.getPreconditionExpression();
- Boolean preconditionValid = new Eval(interpreter, variableManager).get(preconditionExpression, Boolean.class);
+ Boolean preconditionValid = EvalFactory.of(interpreter, variableManager).logIfInvalidType(Boolean.class)
+ .evaluate(preconditionExpression);
if (preconditionValid != null && preconditionValid.booleanValue()) {
hyperlinkStyle = eefHyperlinkConditionalStyle.getStyle();
break;
@@ -243,13 +243,8 @@ public class EEFHyperlinkLifecycleManager extends AbstractEEFWidgetLifecycleMana
*/
protected void setHyperlinkStyle(EEFHyperlinkStyle style) {
if (style != null) {
- // Set font
- setFont(style.getFontNameExpression(), EefPackage.Literals.EEF_HYPERLINK_STYLE__FONT_NAME_EXPRESSION, style.getFontSizeExpression(),
- EefPackage.Literals.EEF_HYPERLINK_STYLE__FONT_SIZE_EXPRESSION, style.getFontStyleExpression(),
- EefPackage.Literals.EEF_HYPERLINK_STYLE__FONT_STYLE_EXPRESSION, hyperlink);
-
- // Set background color
- setBackgroundColor(style.getBackgroundColorExpression(), EefPackage.Literals.EEF_HYPERLINK_STYLE__BACKGROUND_COLOR_EXPRESSION, hyperlink);
+ setFont(style.getFontNameExpression(), style.getFontSizeExpression(), style.getFontStyleExpression(), hyperlink);
+ setBackgroundColor(style.getBackgroundColorExpression(), hyperlink);
}
StyleRange[] styleRanges = hyperlink.getStyleRanges();
StyleRange styleRange;
diff --git a/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/EEFLabelLifecycleManager.java b/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/EEFLabelLifecycleManager.java
index f7f04fccb..8e64b331e 100644
--- a/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/EEFLabelLifecycleManager.java
+++ b/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/EEFLabelLifecycleManager.java
@@ -21,7 +21,6 @@ import org.eclipse.eef.EEFLabelDescription;
import org.eclipse.eef.EEFLabelStyle;
import org.eclipse.eef.EEFWidgetDescription;
import org.eclipse.eef.EEFWidgetStyle;
-import org.eclipse.eef.EefPackage;
import org.eclipse.eef.common.ui.api.EEFWidgetFactory;
import org.eclipse.eef.common.ui.api.IEEFFormContainer;
import org.eclipse.eef.core.api.EditingContextAdapter;
@@ -29,7 +28,7 @@ import org.eclipse.eef.core.api.controllers.EEFControllersFactory;
import org.eclipse.eef.core.api.controllers.IConsumer;
import org.eclipse.eef.core.api.controllers.IEEFLabelController;
import org.eclipse.eef.core.api.controllers.IEEFWidgetController;
-import org.eclipse.eef.core.api.utils.Eval;
+import org.eclipse.eef.core.api.utils.EvalFactory;
import org.eclipse.eef.ide.ui.api.widgets.AbstractEEFWidgetLifecycleManager;
import org.eclipse.sirius.common.interpreter.api.IInterpreter;
import org.eclipse.sirius.common.interpreter.api.IVariableManager;
@@ -125,7 +124,8 @@ public class EEFLabelLifecycleManager extends AbstractEEFWidgetLifecycleManager
if (conditionalStyles != null) {
for (EEFLabelConditionalStyle eefTextConditionalStyle : conditionalStyles) {
String preconditionExpression = eefTextConditionalStyle.getPreconditionExpression();
- Boolean preconditionValid = new Eval(interpreter, variableManager).get(preconditionExpression, Boolean.class);
+ Boolean preconditionValid = EvalFactory.of(interpreter, variableManager).logIfInvalidType(Boolean.class)
+ .evaluate(preconditionExpression);
if (preconditionValid != null && preconditionValid.booleanValue()) {
textStyle = eefTextConditionalStyle.getStyle();
break;
@@ -145,16 +145,9 @@ public class EEFLabelLifecycleManager extends AbstractEEFWidgetLifecycleManager
*/
private void setLabelStyle(EEFLabelStyle style, StyledText text) {
if (style != null) {
- // Set font
- setFont(style.getFontNameExpression(), EefPackage.Literals.EEF_TEXT_STYLE__FONT_NAME_EXPRESSION, style.getFontSizeExpression(),
- EefPackage.Literals.EEF_TEXT_STYLE__FONT_SIZE_EXPRESSION, style.getFontStyleExpression(),
- EefPackage.Literals.EEF_TEXT_STYLE__FONT_STYLE_EXPRESSION, text);
-
- // Set background color
- setBackgroundColor(style.getBackgroundColorExpression(), EefPackage.Literals.EEF_TEXT_STYLE__BACKGROUND_COLOR_EXPRESSION, text);
-
- // Set foreground color
- setForegroundColor(style.getForegroundColorExpression(), EefPackage.Literals.EEF_TEXT_STYLE__FOREGROUND_COLOR_EXPRESSION, text);
+ this.setFont(style.getFontNameExpression(), style.getFontSizeExpression(), style.getFontStyleExpression(), text);
+ this.setBackgroundColor(style.getBackgroundColorExpression(), text);
+ this.setForegroundColor(style.getForegroundColorExpression(), text);
}
}
diff --git a/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/EEFRadioLifecycleManager.java b/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/EEFRadioLifecycleManager.java
index 75aeae08e..9ca90c511 100644
--- a/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/EEFRadioLifecycleManager.java
+++ b/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/EEFRadioLifecycleManager.java
@@ -30,7 +30,7 @@ import org.eclipse.eef.core.api.controllers.EEFControllersFactory;
import org.eclipse.eef.core.api.controllers.IConsumer;
import org.eclipse.eef.core.api.controllers.IEEFRadioController;
import org.eclipse.eef.core.api.controllers.IEEFWidgetController;
-import org.eclipse.eef.core.api.utils.Eval;
+import org.eclipse.eef.core.api.utils.EvalFactory;
import org.eclipse.eef.ide.ui.api.widgets.AbstractEEFWidgetLifecycleManager;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.jface.viewers.ArrayContentProvider;
@@ -286,7 +286,8 @@ public class EEFRadioLifecycleManager extends AbstractEEFWidgetLifecycleManager
variables.put(EEFExpressionUtils.SELF, variableManager.getVariables().get(EEFExpressionUtils.SELF));
variables.put(EEFSelect.CANDIDATE, element);
- return new Eval(EEFRadioLifecycleManager.this.interpreter, variables).get(eAttribute, expression, String.class);
+ return EvalFactory.of(EEFRadioLifecycleManager.this.interpreter, variables).logIfInvalidType(String.class).logIfBlank(eAttribute)
+ .evaluate(expression);
}
}
}
diff --git a/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/EEFReferenceLifecycleManager.java b/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/EEFReferenceLifecycleManager.java
index 74fd3c8ae..877dd9ac3 100644
--- a/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/EEFReferenceLifecycleManager.java
+++ b/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/EEFReferenceLifecycleManager.java
@@ -30,7 +30,7 @@ import org.eclipse.eef.core.api.controllers.EEFControllersFactory;
import org.eclipse.eef.core.api.controllers.IConsumer;
import org.eclipse.eef.core.api.controllers.IEEFReferenceController;
import org.eclipse.eef.core.api.controllers.IEEFWidgetController;
-import org.eclipse.eef.core.api.utils.Eval;
+import org.eclipse.eef.core.api.utils.EvalFactory;
import org.eclipse.eef.ide.ui.api.widgets.AbstractEEFWidgetLifecycleManager;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.jface.viewers.ArrayContentProvider;
@@ -326,10 +326,11 @@ public class EEFReferenceLifecycleManager extends AbstractEEFWidgetLifecycleMana
*/
private void setSingleValuedReference(Object value) {
String expression = description.getDisplayExpression();
- EAttribute eAttribute = EefPackage.Literals.EEF_REFERENCE_DESCRIPTION__DISPLAY_EXPRESSION;
+
Map<String, Object> variables = new HashMap<String, Object>();
variables.put(EEFExpressionUtils.SELF, value);
- String display = new Eval(EEFReferenceLifecycleManager.this.interpreter, variables).get(eAttribute, expression, String.class);
+ String display = EvalFactory.of(EEFReferenceLifecycleManager.this.interpreter, variables).logIfInvalidType(String.class).evaluate(expression);
+
if (display != null) {
if (hyperlink != null && !hyperlink.isDisposed() && !(hyperlink.getText() != null && hyperlink.getText().equals(value))) {
hyperlink.setText(display);
@@ -474,7 +475,8 @@ public class EEFReferenceLifecycleManager extends AbstractEEFWidgetLifecycleMana
String expression = description.getDisplayExpression();
EAttribute eAttribute = EefPackage.Literals.EEF_REFERENCE_DESCRIPTION__DISPLAY_EXPRESSION;
- String value = new Eval(EEFReferenceLifecycleManager.this.interpreter, variables).get(eAttribute, expression, String.class);
+ String value = EvalFactory.of(EEFReferenceLifecycleManager.this.interpreter, variables).logIfInvalidType(String.class)
+ .logIfBlank(eAttribute).evaluate(expression);
cell.setText(value);
super.update(cell);
}
diff --git a/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/EEFSectionLifecycleManager.java b/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/EEFSectionLifecycleManager.java
index a0b512886..b7fe1b240 100644
--- a/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/EEFSectionLifecycleManager.java
+++ b/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/EEFSectionLifecycleManager.java
@@ -133,8 +133,10 @@ public class EEFSectionLifecycleManager extends AbstractEEFLifecycleManager {
public void aboutToBeHidden() {
super.aboutToBeHidden();
- this.container.getForm().removeMessageHyperlinkListener(this.hyperlinkListener);
- this.container.getForm().getMessageManager().removeAllMessages();
+ if (!this.container.getForm().isDisposed()) {
+ this.container.getForm().removeMessageHyperlinkListener(this.hyperlinkListener);
+ this.container.getForm().getMessageManager().removeAllMessages();
+ }
for (IEEFLifecycleManager lifecycleManager : this.lifecycleManagers) {
lifecycleManager.aboutToBeHidden();
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 3da8eaebf..8552b741d 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
@@ -30,7 +30,7 @@ import org.eclipse.eef.core.api.controllers.EEFControllersFactory;
import org.eclipse.eef.core.api.controllers.IConsumer;
import org.eclipse.eef.core.api.controllers.IEEFSelectController;
import org.eclipse.eef.core.api.controllers.IEEFWidgetController;
-import org.eclipse.eef.core.api.utils.Eval;
+import org.eclipse.eef.core.api.utils.EvalFactory;
import org.eclipse.eef.ide.ui.api.widgets.AbstractEEFWidgetLifecycleManager;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.jface.viewers.ArrayContentProvider;
@@ -310,7 +310,8 @@ public class EEFSelectLifecycleManager extends AbstractEEFWidgetLifecycleManager
variables.put(EEFExpressionUtils.SELF, variableManager.getVariables().get(EEFExpressionUtils.SELF));
variables.put(EEFSelect.CANDIDATE, element);
- return new Eval(EEFSelectLifecycleManager.this.interpreter, variables).get(eAttribute, expression, String.class);
+ return EvalFactory.of(EEFSelectLifecycleManager.this.interpreter, variables).logIfInvalidType(String.class).logIfBlank(eAttribute)
+ .evaluate(expression);
}
}
}
diff --git a/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/EEFTextLifecycleManager.java b/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/EEFTextLifecycleManager.java
index ecd23a5d9..9c6502de5 100644
--- a/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/EEFTextLifecycleManager.java
+++ b/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/EEFTextLifecycleManager.java
@@ -27,7 +27,7 @@ import org.eclipse.eef.core.api.controllers.EEFControllersFactory;
import org.eclipse.eef.core.api.controllers.IConsumer;
import org.eclipse.eef.core.api.controllers.IEEFTextController;
import org.eclipse.eef.core.api.controllers.IEEFWidgetController;
-import org.eclipse.eef.core.api.utils.Eval;
+import org.eclipse.eef.core.api.utils.EvalFactory;
import org.eclipse.eef.ide.ui.api.widgets.AbstractEEFWidgetLifecycleManager;
import org.eclipse.eef.ide.ui.internal.widgets.styles.EEFColor;
import org.eclipse.sirius.common.interpreter.api.IInterpreter;
@@ -224,7 +224,12 @@ public class EEFTextLifecycleManager extends AbstractEEFWidgetLifecycleManager {
* Set the style.
*/
private void setStyle() {
- setTextStyle(getTextStyle(), text);
+ EEFTextStyle style = this.getTextStyle();
+ if (style != null) {
+ this.setFont(style.getFontNameExpression(), style.getFontSizeExpression(), style.getFontStyleExpression(), text);
+ this.setBackgroundColor(style.getBackgroundColorExpression(), text);
+ this.setForegroundColor(style.getForegroundColorExpression(), text);
+ }
}
/**
@@ -238,7 +243,8 @@ public class EEFTextLifecycleManager extends AbstractEEFWidgetLifecycleManager {
if (conditionalStyles != null) {
for (EEFTextConditionalStyle eefTextConditionalStyle : conditionalStyles) {
String preconditionExpression = eefTextConditionalStyle.getPreconditionExpression();
- Boolean preconditionValid = new Eval(interpreter, variableManager).get(preconditionExpression, Boolean.class);
+ Boolean preconditionValid = EvalFactory.of(interpreter, variableManager).logIfInvalidType(Boolean.class)
+ .evaluate(preconditionExpression);
if (preconditionValid != null && preconditionValid.booleanValue()) {
textStyle = eefTextConditionalStyle.getStyle();
break;
diff --git a/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/quickfix/EEFQuickFixPage.java b/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/quickfix/EEFQuickFixPage.java
index 91b33d557..7cc12a96f 100644
--- a/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/quickfix/EEFQuickFixPage.java
+++ b/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/quickfix/EEFQuickFixPage.java
@@ -17,7 +17,7 @@ import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.eef.EEFValidationFixDescription;
import org.eclipse.eef.EEFValidationRuleDescription;
import org.eclipse.eef.EefPackage;
-import org.eclipse.eef.core.api.utils.Eval;
+import org.eclipse.eef.core.api.utils.EvalFactory.Eval;
import org.eclipse.eef.ide.ui.internal.EEFIdeUiPlugin;
import org.eclipse.eef.ide.ui.internal.Messages;
import org.eclipse.emf.ecore.EAttribute;
@@ -59,7 +59,7 @@ public class EEFQuickFixPage extends WizardPage {
/**
* The evaluation utility class.
*/
- private Eval eval;
+ private Eval<?> eval;
/**
* The selected {@link IMessage}.
@@ -76,7 +76,7 @@ public class EEFQuickFixPage extends WizardPage {
* @param eval
* The evaluation utility class
*/
- public EEFQuickFixPage(IMessage message, EEFValidationRuleDescription validationRule, Eval eval) {
+ public EEFQuickFixPage(IMessage message, EEFValidationRuleDescription validationRule, Eval<?> eval) {
super(message.getMessage());
this.setTitle(Messages.EEFQuickFixPage_title);
this.setDescription(MessageFormat.format(Messages.EEFQuickFixPage_description, message.getMessage()));
@@ -87,7 +87,7 @@ public class EEFQuickFixPage extends WizardPage {
/**
* Returns the selected {@link IMessage}.
- *
+ *
* @return The selected {@link IMessage}
*/
public IMessage getSelectedMessage() {
@@ -170,7 +170,7 @@ public class EEFQuickFixPage extends WizardPage {
// Run the quick fix using the given eval
EEFValidationFixDescription validationFix = (EEFValidationFixDescription) element;
EAttribute expressionEAttribute = EefPackage.Literals.EEF_VALIDATION_FIX_DESCRIPTION__FIX_EXPRESSION;
- EEFQuickFixPage.this.eval.call(expressionEAttribute, validationFix.getFixExpression());
+ EEFQuickFixPage.this.eval.logIfBlank(expressionEAttribute).call(validationFix.getFixExpression());
}
}
diff --git a/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/quickfix/EEFQuickFixWizard.java b/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/quickfix/EEFQuickFixWizard.java
index 27cf75af4..20211e6fb 100644
--- a/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/quickfix/EEFQuickFixWizard.java
+++ b/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/quickfix/EEFQuickFixWizard.java
@@ -15,7 +15,7 @@ import java.lang.reflect.InvocationTargetException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.eef.EEFValidationRuleDescription;
-import org.eclipse.eef.core.api.utils.Eval;
+import org.eclipse.eef.core.api.utils.EvalFactory.Eval;
import org.eclipse.eef.ide.ui.internal.EEFIdeUiPlugin;
import org.eclipse.eef.ide.ui.internal.Icons;
import org.eclipse.eef.ide.ui.internal.Messages;
@@ -78,7 +78,7 @@ public class EEFQuickFixWizard extends Wizard {
IMessage message = this.messages[0];
if (message.getKey() instanceof EEFValidationRuleDescription && message.getData() instanceof Eval) {
EEFValidationRuleDescription validationRule = (EEFValidationRuleDescription) message.getKey();
- Eval eval = (Eval) message.getData();
+ Eval<?> eval = (Eval<?>) message.getData();
this.quickFixPage = new EEFQuickFixPage(message, validationRule, eval);
this.addPage(this.quickFixPage);
@@ -105,7 +105,7 @@ public class EEFQuickFixWizard extends Wizard {
// The second page will show the quick fixes of the message of the first page
if (message.getKey() instanceof EEFValidationRuleDescription && message.getData() instanceof Eval) {
EEFValidationRuleDescription validationRule = (EEFValidationRuleDescription) message.getKey();
- Eval eval = (Eval) message.getData();
+ Eval<?> eval = (Eval<?>) message.getData();
this.quickFixPage = new EEFQuickFixPage(message, validationRule, eval);
this.quickFixPage.setWizard(this);
return this.quickFixPage;
@@ -159,8 +159,10 @@ public class EEFQuickFixWizard extends Wizard {
subMonitor.worked(1);
if (EEFQuickFixWizard.this.quickFixPage != null) {
+ // Use submonitor.split once we get to Neon as the minimum target platfom
+
EEFQuickFixWizard.this.getShell().getDisplay().readAndDispatch();
- EEFQuickFixWizard.this.quickFixPage.performFinish(subMonitor.split(SUBMONITOR_TASK_WORK));
+ EEFQuickFixWizard.this.quickFixPage.performFinish(subMonitor.newChild(SUBMONITOR_TASK_WORK));
}
}
};
diff --git a/samples/org.eclipse.eef.sample.custom.widget.colorpicker/src/org/eclipse/eef/sample/custom/widget/colorpicker/ColorPickerController.java b/samples/org.eclipse.eef.sample.custom.widget.colorpicker/src/org/eclipse/eef/sample/custom/widget/colorpicker/ColorPickerController.java
index 9404720c2..4d1d6e036 100644
--- a/samples/org.eclipse.eef.sample.custom.widget.colorpicker/src/org/eclipse/eef/sample/custom/widget/colorpicker/ColorPickerController.java
+++ b/samples/org.eclipse.eef.sample.custom.widget.colorpicker/src/org/eclipse/eef/sample/custom/widget/colorpicker/ColorPickerController.java
@@ -14,13 +14,11 @@ import java.util.HashMap;
import java.util.Map;
import org.eclipse.eef.EEFCustomWidgetDescription;
-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.AbstractEEFCustomWidgetController;
import org.eclipse.eef.core.api.controllers.IConsumer;
-import org.eclipse.eef.core.api.utils.Eval;
-import org.eclipse.emf.ecore.EAttribute;
+import org.eclipse.eef.core.api.utils.EvalFactory;
import org.eclipse.sirius.common.interpreter.api.IInterpreter;
import org.eclipse.sirius.common.interpreter.api.IVariableManager;
import org.eclipse.swt.graphics.Color;
@@ -85,9 +83,7 @@ public class ColorPickerController extends AbstractEEFCustomWidgetController imp
super.refresh();
String valueExpression = getCustomExpression(VALUE_EXPRESSION_ID);
- EAttribute eAttribute = EefPackage.Literals.EEF_CUSTOM_EXPRESSION__CUSTOM_EXPRESSION;
-
- this.newEval().call(eAttribute, valueExpression, String.class, new IConsumer<String>() {
+ this.newEval().logIfInvalidType(String.class).call(valueExpression, new IConsumer<String>() {
@Override
public void apply(String value) {
int red = DEFAULT_COLOR_CODE;
@@ -132,13 +128,12 @@ public class ColorPickerController extends AbstractEEFCustomWidgetController imp
@Override
public void run() {
String editExpression = getCustomExpression(EDIT_EXPRESSION_ID);
- EAttribute eAttribute = EefPackage.Literals.EEF_CUSTOM_EXPRESSION__CUSTOM_EXPRESSION;
Map<String, Object> variables = new HashMap<String, Object>();
variables.putAll(ColorPickerController.this.variableManager.getVariables());
variables.put(EEFExpressionUtils.EEFText.NEW_VALUE, color.red + SEPARATOR + color.green + SEPARATOR + color.blue);
- new Eval(ColorPickerController.this.interpreter, variables).call(eAttribute, editExpression);
+ EvalFactory.of(ColorPickerController.this.interpreter, variables).call(editExpression);
}
});
}
diff --git a/tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/AllTests.java b/tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/AllTests.java
index 951a0052f..4b99e3edf 100644
--- a/tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/AllTests.java
+++ b/tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/AllTests.java
@@ -17,6 +17,7 @@ import org.eclipse.eef.tests.internal.controllers.EEFRadioControllerTests;
import org.eclipse.eef.tests.internal.controllers.EEFSelectControllerTests;
import org.eclipse.eef.tests.internal.controllers.EEFTextControllerTests;
import org.eclipse.eef.tests.internal.core.EEFDomainClassTesterTests;
+import org.eclipse.eef.tests.internal.core.EvalTests;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
@@ -27,8 +28,8 @@ import org.junit.runners.Suite.SuiteClasses;
* @author sbegaudeau
*/
@RunWith(Suite.class)
-@SuiteClasses({ EEFDataTests.class, EEFTextControllerTests.class, EEFLabelControllerTests.class, EEFButtonControllerTests.class,
- EEFCheckboxControllerTests.class, EEFRadioControllerTests.class, EEFSelectControllerTests.class, EEFDomainClassTesterTests.class })
+@SuiteClasses({ EvalTests.class, EEFDataTests.class, EEFTextControllerTests.class, EEFLabelControllerTests.class, EEFButtonControllerTests.class,
+ EEFCheckboxControllerTests.class, EEFRadioControllerTests.class, EEFSelectControllerTests.class, EEFDomainClassTesterTests.class })
public final class AllTests {
/**
* The constructor.
diff --git a/tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/core/EvalTests.java b/tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/core/EvalTests.java
new file mode 100644
index 000000000..c8c643b03
--- /dev/null
+++ b/tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/core/EvalTests.java
@@ -0,0 +1,98 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Obeo.
+ * 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:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.eef.tests.internal.core;
+
+import java.util.Map;
+
+import org.eclipse.eef.core.api.utils.EvalFactory;
+import org.eclipse.sirius.common.interpreter.api.EvaluationResult;
+import org.eclipse.sirius.common.interpreter.api.IInterpreter;
+import org.eclipse.sirius.common.interpreter.api.IVariableManager;
+import org.eclipse.sirius.common.interpreter.api.VariableManagerFactory;
+import org.junit.Test;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.nullValue;
+
+/**
+ * Tests of the {@link EvalFactory} utility class.
+ *
+ * @author sbegaudeau
+ */
+@SuppressWarnings({ "checkstyle:javadocmethod" })
+public class EvalTests {
+
+ /**
+ * The first AQL based expression used for the test.
+ */
+ private static final String FIRST_EXPRESSION = "aql:self.name"; //$NON-NLS-1$
+
+ /**
+ * The result of the first AQL based expression.
+ */
+ private static final String FIRST_RESULT = "John Doe"; //$NON-NLS-1$
+
+ /**
+ * The second AQL based expression used for the test.
+ */
+ private static final String SECOND_EXPRESSION = "aql:self.abstract"; //$NON-NLS-1$
+
+ /**
+ * The result of the second AQL based expression.
+ */
+ private static final boolean SECOND_RESULT = true;
+
+ @Test
+ public void testGetResult() {
+ IInterpreter interpreter = (Map<String, Object> variables, String expressionBody) -> {
+ if (FIRST_EXPRESSION.equals(expressionBody)) {
+ return EvaluationResult.of(FIRST_RESULT);
+ }
+ return EvaluationResult.of(Boolean.valueOf(SECOND_RESULT));
+ };
+
+ IVariableManager variableManager = new VariableManagerFactory().createVariableManager();
+ Object result = EvalFactory.of(interpreter, variableManager).evaluate(FIRST_EXPRESSION);
+ assertThat(result, is(FIRST_RESULT));
+ }
+
+ @Test
+ public void testGetDefaultValue() {
+ IInterpreter interpreter = (Map<String, Object> variables, String expressionBody) -> {
+ return EvaluationResult.of(null);
+ };
+ IVariableManager variableManager = new VariableManagerFactory().createVariableManager();
+
+ assertThat(EvalFactory.of(interpreter, variableManager).evaluate(FIRST_EXPRESSION), nullValue());
+
+ Object result = EvalFactory.of(interpreter, variableManager).defaultValue(FIRST_RESULT).evaluate(FIRST_EXPRESSION);
+ assertThat(result, is(FIRST_RESULT));
+ }
+
+ @Test
+ public void testGetCastValue() {
+ IInterpreter interpreter = (Map<String, Object> variables, String expressionBody) -> {
+ if (FIRST_EXPRESSION.equals(expressionBody)) {
+ return EvaluationResult.of(FIRST_RESULT);
+ }
+ return EvaluationResult.of(Boolean.valueOf(SECOND_RESULT));
+ };
+
+ IVariableManager variableManager = new VariableManagerFactory().createVariableManager();
+
+ String stringResult = EvalFactory.of(interpreter, variableManager).logIfInvalidType(String.class).evaluate(FIRST_EXPRESSION);
+ assertThat(stringResult, is(FIRST_RESULT));
+
+ Boolean booleanResult = EvalFactory.of(interpreter, variableManager).logIfInvalidType(Boolean.class).evaluate(SECOND_EXPRESSION);
+ assertThat(booleanResult, is(SECOND_RESULT));
+ }
+}

Back to the top