From 31c25928c9d3a7250c49e61da8ec932481dd267e Mon Sep 17 00:00:00 2001 From: Stéphane Bégaudeau Date: Thu, 15 Dec 2016 10:05:38 +0100 Subject: [refactoring] Improve some code thanks to JavaSE-8.0 Change-Id: If0cb48804b274f430b6aa7b30750c242c366643e Signed-off-by: Stéphane Bégaudeau --- .../widget/colorpicker/ColorPickerController.java | 48 ++++++++++------------ .../colorpicker/ColorPickerLifecycleManager.java | 15 +++---- 2 files changed, 26 insertions(+), 37 deletions(-) (limited to 'samples') 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 4d1d6e036..60d197478 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 @@ -83,24 +83,21 @@ public class ColorPickerController extends AbstractEEFCustomWidgetController imp super.refresh(); String valueExpression = getCustomExpression(VALUE_EXPRESSION_ID); - this.newEval().logIfInvalidType(String.class).call(valueExpression, new IConsumer() { - @Override - public void apply(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); - ColorPickerController.this.newValueConsumer.apply(color); - } catch (NumberFormatException e) { - // TODO Log warning about unexpected result format from the expression. - } + 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.apply(color); + } catch (NumberFormatException e) { + // TODO Log warning about unexpected result format from the expression. } } } @@ -124,17 +121,14 @@ public class ColorPickerController extends AbstractEEFCustomWidgetController imp @Override public void updateValue(final RGB color) { - contextAdapter.performModelChange(new Runnable() { - @Override - public void run() { - String editExpression = getCustomExpression(EDIT_EXPRESSION_ID); + contextAdapter.performModelChange(() -> { + String editExpression = getCustomExpression(EDIT_EXPRESSION_ID); - Map variables = new HashMap(); - variables.putAll(ColorPickerController.this.variableManager.getVariables()); - variables.put(EEFExpressionUtils.EEFText.NEW_VALUE, color.red + SEPARATOR + color.green + SEPARATOR + color.blue); + Map variables = new HashMap(); + variables.putAll(this.variableManager.getVariables()); + variables.put(EEFExpressionUtils.EEFText.NEW_VALUE, color.red + SEPARATOR + color.green + SEPARATOR + color.blue); - EvalFactory.of(ColorPickerController.this.interpreter, variables).call(editExpression); - } + EvalFactory.of(this.interpreter, variables).call(editExpression); }); } diff --git a/samples/org.eclipse.eef.sample.custom.widget.colorpicker/src/org/eclipse/eef/sample/custom/widget/colorpicker/ColorPickerLifecycleManager.java b/samples/org.eclipse.eef.sample.custom.widget.colorpicker/src/org/eclipse/eef/sample/custom/widget/colorpicker/ColorPickerLifecycleManager.java index 8ec8e2374..b70e08bf1 100644 --- a/samples/org.eclipse.eef.sample.custom.widget.colorpicker/src/org/eclipse/eef/sample/custom/widget/colorpicker/ColorPickerLifecycleManager.java +++ b/samples/org.eclipse.eef.sample.custom.widget.colorpicker/src/org/eclipse/eef/sample/custom/widget/colorpicker/ColorPickerLifecycleManager.java @@ -15,7 +15,6 @@ import org.eclipse.eef.EEFWidgetDescription; 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.ide.ui.api.widgets.AbstractEEFWidgetLifecycleManager; import org.eclipse.sirius.common.interpreter.api.IInterpreter; @@ -23,7 +22,6 @@ import org.eclipse.sirius.common.interpreter.api.IVariableManager; import org.eclipse.swt.SWT; import org.eclipse.swt.events.MouseAdapter; import org.eclipse.swt.events.MouseEvent; -import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.RGB; import org.eclipse.swt.widgets.ColorDialog; import org.eclipse.swt.widgets.Composite; @@ -131,14 +129,11 @@ public class ColorPickerLifecycleManager extends AbstractEEFWidgetLifecycleManag }; this.colorPicker.addMouseListener(mouseListener); - this.controller.onNewValue(new IConsumer() { - @Override - public void apply(Color value) { - if (!colorPicker.isDisposed() && !(colorPicker.getBackground() != null && colorPicker.getBackground().equals(value))) { - colorPicker.setImage(colorPicker.getColorImage(value)); - if (!colorPicker.isEnabled()) { - colorPicker.setEnabled(true); - } + this.controller.onNewValue((value) -> { + if (!colorPicker.isDisposed() && !(colorPicker.getBackground() != null && colorPicker.getBackground().equals(value))) { + colorPicker.setImage(colorPicker.getColorImage(value)); + if (!colorPicker.isEnabled()) { + colorPicker.setEnabled(true); } } }); -- cgit v1.2.3