1
/*******************************************************************************
2
* Copyright (C) 2003-2007, 2013, Guillaume Brocker
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
10
* Guillaume Brocker - Initial API and implementation
12
******************************************************************************/
14
package eclox.ui.editor.basic;
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;
25
* Implements a specialized multi editor that is represented by a check box and
26
* provides only two states: SELECTED and DESELECTED.
28
* @author Guillaume Brocker
30
public class CheckMultiEditor extends MultiEditor {
33
* the selected state name constant
35
public static final String SELECTED = "Selected";
38
* the deselected state name constant
40
public static final String DESELECTED = "Deselected";
43
* Defines the selection listener for the check box button
45
private class MySelectionListener implements SelectionListener {
47
public void widgetDefaultSelected(SelectionEvent e) {
51
public void widgetSelected(SelectionEvent e) {
52
Button button = (Button) e.widget;
53
selectState( button.getSelection() ? SELECTED : DESELECTED );
60
* a string containing the text to use for the check box button
65
* the check box button that represents the editor
67
private Button button;
72
* @param text a string containing the text that will be used for the check box control
74
public CheckMultiEditor( String text ) {
75
super( new String[] {SELECTED, DESELECTED} );
81
* @see eclox.ui.editor.editors.IEditor#createContent(org.eclipse.swt.widgets.Composite, org.eclipse.ui.forms.widgets.FormToolkit)
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));
90
* @see eclox.ui.editor.editors.IEditor#dispose()
92
public void dispose() {
97
* @see eclox.ui.editor.editors.IEditor#grabVerticalSpace()
99
public boolean grabVerticalSpace() {
104
* @see eclox.ui.editor.basic.MultiEditor#refresh()
106
public void refresh() {
108
assert button != null;
110
// Refreshes the states.
113
// Refreshes the check box
114
State selection = getSelectionAsState();
115
button.setSelection( selection != null && selection.getName().equals(SELECTED) );
119
* @see eclox.ui.editor.editors.IEditor#setEnabled(boolean)
121
public void setEnabled(boolean enabled) {
123
assert button != null;
125
button.setEnabled(enabled);
129
* @see eclox.ui.editor.editors.IEditor#setFocus()
131
public void setFocus() {
133
assert button != null;