1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
14 * @author Toni Kalajainen
16 package org.simantics.utils.ui.color;
18 import org.eclipse.jface.viewers.DialogCellEditor;
19 import org.eclipse.jface.window.Window;
20 import org.eclipse.swt.graphics.Color;
21 import org.eclipse.swt.widgets.Composite;
22 import org.eclipse.swt.widgets.Control;
24 public class ColorGradientCellEditor extends DialogCellEditor {
26 public ColorGradientCellEditor(Composite parent) {
31 * The composite showing the gradient
33 private ColorGradientCanvas canvas;
36 * Method declared on DialogCellEditor.
38 protected Control createContents(Composite cell) {
39 Color bg = cell.getBackground();
40 canvas = new ColorGradientCanvas(cell, getStyle());
41 canvas.setBackground(bg);
46 * Method declared on DialogCellEditor.
48 protected Object openDialogBox(Control cellEditorWindow) {
49 ColorGradient value = (ColorGradient)getValue();
50 ColorGradientDialog dialog = new ColorGradientDialog(cellEditorWindow.getShell(), value);
51 if (dialog.open() == Window.OK)
52 return dialog.getGradient();
57 * Method declared on DialogCellEditor.
59 protected void updateContents(Object value) {
60 ColorGradient cg = (ColorGradient) value;
61 canvas.setGradient(cg);