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.Combo;
21
import org.eclipse.swt.widgets.Composite;
22
import org.eclipse.ui.forms.widgets.FormToolkit;
25
* Implements a multi editor that presents choices in a combo box.
27
* @author Guillaume Brocker
29
public class ComboMultiEditor extends MultiEditor {
32
* Implements a selection listener that will handle selection changes in the combo control.
34
private class MySelectionListener implements SelectionListener {
37
* @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
39
public void widgetDefaultSelected(SelectionEvent e) {
44
* @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
46
public void widgetSelected(SelectionEvent e) {
47
selectState( combo.getItem(combo.getSelectionIndex()) );
53
* the combo control that is the representation of the editor
60
* @param states an array of string representing all posible states
62
ComboMultiEditor( String [] states ) {
67
* @see eclox.ui.editor.editors.IEditor#createContent(org.eclipse.swt.widgets.Composite, org.eclipse.ui.forms.widgets.FormToolkit)
69
public void createContent(Composite parent, FormToolkit formToolkit) {
73
// Creates the combo control.
74
combo = new Combo(parent, SWT.DROP_DOWN|SWT.READ_ONLY);
75
combo.addSelectionListener( new MySelectionListener() );
76
formToolkit.adapt(combo, true, true);
78
// Fills the combo with the state names.
79
for( int i = 0; i != states.length; ++i ) {
80
combo.add( states[i].getName() );
82
combo.setVisibleItemCount(states.length);
84
// Installs a layout in the parent composite
85
parent.setLayout(new FillLayout());
89
* @see eclox.ui.editor.editors.IEditor#dispose()
91
public void dispose() {
96
* @see eclox.ui.editor.editors.IEditor#grabVerticalSpace()
98
public boolean grabVerticalSpace() {
103
* @see eclox.ui.editor.basic.MultiEditor#refresh()
105
public void refresh() {
107
assert combo != null;
111
// Selectes the string corresponding to the current selection
112
State selection = getSelectionAsState();
113
if( selection != null ) {
114
combo.select( combo.indexOf(selection.getName()) );
122
* @see eclox.ui.editor.editors.IEditor#setEnabled(boolean)
124
public void setEnabled(boolean enabled) {
126
assert combo != null;
128
combo.setEnabled(enabled);
132
* @see eclox.ui.editor.editors.IEditor#setFocus()
134
public void setFocus() {
136
assert combo != null;