1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2007 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
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.
|
9
|
*/
|
10
|
|
11
|
package eu.etaxonomy.taxeditor.propertysheet;
|
12
|
|
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;
|
23
|
|
24
|
/**
|
25
|
* @author p.ciardelli
|
26
|
* @created 15.05.2009
|
27
|
* @version 1.0
|
28
|
*/
|
29
|
public class CheckboxCellEditor extends CellEditor {
|
30
|
private static final Logger logger = Logger
|
31
|
.getLogger(CheckboxCellEditor.class);
|
32
|
|
33
|
/**
|
34
|
* The checkbox value.
|
35
|
*/
|
36
|
/* package */
|
37
|
boolean value = false;
|
38
|
|
39
|
private Button button;
|
40
|
|
41
|
/**
|
42
|
* Default CheckboxCellEditor style
|
43
|
*/
|
44
|
private static final int defaultStyle = SWT.NONE;
|
45
|
|
46
|
/**
|
47
|
* Creates a new checkbox cell editor with no control
|
48
|
* @since 2.1
|
49
|
*/
|
50
|
public CheckboxCellEditor() {
|
51
|
setStyle(defaultStyle);
|
52
|
}
|
53
|
|
54
|
/**
|
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.
|
58
|
*
|
59
|
* @param parent the parent control
|
60
|
*/
|
61
|
public CheckboxCellEditor(Composite parent) {
|
62
|
this(parent, defaultStyle);
|
63
|
}
|
64
|
|
65
|
/**
|
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.
|
69
|
*
|
70
|
* @param parent the parent control
|
71
|
* @param style the style bits
|
72
|
* @since 2.1
|
73
|
*/
|
74
|
public CheckboxCellEditor(Composite parent, int style) {
|
75
|
super(parent, style);
|
76
|
}
|
77
|
|
78
|
/**
|
79
|
* The <code>CheckboxCellEditor</code> implementation of
|
80
|
* this <code>CellEditor</code> framework method does
|
81
|
* nothing and returns <code>null</code>.
|
82
|
*/
|
83
|
protected Control createControl(Composite parent) {
|
84
|
button = new Button(parent, SWT.CHECK);
|
85
|
|
86
|
button.addSelectionListener(new SelectionAdapter() {
|
87
|
public void widgetSelected(SelectionEvent e) {
|
88
|
value = button.getSelection();
|
89
|
}
|
90
|
});
|
91
|
return button;
|
92
|
}
|
93
|
|
94
|
/**
|
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>.
|
98
|
*
|
99
|
* @return the Boolean checkbox value
|
100
|
*/
|
101
|
protected Object doGetValue() {
|
102
|
return value ? Boolean.TRUE : Boolean.FALSE;
|
103
|
}
|
104
|
|
105
|
/* (non-Javadoc)
|
106
|
* Method declared on CellEditor.
|
107
|
*/
|
108
|
protected void doSetFocus() {
|
109
|
// Ignore
|
110
|
}
|
111
|
|
112
|
/**
|
113
|
* The <code>CheckboxCellEditor</code> implementation of
|
114
|
* this <code>CellEditor</code> framework method accepts
|
115
|
* a value wrapped as a <code>Boolean</code>.
|
116
|
*
|
117
|
* @param value a Boolean value
|
118
|
*/
|
119
|
protected void doSetValue(Object value) {
|
120
|
Assert.isTrue(value instanceof Boolean);
|
121
|
this.value = ((Boolean) value).booleanValue();
|
122
|
}
|
123
|
|
124
|
public void activate(ColumnViewerEditorActivationEvent activationEvent) {
|
125
|
if (activationEvent.eventType != ColumnViewerEditorActivationEvent.TRAVERSAL) {
|
126
|
super.activate(activationEvent);
|
127
|
}
|
128
|
}
|
129
|
|
130
|
public Control getControl() {
|
131
|
return button;
|
132
|
}
|
133
|
}
|