--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+/*\r
+ *\r
+ * @author Toni Kalajainen\r
+ */\r
+package org.simantics.utils.ui.color;\r
+\r
+import org.eclipse.jface.viewers.DialogCellEditor;\r
+import org.eclipse.jface.window.Window;\r
+import org.eclipse.swt.graphics.Color;\r
+import org.eclipse.swt.widgets.Composite;\r
+import org.eclipse.swt.widgets.Control;\r
+\r
+public class ColorGradientCellEditor extends DialogCellEditor {\r
+\r
+ public ColorGradientCellEditor(Composite parent) {\r
+ super(parent);\r
+ }\r
+\r
+ /**\r
+ * The composite showing the gradient\r
+ */\r
+ private ColorGradientCanvas canvas;\r
+\r
+ /* (non-Javadoc)\r
+ * Method declared on DialogCellEditor.\r
+ */\r
+ protected Control createContents(Composite cell) {\r
+ Color bg = cell.getBackground();\r
+ canvas = new ColorGradientCanvas(cell, getStyle());\r
+ canvas.setBackground(bg);\r
+ return canvas;\r
+ }\r
+\r
+ /* (non-Javadoc)\r
+ * Method declared on DialogCellEditor.\r
+ */\r
+ protected Object openDialogBox(Control cellEditorWindow) {\r
+ ColorGradient value = (ColorGradient)getValue();\r
+ ColorGradientDialog dialog = new ColorGradientDialog(cellEditorWindow.getShell(), value);\r
+ if (dialog.open() == Window.OK)\r
+ return dialog.getGradient();\r
+ return value;\r
+ }\r
+\r
+ /* (non-Javadoc)\r
+ * Method declared on DialogCellEditor.\r
+ */\r
+ protected void updateContents(Object value) {\r
+ ColorGradient cg = (ColorGradient) value;\r
+ canvas.setGradient(cg);\r
+ } \r
+ \r
+\r
+}\r