3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
11 package eu
.etaxonomy
.taxeditor
.propertysheet
;
13 import org
.eclipse
.core
.runtime
.Assert
;
14 import org
.eclipse
.jface
.viewers
.CellEditor
;
15 import org
.eclipse
.jface
.viewers
.ColumnViewerEditorActivationEvent
;
16 import org
.eclipse
.swt
.SWT
;
17 import org
.eclipse
.swt
.events
.SelectionAdapter
;
18 import org
.eclipse
.swt
.events
.SelectionEvent
;
19 import org
.eclipse
.swt
.widgets
.Button
;
20 import org
.eclipse
.swt
.widgets
.Composite
;
21 import org
.eclipse
.swt
.widgets
.Control
;
28 public class CheckboxCellEditor
extends CellEditor
{
34 boolean value
= false;
36 private Button button
;
39 * Default CheckboxCellEditor style
41 private static final int defaultStyle
= SWT
.NONE
;
44 * Creates a new checkbox cell editor with no control
47 public CheckboxCellEditor() {
48 setStyle(defaultStyle
);
52 * Creates a new checkbox cell editor parented under the given control.
53 * The cell editor value is a boolean value, which is initially <code>false</code>.
54 * Initially, the cell editor has no cell validator.
56 * @param parent the parent control
58 public CheckboxCellEditor(Composite parent
) {
59 this(parent
, defaultStyle
);
63 * Creates a new checkbox cell editor parented under the given control.
64 * The cell editor value is a boolean value, which is initially <code>false</code>.
65 * Initially, the cell editor has no cell validator.
67 * @param parent the parent control
68 * @param style the style bits
71 public CheckboxCellEditor(Composite parent
, int style
) {
76 * The <code>CheckboxCellEditor</code> implementation of
77 * this <code>CellEditor</code> framework method does
78 * nothing and returns <code>null</code>.
80 protected Control
createControl(Composite parent
) {
81 button
= new Button(parent
, SWT
.CHECK
);
83 button
.addSelectionListener(new SelectionAdapter() {
84 public void widgetSelected(SelectionEvent e
) {
85 value
= button
.getSelection();
92 * The <code>CheckboxCellEditor</code> implementation of
93 * this <code>CellEditor</code> framework method returns
94 * the checkbox setting wrapped as a <code>Boolean</code>.
96 * @return the Boolean checkbox value
98 protected Object
doGetValue() {
99 return value ? Boolean
.TRUE
: Boolean
.FALSE
;
103 * Method declared on CellEditor.
105 protected void doSetFocus() {
110 * The <code>CheckboxCellEditor</code> implementation of
111 * this <code>CellEditor</code> framework method accepts
112 * a value wrapped as a <code>Boolean</code>.
114 * @param value a Boolean value
116 protected void doSetValue(Object value
) {
117 Assert
.isTrue(value
instanceof Boolean
);
118 this.value
= ((Boolean
) value
).booleanValue();
121 public void activate(ColumnViewerEditorActivationEvent activationEvent
) {
122 if (activationEvent
.eventType
!= ColumnViewerEditorActivationEvent
.TRAVERSAL
) {
123 super.activate(activationEvent
);
127 public Control
getControl() {