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
.apache
.log4j
.Logger
;
14 import org
.eclipse
.core
.runtime
.Assert
;
15 import org
.eclipse
.jface
.viewers
.CellEditor
;
16 import org
.eclipse
.jface
.viewers
.ColumnViewerEditorActivationEvent
;
17 import org
.eclipse
.swt
.SWT
;
18 import org
.eclipse
.swt
.events
.SelectionAdapter
;
19 import org
.eclipse
.swt
.events
.SelectionEvent
;
20 import org
.eclipse
.swt
.widgets
.Button
;
21 import org
.eclipse
.swt
.widgets
.Composite
;
22 import org
.eclipse
.swt
.widgets
.Control
;
29 public class CheckboxCellEditor
extends CellEditor
{
30 private static final Logger logger
= Logger
31 .getLogger(CheckboxCellEditor
.class);
37 boolean value
= false;
39 private Button button
;
42 * Default CheckboxCellEditor style
44 private static final int defaultStyle
= SWT
.NONE
;
47 * Creates a new checkbox cell editor with no control
50 public CheckboxCellEditor() {
51 setStyle(defaultStyle
);
55 * Creates a new checkbox cell editor parented under the given control.
56 * The cell editor value is a boolean value, which is initially <code>false</code>.
57 * Initially, the cell editor has no cell validator.
59 * @param parent the parent control
61 public CheckboxCellEditor(Composite parent
) {
62 this(parent
, defaultStyle
);
66 * Creates a new checkbox cell editor parented under the given control.
67 * The cell editor value is a boolean value, which is initially <code>false</code>.
68 * Initially, the cell editor has no cell validator.
70 * @param parent the parent control
71 * @param style the style bits
74 public CheckboxCellEditor(Composite parent
, int style
) {
79 * The <code>CheckboxCellEditor</code> implementation of
80 * this <code>CellEditor</code> framework method does
81 * nothing and returns <code>null</code>.
83 protected Control
createControl(Composite parent
) {
84 button
= new Button(parent
, SWT
.CHECK
);
86 button
.addSelectionListener(new SelectionAdapter() {
87 public void widgetSelected(SelectionEvent e
) {
88 value
= button
.getSelection();
95 * The <code>CheckboxCellEditor</code> implementation of
96 * this <code>CellEditor</code> framework method returns
97 * the checkbox setting wrapped as a <code>Boolean</code>.
99 * @return the Boolean checkbox value
101 protected Object
doGetValue() {
102 return value ? Boolean
.TRUE
: Boolean
.FALSE
;
106 * Method declared on CellEditor.
108 protected void doSetFocus() {
113 * The <code>CheckboxCellEditor</code> implementation of
114 * this <code>CellEditor</code> framework method accepts
115 * a value wrapped as a <code>Boolean</code>.
117 * @param value a Boolean value
119 protected void doSetValue(Object value
) {
120 Assert
.isTrue(value
instanceof Boolean
);
121 this.value
= ((Boolean
) value
).booleanValue();
124 public void activate(ColumnViewerEditorActivationEvent activationEvent
) {
125 if (activationEvent
.eventType
!= ColumnViewerEditorActivationEvent
.TRAVERSAL
) {
126 super.activate(activationEvent
);
130 public Control
getControl() {