Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMélanie Bats2016-02-16 11:46:07 -0500
committerMélanie Bats2016-03-24 12:38:28 -0400
commit5ff35902e0f45da1aa73abb0424f1108b51adc7f (patch)
treeb033886449fb2b186372f46c8f514be7da3b3ddb /samples
parent2215835d7f91abc0c096662d71abce8b0b805ee3 (diff)
downloadorg.eclipse.eef-5ff35902e0f45da1aa73abb0424f1108b51adc7f.tar.gz
org.eclipse.eef-5ff35902e0f45da1aa73abb0424f1108b51adc7f.tar.xz
org.eclipse.eef-5ff35902e0f45da1aa73abb0424f1108b51adc7f.zip
Custom widgets support.
Change-Id: I311a831f071ba9c85594c68c21836a584a8a55e6 Signed-off-by: Mélanie Bats <melanie.bats@obeo.fr>
Diffstat (limited to 'samples')
-rw-r--r--samples/org.eclipse.eef.sample.custom.widget.colorpicker/.checkstyle10
-rw-r--r--samples/org.eclipse.eef.sample.custom.widget.colorpicker/.classpath7
-rw-r--r--samples/org.eclipse.eef.sample.custom.widget.colorpicker/.project34
-rw-r--r--samples/org.eclipse.eef.sample.custom.widget.colorpicker/.settings/org.eclipse.jdt.core.prefs7
-rw-r--r--samples/org.eclipse.eef.sample.custom.widget.colorpicker/META-INF/MANIFEST.MF32
-rw-r--r--samples/org.eclipse.eef.sample.custom.widget.colorpicker/about.html28
-rw-r--r--samples/org.eclipse.eef.sample.custom.widget.colorpicker/build.properties16
-rw-r--r--samples/org.eclipse.eef.sample.custom.widget.colorpicker/icons/16x16/Add_16x16.gifbin0 -> 318 bytes
-rw-r--r--samples/org.eclipse.eef.sample.custom.widget.colorpicker/icons/16x16/Create_16x16.gifbin0 -> 124 bytes
-rw-r--r--samples/org.eclipse.eef.sample.custom.widget.colorpicker/icons/16x16/Delete_16x16.gifbin0 -> 351 bytes
-rw-r--r--samples/org.eclipse.eef.sample.custom.widget.colorpicker/plugin.properties9
-rw-r--r--samples/org.eclipse.eef.sample.custom.widget.colorpicker/plugin.xml14
-rw-r--r--samples/org.eclipse.eef.sample.custom.widget.colorpicker/src/org/eclipse/eef/sample/custom/widget/colorpicker/ColorHelper.java95
-rw-r--r--samples/org.eclipse.eef.sample.custom.widget.colorpicker/src/org/eclipse/eef/sample/custom/widget/colorpicker/ColorPicker.java121
-rw-r--r--samples/org.eclipse.eef.sample.custom.widget.colorpicker/src/org/eclipse/eef/sample/custom/widget/colorpicker/ColorPickerController.java149
-rw-r--r--samples/org.eclipse.eef.sample.custom.widget.colorpicker/src/org/eclipse/eef/sample/custom/widget/colorpicker/ColorPickerLifecycleManager.java169
-rw-r--r--samples/org.eclipse.eef.sample.custom.widget.colorpicker/src/org/eclipse/eef/sample/custom/widget/colorpicker/ColorPickerPlugin.java75
-rw-r--r--samples/org.eclipse.eef.sample.custom.widget.colorpicker/src/org/eclipse/eef/sample/custom/widget/colorpicker/ColorPickerProvider.java32
-rw-r--r--samples/org.eclipse.eef.sample.custom.widget.colorpicker/src/org/eclipse/eef/sample/custom/widget/colorpicker/IColorPickerController.java47
19 files changed, 845 insertions, 0 deletions
diff --git a/samples/org.eclipse.eef.sample.custom.widget.colorpicker/.checkstyle b/samples/org.eclipse.eef.sample.custom.widget.colorpicker/.checkstyle
new file mode 100644
index 000000000..121faf77d
--- /dev/null
+++ b/samples/org.eclipse.eef.sample.custom.widget.colorpicker/.checkstyle
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<fileset-config file-format-version="1.2.0" simple-config="true" sync-formatter="false">
+ <local-check-config name="EEF" location="/org.eclipse.eef.releng/codestyle/EEFCheckstyleConfiguration.xml" type="project" description="">
+ <additional-data name="protect-config-file" value="false"/>
+ </local-check-config>
+ <fileset name="all" enabled="true" check-config-name="EEF" local="true">
+ <file-match-pattern match-pattern="." include-pattern="true"/>
+ </fileset>
+</fileset-config>
diff --git a/samples/org.eclipse.eef.sample.custom.widget.colorpicker/.classpath b/samples/org.eclipse.eef.sample.custom.widget.colorpicker/.classpath
new file mode 100644
index 000000000..ad32c83a7
--- /dev/null
+++ b/samples/org.eclipse.eef.sample.custom.widget.colorpicker/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/samples/org.eclipse.eef.sample.custom.widget.colorpicker/.project b/samples/org.eclipse.eef.sample.custom.widget.colorpicker/.project
new file mode 100644
index 000000000..c4edcd13d
--- /dev/null
+++ b/samples/org.eclipse.eef.sample.custom.widget.colorpicker/.project
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.eef.sample.custom.widget.colorpicker</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>net.sf.eclipsecs.core.CheckstyleBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>net.sf.eclipsecs.core.CheckstyleNature</nature>
+ </natures>
+</projectDescription>
diff --git a/samples/org.eclipse.eef.sample.custom.widget.colorpicker/.settings/org.eclipse.jdt.core.prefs b/samples/org.eclipse.eef.sample.custom.widget.colorpicker/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 000000000..c537b6306
--- /dev/null
+++ b/samples/org.eclipse.eef.sample.custom.widget.colorpicker/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,7 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
diff --git a/samples/org.eclipse.eef.sample.custom.widget.colorpicker/META-INF/MANIFEST.MF b/samples/org.eclipse.eef.sample.custom.widget.colorpicker/META-INF/MANIFEST.MF
new file mode 100644
index 000000000..9d484e878
--- /dev/null
+++ b/samples/org.eclipse.eef.sample.custom.widget.colorpicker/META-INF/MANIFEST.MF
@@ -0,0 +1,32 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: %pluginName
+Bundle-SymbolicName: org.eclipse.eef.sample.custom.widget.colorpicker;singleton:=true
+Bundle-Version: 1.6.0.qualifier
+Bundle-Vendor: %providerName
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Import-Package: org.eclipse.eef;version="[1.6.0,2.0.0)",
+ org.eclipse.eef.api;version="[1.6.0,2.0.0)",
+ org.eclipse.eef.core.api;version="[1.6.0,2.0.0)",
+ org.eclipse.eef.core.api.controllers;version="[1.6.0,2.0.0)",
+ org.eclipse.eef.core.api.utils;version="[1.6.0,2.0.0)",
+ org.eclipse.eef.ide.internal;version="[1.6.0,2.0.0)",
+ org.eclipse.sirius.common.interpreter.api;version="1.0.0"
+Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.7.0,4.0.0)",
+ org.eclipse.emf.common;bundle-version="[2.8.0,3.0.0)",
+ org.eclipse.emf.ecore;bundle-version="[2.8.0,3.0.0)",
+ org.eclipse.emf.transaction;bundle-version="[1.4.0,2.0.0)",
+ org.eclipse.eef.properties.ui;bundle-version="[1.6.0,2.0.0)",
+ org.eclipse.swt;bundle-version="[3.0.0,4.0.0)",
+ org.eclipse.ui.forms;bundle-version="[3.5.200,4.0.0)",
+ org.eclipse.jface;bundle-version="[3.1.0,4.0.0)",
+ org.eclipse.ui.workbench;bundle-version="[3.0.0,4.0.0)",
+ org.eclipse.ui;bundle-version="[3.0.0,4.0.0)",
+ org.eclipse.emf.common.ui;bundle-version="[2.7.0,3.0.0)",
+ org.eclipse.eef.core;bundle-version="[1.6.0,2.0.0)",
+ org.eclipse.eef.common;bundle-version="[1.6.0,2.0.0)",
+ org.eclipse.eef.ide.ui,
+ com.google.guava
+Bundle-Localization: plugin
+Bundle-ActivationPolicy: lazy
+Bundle-Activator: org.eclipse.eef.sample.custom.widget.colorpicker.ColorPickerPlugin$Implementation
diff --git a/samples/org.eclipse.eef.sample.custom.widget.colorpicker/about.html b/samples/org.eclipse.eef.sample.custom.widget.colorpicker/about.html
new file mode 100644
index 000000000..f3a55ce5f
--- /dev/null
+++ b/samples/org.eclipse.eef.sample.custom.widget.colorpicker/about.html
@@ -0,0 +1,28 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
+<title>About</title>
+</head>
+<body lang="EN-US">
+<h2>About This Content</h2>
+
+<p>June 15, 2010</p>
+<h3>License</h3>
+
+<p>The Eclipse Foundation makes available all content in this plug-in (&quot;Content&quot;). Unless otherwise
+indicated below, the Content is provided to you under the terms and conditions of the
+Eclipse Public License Version 1.0 (&quot;EPL&quot;). A copy of the EPL is available
+at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
+For purposes of the EPL, &quot;Program&quot; will mean the Content.</p>
+
+<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is
+being redistributed by another party (&quot;Redistributor&quot;) and different terms and conditions may
+apply to your use of any object code in the Content. Check the Redistributor's license that was
+provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
+indicated below, the terms and conditions of the EPL still apply to any source code in the Content
+and such source code may be obtained at <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p>
+
+</body>
+</html> \ No newline at end of file
diff --git a/samples/org.eclipse.eef.sample.custom.widget.colorpicker/build.properties b/samples/org.eclipse.eef.sample.custom.widget.colorpicker/build.properties
new file mode 100644
index 000000000..962cf74fb
--- /dev/null
+++ b/samples/org.eclipse.eef.sample.custom.widget.colorpicker/build.properties
@@ -0,0 +1,16 @@
+# 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.htm
+# Contributors: Obeo - initial API and implementation
+
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ about.html,\
+ plugin.properties,\
+ plugin.xml
+javacProjectSettings = true
+additional.bundles = org.eclipse.emf.transaction
diff --git a/samples/org.eclipse.eef.sample.custom.widget.colorpicker/icons/16x16/Add_16x16.gif b/samples/org.eclipse.eef.sample.custom.widget.colorpicker/icons/16x16/Add_16x16.gif
new file mode 100644
index 000000000..252d7ebcb
--- /dev/null
+++ b/samples/org.eclipse.eef.sample.custom.widget.colorpicker/icons/16x16/Add_16x16.gif
Binary files differ
diff --git a/samples/org.eclipse.eef.sample.custom.widget.colorpicker/icons/16x16/Create_16x16.gif b/samples/org.eclipse.eef.sample.custom.widget.colorpicker/icons/16x16/Create_16x16.gif
new file mode 100644
index 000000000..cb415064e
--- /dev/null
+++ b/samples/org.eclipse.eef.sample.custom.widget.colorpicker/icons/16x16/Create_16x16.gif
Binary files differ
diff --git a/samples/org.eclipse.eef.sample.custom.widget.colorpicker/icons/16x16/Delete_16x16.gif b/samples/org.eclipse.eef.sample.custom.widget.colorpicker/icons/16x16/Delete_16x16.gif
new file mode 100644
index 000000000..b6922ac11
--- /dev/null
+++ b/samples/org.eclipse.eef.sample.custom.widget.colorpicker/icons/16x16/Delete_16x16.gif
Binary files differ
diff --git a/samples/org.eclipse.eef.sample.custom.widget.colorpicker/plugin.properties b/samples/org.eclipse.eef.sample.custom.widget.colorpicker/plugin.properties
new file mode 100644
index 000000000..b112c730f
--- /dev/null
+++ b/samples/org.eclipse.eef.sample.custom.widget.colorpicker/plugin.properties
@@ -0,0 +1,9 @@
+# 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.htm
+# Contributors: Obeo - initial API and implementation
+
+pluginName=EEF Multi/Mono references widgets
+providerName=Eclipse Modeling Project \ No newline at end of file
diff --git a/samples/org.eclipse.eef.sample.custom.widget.colorpicker/plugin.xml b/samples/org.eclipse.eef.sample.custom.widget.colorpicker/plugin.xml
new file mode 100644
index 000000000..d172b2424
--- /dev/null
+++ b/samples/org.eclipse.eef.sample.custom.widget.colorpicker/plugin.xml
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+ <extension
+ point="org.eclipse.eef.ide.ui.eefLifecycleManagerProvider">
+ <descriptor
+ class="org.eclipse.eef.sample.custom.widget.colorpicker.ColorPickerProvider"
+ description="Provides a color picker custom widget"
+ id="org.eclipse.eef.sample.custom.widget.colorpicker"
+ label="Color Picker Widget">
+ </descriptor>
+ </extension>
+
+</plugin>
diff --git a/samples/org.eclipse.eef.sample.custom.widget.colorpicker/src/org/eclipse/eef/sample/custom/widget/colorpicker/ColorHelper.java b/samples/org.eclipse.eef.sample.custom.widget.colorpicker/src/org/eclipse/eef/sample/custom/widget/colorpicker/ColorHelper.java
new file mode 100644
index 000000000..3480a8eed
--- /dev/null
+++ b/samples/org.eclipse.eef.sample.custom.widget.colorpicker/src/org/eclipse/eef/sample/custom/widget/colorpicker/ColorHelper.java
@@ -0,0 +1,95 @@
+/*******************************************************************************
+ * Copyright (c) 2012, 2015 Original authors and others.
+ * 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:
+ * Original authors and others - initial API and implementation
+ * Dirk Fauth <dirk.fauth@googlemail.com> - Added image scaling
+ * Obeo - renamed and keep only color related stuff
+ ******************************************************************************/
+package org.eclipse.eef.sample.custom.widget.colorpicker;
+
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.RGB;
+
+/**
+ * A color helper.
+ *
+ * @author mbats
+ * @see org.eclipse.nebula.widgets.nattable.core#GUIHelper
+ */
+public final class ColorHelper {
+ /**
+ * Key prefix.
+ */
+ private static final String KEY_PREFIX = ColorHelper.class.getCanonicalName() + "."; //$NON-NLS-1$
+
+ /**
+ * Private constructor.
+ */
+ private ColorHelper() {
+ // Nothing
+ }
+
+ /**
+ * Get color.
+ *
+ * @param rgb
+ * RGB
+ * @return The color
+ */
+ public static Color getColor(RGB rgb) {
+ return getColor(rgb.red, rgb.green, rgb.blue);
+ }
+
+ /**
+ * Get color.
+ *
+ * @param red
+ * Red
+ * @param green
+ * Green
+ * @param blue
+ * Blue
+ * @return The color
+ */
+ public static Color getColor(int red, int green, int blue) {
+ String key = getColorKey(red, green, blue);
+ if (JFaceResources.getColorRegistry().hasValueFor(key)) {
+ return JFaceResources.getColorRegistry().get(key);
+ } else {
+ JFaceResources.getColorRegistry().put(key, new RGB(red, green, blue));
+ return getColor(key);
+ }
+ }
+
+ /**
+ * Get color.
+ *
+ * @param key
+ * Key
+ * @return The color.
+ */
+ private static Color getColor(String key) {
+ return JFaceResources.getColorRegistry().get(key);
+ }
+
+ /**
+ * Get the color key.
+ *
+ * @param red
+ * Red
+ * @param green
+ * Green
+ * @param blue
+ * Blue
+ * @return The color key
+ */
+ private static String getColorKey(int red, int green, int blue) {
+ return KEY_PREFIX + "_COLOR_" + red + "_" + green + "_" + blue; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+}
diff --git a/samples/org.eclipse.eef.sample.custom.widget.colorpicker/src/org/eclipse/eef/sample/custom/widget/colorpicker/ColorPicker.java b/samples/org.eclipse.eef.sample.custom.widget.colorpicker/src/org/eclipse/eef/sample/custom/widget/colorpicker/ColorPicker.java
new file mode 100644
index 000000000..ce84e0f32
--- /dev/null
+++ b/samples/org.eclipse.eef.sample.custom.widget.colorpicker/src/org/eclipse/eef/sample/custom/widget/colorpicker/ColorPicker.java
@@ -0,0 +1,121 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Original authors and others.
+ * 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:
+ * Original authors and others - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.eef.sample.custom.widget.colorpicker;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.CLabel;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+
+/**
+ * A button that displays a solid block of color and allows the user to pick a
+ * color. The user can double click on the button in order to change the
+ * selected color which also changes the background color of the button.
+ *
+ */
+public class ColorPicker extends CLabel {
+ /**
+ * The width.
+ */
+ private static final int WIDTH = 70;
+
+ /**
+ * The height.
+ */
+ private static final int HEIGHT = 20;
+
+ /**
+ * The selected color.
+ */
+ private Color selectedColor;
+
+ /**
+ * The image.
+ */
+ private Image image;
+
+ /**
+ * The constructor.
+ *
+ * @param parent
+ * The parent
+ */
+ public ColorPicker(Composite parent) {
+ super(parent, SWT.SHADOW_OUT);
+ }
+
+ /**
+ * Get the color image.
+ *
+ * @param color
+ * The color
+ * @return The color imae
+ */
+ public Image getColorImage(Color color) {
+ Display display = Display.getCurrent();
+
+ image = new Image(display, new Rectangle(10, 10, WIDTH, HEIGHT));
+ GC gc = new GC(image);
+ gc.setBackground(color);
+ gc.fillRectangle(image.getBounds());
+ gc.dispose();
+ return image;
+ }
+
+ /**
+ * The RGB color.
+ *
+ * @param selected
+ * The selection.
+ */
+ private void update(RGB selected) {
+ this.selectedColor = ColorHelper.getColor(selected);
+ setImage(getColorImage(selectedColor));
+ }
+
+ /**
+ * The selected color.
+ *
+ * @return the Color most recently selected by the user.
+ * <em>Note that it is the responsibility of the client to
+ * dispose this resource</em>
+ */
+ public Color getSelectedColor() {
+ return selectedColor;
+ }
+
+ /**
+ * Set the current selected color that will be displayed by the picker.
+ * <em>Note that this class is not responsible
+ * for destroying the given Color object. It does not take ownership. Instead it will create its own internal
+ * copy of the given Color resource.</em>
+ *
+ * @param backgroundColor
+ * the background color
+ */
+ public void setSelectedColor(Color backgroundColor) {
+ if (backgroundColor == null) {
+ throw new IllegalArgumentException("null"); //$NON-NLS-1$
+ }
+ update(backgroundColor.getRGB());
+ }
+
+ @Override
+ public void dispose() {
+ super.dispose();
+ image.dispose();
+ }
+}
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
new file mode 100644
index 000000000..19c5aa7b3
--- /dev/null
+++ b/samples/org.eclipse.eef.sample.custom.widget.colorpicker/src/org/eclipse/eef/sample/custom/widget/colorpicker/ColorPickerController.java
@@ -0,0 +1,149 @@
+package org.eclipse.eef.sample.custom.widget.colorpicker;
+
+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.controllers.AbstractEEFCustomWidgetController;
+import org.eclipse.eef.core.api.controllers.IConsumer;
+import org.eclipse.eef.core.api.utils.Eval;
+import org.eclipse.eef.core.api.utils.ISuccessfulResultConsumer;
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.common.command.CommandStack;
+import org.eclipse.emf.ecore.EAttribute;
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.sirius.common.interpreter.api.IInterpreter;
+import org.eclipse.sirius.common.interpreter.api.IVariableManager;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.RGB;
+
+/**
+ * This class is used to provide utilities to single reference viewer
+ * controller.
+ *
+ * @author mbats
+ */
+public class ColorPickerController extends AbstractEEFCustomWidgetController implements IColorPickerController {
+
+ /**
+ * Default color code.
+ */
+ private static final int DEFAULT_COLOR_CODE = 255;
+
+ /**
+ * Value expression id.
+ */
+ private static final String VALUE_EXPRESSION_ID = "valueExpression";
+
+ /**
+ * Add expression id.
+ */
+ private static final String EDIT_EXPRESSION_ID = "editExpression";
+
+ /**
+ * Separator.
+ */
+ private static final String SEPARATOR = ",";
+
+ /**
+ * The consumer of a new value of the color.
+ */
+ private IConsumer<Color> newValueConsumer;
+
+ /**
+ * The constructor.
+ *
+ * @param description
+ * The description
+ * @param variableManager
+ * The variable manager
+ * @param interpreter
+ * The interpreter
+ * @param editingDomain
+ * The editing domain
+ */
+ public ColorPickerController(EEFCustomWidgetDescription description, IVariableManager variableManager, IInterpreter interpreter, TransactionalEditingDomain editingDomain) {
+ super(description, variableManager, interpreter, editingDomain);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.eef.core.internal.controllers.AbstractEEFCustomWidgetController#refresh()
+ */
+ @Override
+ public void refresh() {
+ 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 ISuccessfulResultConsumer<String>() {
+ @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);
+ 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);
+ }
+ }
+ });
+ }
+
+ @Override
+ public void onNewValue(IConsumer<Color> consumer) {
+ this.newValueConsumer = consumer;
+ }
+
+ @Override
+ public void removeNewValueConsumer() {
+ this.newValueConsumer = null;
+ }
+
+ @Override
+ protected EEFCustomWidgetDescription getDescription() {
+ return this.description;
+ }
+
+ @Override
+ public void updateValue(final RGB color) {
+
+ final Command command = new RecordingCommand(this.editingDomain) {
+ @Override
+ protected void doExecute() {
+ 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);
+ }
+
+ @Override
+ public boolean canExecute() {
+ return true;
+ }
+ };
+
+ Runnable runnable = new Runnable() {
+ @Override
+ public void run() {
+ CommandStack commandStack = ColorPickerController.this.editingDomain.getCommandStack();
+ commandStack.execute(command);
+ }
+ };
+ runnable.run();
+ }
+
+}
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
new file mode 100644
index 000000000..1437d4892
--- /dev/null
+++ b/samples/org.eclipse.eef.sample.custom.widget.colorpicker/src/org/eclipse/eef/sample/custom/widget/colorpicker/ColorPickerLifecycleManager.java
@@ -0,0 +1,169 @@
+package org.eclipse.eef.sample.custom.widget.colorpicker;
+
+import org.eclipse.eef.EEFCustomWidgetDescription;
+import org.eclipse.eef.EEFWidgetDescription;
+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.eef.properties.ui.api.EEFTabbedPropertySheetPage;
+import org.eclipse.eef.properties.ui.api.EEFTabbedPropertySheetWidgetFactory;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.sirius.common.interpreter.api.IInterpreter;
+import org.eclipse.sirius.common.interpreter.api.IVariableManager;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.MouseAdapter;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.layout.FormAttachment;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.widgets.ColorDialog;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * This class will be used in order to manager the lifecycle of a color picker.
+ *
+ * @author mbats
+ */
+public class ColorPickerLifecycleManager extends AbstractEEFWidgetLifecycleManager {
+ /**
+ * The description.
+ */
+ private EEFCustomWidgetDescription description;
+
+ /**
+ * The color picker.
+ */
+ private ColorPicker colorPicker;
+
+ /**
+ * The controller.
+ */
+ private IColorPickerController controller;
+
+ /**
+ * The mouse listener.
+ */
+ private MouseAdapter mouseListener;
+
+ /**
+ * The constructor.
+ *
+ * @param description
+ * The description
+ * @param variableManager
+ * The variable manager
+ * @param interpreter
+ * The interpreter
+ * @param editingDomain
+ * The editing domain
+ * @param singleReferenceViewerProvider
+ */
+ public ColorPickerLifecycleManager(EEFCustomWidgetDescription description, IVariableManager variableManager, IInterpreter interpreter, TransactionalEditingDomain editingDomain) {
+ super(variableManager, interpreter, editingDomain);
+ this.description = description;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.eef.ide.ui.api.AbstractEEFCustomWidgetLifecycleManager#createControl(org.eclipse.swt.widgets.Composite,
+ * org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage)
+ */
+ @Override
+ protected void createMainControl(Composite parent, EEFTabbedPropertySheetPage tabbedPropertySheetPage) {
+ EEFTabbedPropertySheetWidgetFactory widgetFactory = tabbedPropertySheetPage.getWidgetFactory();
+
+ FormData formData = new FormData();
+ formData.left = new FormAttachment(0, LABEL_WIDTH);
+ formData.right = new FormAttachment(100, 0);
+
+ // Create the color picker
+ this.colorPicker = new ColorPicker(parent);
+ widgetFactory.paintBordersFor(parent);
+
+ this.colorPicker.setLayoutData(formData);
+
+ this.controller = new ColorPickerController(this.description, this.variableManager, this.interpreter, this.editingDomain);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.eef.ide.ui.api.widgets.AbstractEEFWidgetLifecycleManager#getController()
+ */
+ @Override
+ protected IEEFWidgetController getController() {
+ return this.controller;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.eef.ide.ui.internal.widgets.AbstractEEFWidgetLifecycleManager#getWidgetDescription()
+ */
+ @Override
+ protected EEFWidgetDescription getWidgetDescription() {
+ return this.description;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.eef.ide.ui.internal.widgets.ILifecycleManager#aboutToBeShown()
+ */
+ @Override
+ public void aboutToBeShown() {
+ super.aboutToBeShown();
+
+ this.mouseListener = new MouseAdapter() {
+ @Override
+ public void mouseDown(MouseEvent e) {
+ ColorDialog dialog = new ColorDialog(new Shell(Display.getDefault(), SWT.SHELL_TRIM));
+ if (colorPicker.getSelectedColor() != null && colorPicker.getSelectedColor().getRGB() != null) {
+ dialog.setRGB(colorPicker.getSelectedColor().getRGB());
+ }
+ RGB selected = dialog.open();
+ if (selected != null) {
+ controller.updateValue(selected);
+ }
+ }
+ };
+ this.colorPicker.addMouseListener(mouseListener);
+
+ this.controller.onNewValue(new IConsumer<Color>() {
+ @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);
+ }
+ }
+ }
+ });
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.eef.ide.ui.api.widgets.AbstractEEFWidgetLifecycleManager#getValidationControl()
+ */
+ @Override
+ protected Control getValidationControl() {
+ return this.colorPicker;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.eef.ide.ui.api.ILifecycleManager#aboutToBeHidden()
+ */
+ @Override
+ public void aboutToBeHidden() {
+ super.aboutToBeHidden();
+ }
+}
diff --git a/samples/org.eclipse.eef.sample.custom.widget.colorpicker/src/org/eclipse/eef/sample/custom/widget/colorpicker/ColorPickerPlugin.java b/samples/org.eclipse.eef.sample.custom.widget.colorpicker/src/org/eclipse/eef/sample/custom/widget/colorpicker/ColorPickerPlugin.java
new file mode 100644
index 000000000..ba6ac2625
--- /dev/null
+++ b/samples/org.eclipse.eef.sample.custom.widget.colorpicker/src/org/eclipse/eef/sample/custom/widget/colorpicker/ColorPickerPlugin.java
@@ -0,0 +1,75 @@
+/*******************************************************************************
+ * 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.sample.custom.widget.colorpicker;
+
+import org.eclipse.eef.common.api.AbstractEEFEclipsePlugin;
+import org.eclipse.emf.common.EMFPlugin;
+import org.eclipse.emf.common.util.ResourceLocator;
+
+/**
+ * The plugin class of the bundle.
+ *
+ * @author mbats
+ */
+public class ColorPickerPlugin extends EMFPlugin {
+
+ /**
+ * The identifier of the plugin.
+ */
+ public static final String PLUGIN_ID = "org.eclipse.eef.properties.ui.widgets.colorpicker"; //$NON-NLS-1$
+
+ /**
+ * The sole instance of the plugin.
+ */
+ public static final ColorPickerPlugin INSTANCE = new ColorPickerPlugin();
+
+ /**
+ * The OSGi related implementation of the plugin.
+ */
+ private static Implementation plugin;
+
+ /**
+ * The constructor.
+ */
+ public ColorPickerPlugin() {
+ super(new ResourceLocator[0]);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.common.EMFPlugin#getPluginResourceLocator()
+ */
+ @Override
+ public ResourceLocator getPluginResourceLocator() {
+ return plugin;
+ }
+
+ public static Implementation getPlugin() {
+ return plugin;
+ }
+
+ /**
+ * This class is used as the bundle activator of the plugin.
+ *
+ * @author mbats
+ */
+ public static class Implementation extends AbstractEEFEclipsePlugin {
+ /**
+ * The constructor.
+ */
+ public Implementation() {
+ super(PLUGIN_ID);
+
+ ColorPickerPlugin.plugin = this;
+ }
+ }
+}
diff --git a/samples/org.eclipse.eef.sample.custom.widget.colorpicker/src/org/eclipse/eef/sample/custom/widget/colorpicker/ColorPickerProvider.java b/samples/org.eclipse.eef.sample.custom.widget.colorpicker/src/org/eclipse/eef/sample/custom/widget/colorpicker/ColorPickerProvider.java
new file mode 100644
index 000000000..53ff07071
--- /dev/null
+++ b/samples/org.eclipse.eef.sample.custom.widget.colorpicker/src/org/eclipse/eef/sample/custom/widget/colorpicker/ColorPickerProvider.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * 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.sample.custom.widget.colorpicker;
+
+import org.eclipse.eef.EEFCustomWidgetDescription;
+import org.eclipse.eef.ide.ui.api.IEEFLifecycleManagerProvider;
+import org.eclipse.eef.ide.ui.api.ILifecycleManager;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.sirius.common.interpreter.api.IInterpreter;
+import org.eclipse.sirius.common.interpreter.api.IVariableManager;
+
+/**
+ * The color picker provider.
+ *
+ * @author mbats
+ */
+public class ColorPickerProvider implements IEEFLifecycleManagerProvider {
+
+ @Override
+ public ILifecycleManager getLifecycleManager(EEFCustomWidgetDescription customWidgetDescription, IVariableManager variableManager, IInterpreter interpreter,
+ TransactionalEditingDomain editingDomain) {
+ return new ColorPickerLifecycleManager(customWidgetDescription, variableManager, interpreter, editingDomain);
+ }
+}
diff --git a/samples/org.eclipse.eef.sample.custom.widget.colorpicker/src/org/eclipse/eef/sample/custom/widget/colorpicker/IColorPickerController.java b/samples/org.eclipse.eef.sample.custom.widget.colorpicker/src/org/eclipse/eef/sample/custom/widget/colorpicker/IColorPickerController.java
new file mode 100644
index 000000000..e21c49a30
--- /dev/null
+++ b/samples/org.eclipse.eef.sample.custom.widget.colorpicker/src/org/eclipse/eef/sample/custom/widget/colorpicker/IColorPickerController.java
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * 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.sample.custom.widget.colorpicker;
+
+import org.eclipse.eef.core.api.controllers.IConsumer;
+import org.eclipse.eef.core.api.controllers.IEEFWidgetController;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.RGB;
+
+/**
+ * The IColorPickerController is responsible of supporting all the interactions
+ * with the widgets created for a color picker.
+ *
+ * @author mbats
+ */
+public interface IColorPickerController extends IEEFWidgetController {
+ /**
+ * Register a consumer which will be called with the new value of the text
+ * when it will change.
+ *
+ * @param consumer
+ * The consumer of the new value of the text
+ */
+ void onNewValue(IConsumer<Color> consumer);
+
+ /**
+ * Remove the consumer of the new value of the text.
+ */
+ void removeNewValueConsumer();
+
+ /**
+ * Update the value of the text.
+ *
+ * @param selected
+ * The new value of the color
+ */
+ void updateValue(RGB selected);
+
+}

Back to the top