~ubuntu-branches/ubuntu/utopic/eclipse-eclox/utopic

« back to all changes in this revision

Viewing changes to eclox.ui/src/eclox/ui/editor/basic/CheckMultiEditor.java

  • Committer: Package Import Robot
  • Author(s): Graham Inggs
  • Date: 2013-07-07 20:33:10 UTC
  • Revision ID: package-import@ubuntu.com-20130707203310-a44yw80gqtc2s9ob
Tags: upstream-0.10.0
ImportĀ upstreamĀ versionĀ 0.10.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*******************************************************************************
 
2
 * Copyright (C) 2003-2007, 2013, Guillaume Brocker
 
3
 * 
 
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
 *     Guillaume Brocker - Initial API and implementation
 
11
 *
 
12
 ******************************************************************************/ 
 
13
 
 
14
package eclox.ui.editor.basic;
 
15
 
 
16
import org.eclipse.swt.SWT;
 
17
import org.eclipse.swt.events.SelectionEvent;
 
18
import org.eclipse.swt.events.SelectionListener;
 
19
import org.eclipse.swt.layout.FillLayout;
 
20
import org.eclipse.swt.widgets.Button;
 
21
import org.eclipse.swt.widgets.Composite;
 
22
import org.eclipse.ui.forms.widgets.FormToolkit;
 
23
 
 
24
/**
 
25
 * Implements a specialized multi editor that is represented by a check box and
 
26
 * provides only two states: SELECTED and DESELECTED. 
 
27
 *  
 
28
 * @author Guillaume Brocker
 
29
 */
 
30
public class CheckMultiEditor extends MultiEditor {
 
31
        
 
32
        /**
 
33
         * the selected state name constant
 
34
         */
 
35
        public static final String SELECTED = "Selected";
 
36
        
 
37
        /**
 
38
         * the deselected state name constant
 
39
         */
 
40
        public static final String DESELECTED = "Deselected";
 
41
        
 
42
        /**
 
43
         * Defines the selection listener for the check box button
 
44
         */
 
45
        private class MySelectionListener implements SelectionListener {
 
46
 
 
47
                public void widgetDefaultSelected(SelectionEvent e) {
 
48
                        widgetSelected(e);                      
 
49
                }
 
50
 
 
51
                public void widgetSelected(SelectionEvent e) {
 
52
                        Button  button = (Button) e.widget;
 
53
                        selectState( button.getSelection() ? SELECTED : DESELECTED );
 
54
                        commit();
 
55
                }
 
56
                
 
57
        }
 
58
        
 
59
        /**
 
60
         * a string containing the text to use for the check box button
 
61
         */
 
62
        private String  text;
 
63
        
 
64
        /**
 
65
         * the check box button that represents the editor
 
66
         */
 
67
        private Button  button;
 
68
        
 
69
        /**
 
70
         * Constructor
 
71
         * 
 
72
         * @param text  a string containing the text that will be used for the check box control
 
73
         */
 
74
        public CheckMultiEditor( String text ) {
 
75
                super( new String[] {SELECTED, DESELECTED} );
 
76
                this.text = text;
 
77
                
 
78
        }
 
79
        
 
80
        /**
 
81
         * @see eclox.ui.editor.editors.IEditor#createContent(org.eclipse.swt.widgets.Composite, org.eclipse.ui.forms.widgets.FormToolkit)
 
82
         */
 
83
        public void createContent(Composite parent, FormToolkit formToolkit) {
 
84
                button = formToolkit.createButton(parent, text, SWT.CHECK);
 
85
                button.addSelectionListener( new MySelectionListener() );
 
86
                parent.setLayout(new FillLayout(SWT.VERTICAL));
 
87
        }
 
88
 
 
89
        /**
 
90
         * @see eclox.ui.editor.editors.IEditor#dispose()
 
91
         */
 
92
        public void dispose() {
 
93
                button = null;
 
94
        }
 
95
 
 
96
        /**
 
97
         * @see eclox.ui.editor.editors.IEditor#grabVerticalSpace()
 
98
         */
 
99
        public boolean grabVerticalSpace() {
 
100
                return false;
 
101
        }
 
102
 
 
103
        /**
 
104
         * @see eclox.ui.editor.basic.MultiEditor#refresh()
 
105
         */
 
106
        public void refresh() {
 
107
                // Pre-condition
 
108
                assert button != null;
 
109
                
 
110
                // Refreshes the states.
 
111
                super.refresh();
 
112
                
 
113
                // Refreshes the check box
 
114
                State   selection = getSelectionAsState();
 
115
                button.setSelection( selection != null && selection.getName().equals(SELECTED) );
 
116
        }
 
117
 
 
118
        /**
 
119
         * @see eclox.ui.editor.editors.IEditor#setEnabled(boolean)
 
120
         */
 
121
        public void setEnabled(boolean enabled) {
 
122
                // Pre-condition
 
123
                assert button != null;
 
124
                
 
125
                button.setEnabled(enabled);
 
126
        }
 
127
 
 
128
        /**
 
129
         * @see eclox.ui.editor.editors.IEditor#setFocus()
 
130
         */
 
131
        public void setFocus() {
 
132
                // Pre-condition
 
133
                assert button != null;
 
134
                
 
135
                button.setFocus();
 
136
        }
 
137
 
 
138
}