]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/color/ColorGradientCellEditor.java
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / bundles / org.simantics.utils.ui / src / org / simantics / utils / ui / color / ColorGradientCellEditor.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 /*
13  *
14  * @author Toni Kalajainen
15  */
16 package org.simantics.utils.ui.color;
17
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;
23
24 public class ColorGradientCellEditor extends DialogCellEditor {
25
26     public ColorGradientCellEditor(Composite parent) {
27         super(parent);
28     }
29
30     /**
31      * The composite showing the gradient
32      */
33     private ColorGradientCanvas canvas;
34
35     /* (non-Javadoc)
36      * Method declared on DialogCellEditor.
37      */
38     protected Control createContents(Composite cell) {
39         Color bg = cell.getBackground();
40         canvas = new ColorGradientCanvas(cell, getStyle());
41         canvas.setBackground(bg);
42         return canvas;
43     }
44
45     /* (non-Javadoc)
46      * Method declared on DialogCellEditor.
47      */
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();
53         return value;
54     }
55
56     /* (non-Javadoc)
57      * Method declared on DialogCellEditor.
58      */
59     protected void updateContents(Object value) {
60         ColorGradient cg = (ColorGradient) value;
61         canvas.setGradient(cg);
62     }    
63     
64
65 }