diff options
17 files changed, 134 insertions, 101 deletions
diff --git a/plugins/org.eclipse.eef.core.ext.widgets.reference/src/org/eclipse/eef/core/ext/widgets/reference/internal/EEFExtReferenceController.java b/plugins/org.eclipse.eef.core.ext.widgets.reference/src/org/eclipse/eef/core/ext/widgets/reference/internal/EEFExtReferenceController.java index c864ae087..54cb9d9a3 100644 --- a/plugins/org.eclipse.eef.core.ext.widgets.reference/src/org/eclipse/eef/core/ext/widgets/reference/internal/EEFExtReferenceController.java +++ b/plugins/org.eclipse.eef.core.ext.widgets.reference/src/org/eclipse/eef/core/ext/widgets/reference/internal/EEFExtReferenceController.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2016 Obeo. + * Copyright (c) 2016, 2017 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 @@ -27,7 +27,7 @@ public class EEFExtReferenceController extends AbstractEEFWidgetController { /** * The description. */ - private EEFExtReferenceDescription description; + private final EEFExtReferenceDescription description; /** * The constructor. diff --git a/plugins/org.eclipse.eef.core/plugin.properties b/plugins/org.eclipse.eef.core/plugin.properties index e8c4d7b9c..87c7c7015 100644 --- a/plugins/org.eclipse.eef.core/plugin.properties +++ b/plugins/org.eclipse.eef.core/plugin.properties @@ -1,4 +1,4 @@ -# Copyright (c) 2015, 2016 Obeo. +# Copyright (c) 2015, 2017 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 @@ -10,4 +10,3 @@ providerName = Eclipse Modeling Project AbstractEEFWidgetController_InvalidValueForExpression=The expression ''{0}'' should return a value with the type {1}, it has returned instead {2} -AbstractEEFWidgetController_NoCustomExpressionFoundForID=No custom expression found for the identifier ''{0}''.
\ No newline at end of file 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 25f6560b0..b4069e19f 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 @@ -14,6 +14,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.function.Consumer; import org.eclipse.core.runtime.IStatus; @@ -42,17 +43,17 @@ public abstract class AbstractEEFController implements IEEFController { /** * The interpreter. */ - protected IInterpreter interpreter; + protected final IInterpreter interpreter; /** * The variable manager. */ - protected IVariableManager variableManager; + protected final IVariableManager variableManager; /** * The editing context adapter. */ - protected EditingContextAdapter editingContextAdapter; + protected final EditingContextAdapter editingContextAdapter; /** * The consumer of the validation messages. @@ -113,9 +114,7 @@ public abstract class AbstractEEFController implements IEEFController { public void refresh() { List<IValidationRuleResult> validationRuleResults = this.getValidationRuleResults(this.getValidationRulesContainer(), this.getValidationRulesReference()); - if (this.validationConsumer != null) { - this.validationConsumer.accept(validationRuleResults); - } + Optional.ofNullable(this.validationConsumer).ifPresent(consumer -> consumer.accept(validationRuleResults)); } /** 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 589a606e6..9e7a902fa 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2016 Obeo. + * Copyright (c) 2016, 2017 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 @@ -10,14 +10,12 @@ *******************************************************************************/ package org.eclipse.eef.core.api.controllers; -import java.text.MessageFormat; +import java.util.Optional; import org.eclipse.eef.EEFCustomExpression; import org.eclipse.eef.EEFCustomWidgetDescription; import org.eclipse.eef.EefPackage; import org.eclipse.eef.core.api.EditingContextAdapter; -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.IInterpreter; import org.eclipse.sirius.common.interpreter.api.IVariableManager; @@ -31,7 +29,7 @@ public abstract class AbstractEEFCustomWidgetController extends AbstractEEFWidge /** * The description. */ - protected EEFCustomWidgetDescription description; + protected final EEFCustomWidgetDescription description; /** * The constructor. @@ -57,29 +55,23 @@ public abstract class AbstractEEFCustomWidgetController extends AbstractEEFWidge * @see org.eclipse.eef.core.api.controllers.AbstractEEFWidgetController#getDescription() */ @Override - protected abstract EEFCustomWidgetDescription getDescription(); + protected EEFCustomWidgetDescription getDescription() { + return this.description; + } /** - * Get the custom expression. + * Get the custom expression with the given id. * * @param customExpressionId * Identifier of the custom expression - * @return The custom expression + * @return An optional with the custom expression or an empty optional if none could be found */ - protected String getCustomExpression(String customExpressionId) { - EEFCustomWidgetDescription customDescription = getDescription(); - if (customDescription != null) { - for (EEFCustomExpression eefCustomExpression : customDescription.getCustomExpressions()) { - if (eefCustomExpression != null && customExpressionId != null && customExpressionId.equals(eefCustomExpression.getIdentifier())) { - return eefCustomExpression.getCustomExpression(); - } - } - } - - String message = MessageFormat.format(Messages.AbstractEEFWidgetController_NoCustomExpressionFoundForID, customExpressionId); - EEFCorePlugin.getPlugin().error(message); + protected Optional<String> getCustomExpression(String customExpressionId) { + Optional<String> optionalCustomExpression = this.getDescription().getCustomExpressions().stream().filter(eefCustomExpression -> { + return customExpressionId != null && customExpressionId.equals(eefCustomExpression.getIdentifier()); + }).map(EEFCustomExpression::getCustomExpression).findFirst(); - return null; + return optionalCustomExpression; } /** @@ -89,13 +81,11 @@ public abstract class AbstractEEFCustomWidgetController extends AbstractEEFWidge * Identifier of the custom expression to execute */ protected void executeCommandExpression(final String customExpressionId) { - this.editingContextAdapter.performModelChange(new Runnable() { - @Override - public void run() { - String pushExpression = getCustomExpression(customExpressionId); + this.editingContextAdapter.performModelChange(() -> { + this.getCustomExpression(customExpressionId).ifPresent(expression -> { EAttribute attr = EefPackage.Literals.EEF_CUSTOM_EXPRESSION__CUSTOM_EXPRESSION; - AbstractEEFCustomWidgetController.this.newEval().logIfBlank(attr).call(pushExpression); - } + AbstractEEFCustomWidgetController.this.newEval().logIfBlank(attr).call(expression); + }); }); } 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 9b406cfdc..771367fc5 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 @@ -10,6 +10,7 @@ *******************************************************************************/ package org.eclipse.eef.core.api.controllers; +import java.util.Optional; import java.util.function.Consumer; import org.eclipse.eef.EEFWidgetDescription; @@ -128,7 +129,9 @@ public abstract class AbstractEEFWidgetController extends AbstractEEFController super.refresh(); String labelExpression = this.getDescription().getLabelExpression(); - this.newEval().logIfInvalidType(String.class).call(labelExpression, this.newLabelConsumer); + Optional.ofNullable(this.newLabelConsumer).ifPresent(consumer -> { + this.newEval().logIfInvalidType(String.class).call(labelExpression, consumer); + }); } /** @@ -139,7 +142,9 @@ public abstract class AbstractEEFWidgetController extends AbstractEEFController @Override public void computeHelp() { String helpExpression = this.getDescription().getHelpExpression(); - this.newEval().logIfInvalidType(String.class).call(helpExpression, this.newHelpConsumer); + Optional.ofNullable(this.newHelpConsumer).ifPresent(consumer -> { + this.newEval().logIfInvalidType(String.class).call(helpExpression, consumer); + }); } } diff --git a/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/Messages.java b/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/Messages.java index 2cfd90d05..ed678a16c 100644 --- a/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/Messages.java +++ b/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/Messages.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2016 Obeo. + * Copyright (c) 2016, 2017 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 @@ -27,10 +27,6 @@ public final class Messages { // CHECKSTYLE:OFF @TranslatableMessage public static String AbstractEEFWidgetController_InvalidValueForExpression; - - @TranslatableMessage - public static String AbstractEEFWidgetController_NoCustomExpressionFoundForID; - // CHECKSTYLE:ON /** 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 87796ddd4..428c57d8e 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 @@ -10,6 +10,7 @@ *******************************************************************************/ package org.eclipse.eef.core.internal.controllers; +import java.util.Optional; import java.util.function.Consumer; import org.eclipse.core.runtime.IStatus; @@ -32,7 +33,7 @@ public class EEFButtonController extends AbstractEEFWidgetController implements /** * The description. */ - private EEFButtonDescription description; + private final EEFButtonDescription description; /** * The consumer of a new value of the button's label. @@ -77,7 +78,9 @@ public class EEFButtonController extends AbstractEEFWidgetController implements super.refresh(); String buttonLabelExpression = this.description.getButtonLabelExpression(); - this.newEval().logIfInvalidType(String.class).defaultValue("...").call(buttonLabelExpression, this.newButtonLabelConsumer); //$NON-NLS-1$ + Optional.ofNullable(this.newButtonLabelConsumer).ifPresent(consumer -> { + this.newEval().logIfInvalidType(String.class).defaultValue("...").call(buttonLabelExpression, consumer); //$NON-NLS-1$ + }); } @Override 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 c049dabb9..16b423072 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 @@ -12,6 +12,7 @@ package org.eclipse.eef.core.internal.controllers; import java.util.HashMap; import java.util.Map; +import java.util.Optional; import java.util.function.Consumer; import org.eclipse.core.runtime.IStatus; @@ -36,7 +37,7 @@ public class EEFCheckboxController extends AbstractEEFWidgetController implement /** * The description. */ - private EEFCheckboxDescription description; + private final EEFCheckboxDescription description; /** * The consumer of a new value of the checkbox. @@ -85,7 +86,9 @@ public class EEFCheckboxController extends AbstractEEFWidgetController implement super.refresh(); String valueExpression = this.description.getValueExpression(); - this.newEval().logIfInvalidType(Boolean.class).call(valueExpression, this.newValueConsumer); + Optional.ofNullable(this.newValueConsumer).ifPresent(consumer -> { + this.newEval().logIfInvalidType(Boolean.class).call(valueExpression, consumer); + }); } /** 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 1f7d90b82..3062a4e09 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 @@ -10,6 +10,7 @@ *******************************************************************************/ package org.eclipse.eef.core.internal.controllers; +import java.util.Optional; import java.util.function.Consumer; import org.eclipse.eef.EEFGroupDescription; @@ -32,10 +33,10 @@ public class EEFGroupController extends AbstractEEFController implements IEEFGro /** * The description. */ - private EEFGroupDescription description; + private final EEFGroupDescription description; /** - * The label consumer. + * The new label consumer. */ private Consumer<String> newLabelConsumer; @@ -107,6 +108,8 @@ public class EEFGroupController extends AbstractEEFController implements IEEFGro super.refresh(); String labelExpression = this.description.getLabelExpression(); - this.newEval().logIfInvalidType(String.class).call(labelExpression, this.newLabelConsumer); + Optional.ofNullable(this.newLabelConsumer).ifPresent(consumer -> { + this.newEval().logIfInvalidType(String.class).call(labelExpression, consumer); + }); } } 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 3456862c0..80af7bf2c 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 @@ -39,7 +39,7 @@ public class EEFHyperlinkController extends AbstractEEFWidgetController implemen /** * The description. */ - private EEFHyperlinkDescription description; + private final EEFHyperlinkDescription description; /** * The consumer of a new value of the text. @@ -74,8 +74,9 @@ public class EEFHyperlinkController extends AbstractEEFWidgetController implemen super.refresh(); String valueExpression = this.description.getValueExpression(); - Object valueExpressionResult = this.newEval().evaluate(valueExpression); - this.newValueConsumer.accept(valueExpressionResult); + Optional.ofNullable(this.newValueConsumer).ifPresent(consumer -> { + this.newEval().call(valueExpression, consumer); + }); } /** 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 b89398869..edfdcbb03 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,6 +12,7 @@ package org.eclipse.eef.core.internal.controllers; import java.util.HashMap; import java.util.Map; +import java.util.Optional; import java.util.function.Consumer; import org.eclipse.core.runtime.IStatus; @@ -38,7 +39,7 @@ public class EEFLabelController extends AbstractEEFWidgetController implements I /** * The description. */ - private EEFLabelDescription description; + private final EEFLabelDescription description; /** * The consumer of the new body. @@ -77,14 +78,16 @@ public class EEFLabelController extends AbstractEEFWidgetController implements I Object valueExpressionResult = this.newEval().evaluate(valueExpression); String displayExpression = this.description.getDisplayExpression(); - if (!Util.isBlank(displayExpression)) { - Map<String, Object> variables = new HashMap<String, Object>(); - variables.putAll(this.variableManager.getVariables()); - variables.put(EEFExpressionUtils.EEFReference.VALUE, valueExpressionResult); - EvalFactory.of(this.interpreter, variables).logIfInvalidType(String.class).call(displayExpression, this.newValueConsumer); - } else if (valueExpressionResult != null) { - this.newValueConsumer.accept(valueExpressionResult.toString()); - } + Optional.ofNullable(this.newValueConsumer).ifPresent(consumer -> { + if (!Util.isBlank(displayExpression)) { + Map<String, Object> variables = new HashMap<String, Object>(); + variables.putAll(this.variableManager.getVariables()); + variables.put(EEFExpressionUtils.EEFReference.VALUE, valueExpressionResult); + EvalFactory.of(this.interpreter, variables).logIfInvalidType(String.class).call(displayExpression, consumer); + } else if (valueExpressionResult != null) { + newValueConsumer.accept(valueExpressionResult.toString()); + } + }); } /** diff --git a/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/controllers/EEFListController.java b/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/controllers/EEFListController.java index 3841501a5..fbe4c61e1 100644 --- a/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/controllers/EEFListController.java +++ b/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/controllers/EEFListController.java @@ -13,6 +13,7 @@ package org.eclipse.eef.core.internal.controllers; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.function.Consumer; import org.eclipse.core.runtime.IStatus; @@ -38,7 +39,7 @@ public class EEFListController extends AbstractEEFWidgetController implements IE /** * The description. */ - private EEFListDescription description; + private final EEFListDescription description; /** * The consumer of a new value of the list. @@ -73,7 +74,9 @@ public class EEFListController extends AbstractEEFWidgetController implements IE super.refresh(); String valueExpression = this.description.getValueExpression(); - this.newEval().call(valueExpression, this.newValueConsumer); + Optional.ofNullable(this.newValueConsumer).ifPresent(consumer -> { + this.newEval().call(valueExpression, consumer); + }); } /** 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 d63debba4..5c52e3b3b 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 @@ -14,6 +14,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.function.Consumer; import org.eclipse.core.runtime.IStatus; @@ -38,7 +39,7 @@ public class EEFRadioController extends AbstractEEFWidgetController implements I /** * The description. */ - private EEFRadioDescription description; + private final EEFRadioDescription description; /** * The consumer of a new value of the combo. @@ -99,12 +100,16 @@ public class EEFRadioController extends AbstractEEFWidgetController implements I ((Iterable<?>) value).forEach(object -> candidates.add(object)); - this.newCandidatesConsumer.accept(candidates); + Optional.ofNullable(this.newCandidatesConsumer).ifPresent(consumer -> { + consumer.accept(candidates); + }); } }); String valueExpression = this.description.getValueExpression(); - this.newEval().call(valueExpression, EEFRadioController.this.newValueConsumer); + Optional.ofNullable(this.newValueConsumer).ifPresent(consumer -> { + this.newEval().call(valueExpression, consumer); + }); } /** 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 c140fffcc..92fccc0d1 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 @@ -16,6 +16,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.function.Consumer; import org.eclipse.core.runtime.IStatus; @@ -40,7 +41,7 @@ public class EEFSelectController extends AbstractEEFWidgetController implements /** * The description. */ - private EEFSelectDescription description; + private final EEFSelectDescription description; /** * The consumer of a new value of the combo. @@ -102,12 +103,16 @@ public class EEFSelectController extends AbstractEEFWidgetController implements Iterators.addAll(candidates, ((Iterable<?>) value).iterator()); - this.newCandidatesConsumer.accept(candidates); + Optional.ofNullable(this.newCandidatesConsumer).ifPresent(consumer -> { + consumer.accept(candidates); + }); } }); String valueExpression = this.description.getValueExpression(); - this.newEval().call(valueExpression, this.newValueConsumer); + Optional.ofNullable(this.newValueConsumer).ifPresent(consumer -> { + this.newEval().call(valueExpression, consumer); + }); } /** 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 f9654ef39..9a831d9c5 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 @@ -12,6 +12,7 @@ package org.eclipse.eef.core.internal.controllers; import java.util.HashMap; import java.util.Map; +import java.util.Optional; import java.util.function.Consumer; import org.eclipse.core.runtime.IStatus; @@ -36,7 +37,7 @@ public class EEFTextController extends AbstractEEFWidgetController implements IE /** * The description. */ - private EEFTextDescription description; + private final EEFTextDescription description; /** * The consumer of a new value of the text. @@ -85,7 +86,9 @@ public class EEFTextController extends AbstractEEFWidgetController implements IE super.refresh(); String valueExpression = this.description.getValueExpression(); - this.newEval().call(valueExpression, this.newValueConsumer); + Optional.ofNullable(this.newValueConsumer).ifPresent(consumer -> { + this.newEval().call(valueExpression, consumer); + }); } /** diff --git a/plugins/org.eclipse.eef.ide.ui.ext.widgets.reference/src/org/eclipse/eef/ide/ui/ext/widgets/reference/internal/AbstractEEFExtReferenceLifecycleManager.java b/plugins/org.eclipse.eef.ide.ui.ext.widgets.reference/src/org/eclipse/eef/ide/ui/ext/widgets/reference/internal/AbstractEEFExtReferenceLifecycleManager.java index bca933bbc..879f5f22b 100644 --- a/plugins/org.eclipse.eef.ide.ui.ext.widgets.reference/src/org/eclipse/eef/ide/ui/ext/widgets/reference/internal/AbstractEEFExtReferenceLifecycleManager.java +++ b/plugins/org.eclipse.eef.ide.ui.ext.widgets.reference/src/org/eclipse/eef/ide/ui/ext/widgets/reference/internal/AbstractEEFExtReferenceLifecycleManager.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2016 Obeo. + * Copyright (c) 2016, 2017 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 @@ -49,17 +49,17 @@ public abstract class AbstractEEFExtReferenceLifecycleManager extends AbstractEE /** * The description. */ - protected EEFExtReferenceDescription description; + protected final EEFExtReferenceDescription description; /** * The target. */ - protected EObject target; + protected final EObject target; /** * The EReference. */ - protected EReference eReference; + protected final EReference eReference; /** * The controller. 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 a71a5b3a0..b69a0bdd7 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 @@ -12,6 +12,7 @@ package org.eclipse.eef.sample.custom.widget.colorpicker; import java.util.HashMap; import java.util.Map; +import java.util.Optional; import java.util.function.Consumer; import org.eclipse.eef.EEFCustomWidgetDescription; @@ -82,26 +83,40 @@ public class ColorPickerController extends AbstractEEFCustomWidgetController imp public void refresh() { super.refresh(); - String valueExpression = getCustomExpression(VALUE_EXPRESSION_ID); - this.newEval().logIfInvalidType(String.class).call(valueExpression, (value) -> { - int red = DEFAULT_COLOR_CODE; - int green = DEFAULT_COLOR_CODE; - int blue = DEFAULT_COLOR_CODE; - if (value != null) { - String[] rgb = value.split(SEPARATOR); - if (rgb.length == 3) { - try { - red = Integer.parseInt(rgb[0]); - green = Integer.parseInt(rgb[1]); - blue = Integer.parseInt(rgb[2]); - Color color = ColorHelper.getColor(red, green, blue); - ColorPickerController.this.newValueConsumer.accept(color); - } catch (NumberFormatException e) { - // TODO Log warning about unexpected result format from the expression. - } + Optional<String> optionalValueExpression = this.getCustomExpression(VALUE_EXPRESSION_ID); + optionalValueExpression.ifPresent(valueExpression -> { + this.newEval().logIfInvalidType(String.class).call(valueExpression, (value) -> { + this.computeNewColorValue(value); + }); + }); + } + + /** + * Computes the new value of the color. + * + * @param value + * The string representation of the new color + */ + private void computeNewColorValue(String value) { + int red = DEFAULT_COLOR_CODE; + int green = DEFAULT_COLOR_CODE; + int blue = DEFAULT_COLOR_CODE; + if (value != null) { + String[] rgb = value.split(SEPARATOR); + if (rgb.length == 3) { + try { + red = Integer.parseInt(rgb[0]); + green = Integer.parseInt(rgb[1]); + blue = Integer.parseInt(rgb[2]); + Color color = ColorHelper.getColor(red, green, blue); + Optional.ofNullable(this.newValueConsumer).ifPresent(consumer -> { + consumer.accept(color); + }); + } catch (@SuppressWarnings("unused") NumberFormatException e) { + // TODO Log warning about unexpected result format from the expression. } } - }); + } } @Override @@ -122,13 +137,13 @@ public class ColorPickerController extends AbstractEEFCustomWidgetController imp @Override public void updateValue(final RGB color) { this.editingContextAdapter.performModelChange(() -> { - String editExpression = getCustomExpression(EDIT_EXPRESSION_ID); - - Map<String, Object> variables = new HashMap<String, Object>(); - variables.putAll(this.variableManager.getVariables()); - variables.put(EEFExpressionUtils.EEFText.NEW_VALUE, color.red + SEPARATOR + color.green + SEPARATOR + color.blue); + this.getCustomExpression(EDIT_EXPRESSION_ID).ifPresent(editExpression -> { + Map<String, Object> variables = new HashMap<String, Object>(); + variables.putAll(this.variableManager.getVariables()); + variables.put(EEFExpressionUtils.EEFText.NEW_VALUE, color.red + SEPARATOR + color.green + SEPARATOR + color.blue); - EvalFactory.of(this.interpreter, variables).call(editExpression); + EvalFactory.of(this.interpreter, variables).call(editExpression); + }); }); } |