Project

General

Profile

Download (3.73 KB) Statistics
| Branch: | Tag: | Revision:
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.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;
22

    
23
/**
24
 * @author p.ciardelli
25
 * @created 15.05.2009
26
 * @version 1.0
27
 */
28
public class CheckboxCellEditor extends CellEditor {
29

    
30
    /**
31
     * The checkbox value.
32
     */
33
    /* package */
34
    boolean value = false;
35

    
36
	private Button button;
37

    
38
    /**
39
     * Default CheckboxCellEditor style
40
     */
41
    private static final int defaultStyle = SWT.NONE;
42

    
43
    /**
44
     * Creates a new checkbox cell editor with no control
45
     * @since 2.1
46
     */
47
    public CheckboxCellEditor() {
48
        setStyle(defaultStyle);
49
    }
50

    
51
    /**
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.
55
     *
56
     * @param parent the parent control
57
     */
58
    public CheckboxCellEditor(Composite parent) {
59
        this(parent, defaultStyle);
60
    }
61

    
62
    /**
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.
66
     *
67
     * @param parent the parent control
68
     * @param style the style bits
69
     * @since 2.1
70
     */
71
    public CheckboxCellEditor(Composite parent, int style) {
72
        super(parent, style);
73
    }
74

    
75
    /**
76
     * The <code>CheckboxCellEditor</code> implementation of
77
     * this <code>CellEditor</code> framework method does
78
     * nothing and returns <code>null</code>.
79
     */
80
    protected Control createControl(Composite parent) {
81
        button = new Button(parent, SWT.CHECK);
82
        
83
        button.addSelectionListener(new SelectionAdapter() {
84
        	public void widgetSelected(SelectionEvent e) {
85
        		value = button.getSelection();
86
        	}
87
        });       
88
        return button;
89
    }
90

    
91
    /**
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>.
95
     *
96
     * @return the Boolean checkbox value
97
     */
98
    protected Object doGetValue() {
99
        return value ? Boolean.TRUE : Boolean.FALSE;
100
    }
101

    
102
    /* (non-Javadoc)
103
     * Method declared on CellEditor.
104
     */
105
    protected void doSetFocus() {
106
        // Ignore
107
    }
108

    
109
    /**
110
     * The <code>CheckboxCellEditor</code> implementation of
111
     * this <code>CellEditor</code> framework method accepts
112
     * a value wrapped as a <code>Boolean</code>.
113
     *
114
     * @param value a Boolean value
115
     */
116
    protected void doSetValue(Object value) {
117
        Assert.isTrue(value instanceof Boolean);
118
        this.value = ((Boolean) value).booleanValue();
119
    }
120

    
121
    public void activate(ColumnViewerEditorActivationEvent activationEvent) {
122
    	if (activationEvent.eventType != ColumnViewerEditorActivationEvent.TRAVERSAL) {
123
    		super.activate(activationEvent);
124
    	}
125
    }
126
    
127
	public Control getControl() {
128
		return button;
129
	}
130
}
(5-5/24)