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.ui.term;
|
12
|
|
13
|
import java.util.ArrayList;
|
14
|
import java.util.List;
|
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.graphics.Color;
|
20
|
import org.eclipse.swt.widgets.Combo;
|
21
|
import org.eclipse.swt.widgets.Label;
|
22
|
|
23
|
import eu.etaxonomy.taxeditor.preference.Resources;
|
24
|
import eu.etaxonomy.taxeditor.singlesource.ui.forms.CdmFormFactoryFacade;
|
25
|
import eu.etaxonomy.taxeditor.store.StoreUtil;
|
26
|
import eu.etaxonomy.taxeditor.ui.forms.AbstractCdmFormElement;
|
27
|
import eu.etaxonomy.taxeditor.ui.forms.CdmPropertyChangeEvent;
|
28
|
import eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement;
|
29
|
import eu.etaxonomy.taxeditor.ui.forms.IEnableableFormElement;
|
30
|
|
31
|
/**
|
32
|
* <p>Abstract AbstractEnumComboElement class.</p>
|
33
|
*
|
34
|
* @author n.hoffmann
|
35
|
* @created Mar 16, 2010
|
36
|
* @version 1.0
|
37
|
*/
|
38
|
public abstract class AbstractEnumComboElement<T extends Enum> extends AbstractCdmFormElement implements SelectionListener, IEnableableFormElement{
|
39
|
|
40
|
private static final int VISIBLE_ITEMS = 10;
|
41
|
|
42
|
protected T selection;
|
43
|
|
44
|
protected List<T> elementTypeList = new ArrayList<T>();
|
45
|
|
46
|
private Label label;
|
47
|
protected Combo combo;
|
48
|
|
49
|
/**
|
50
|
* <p>Constructor for AbstractEnumComboElement.</p>
|
51
|
*
|
52
|
* @param formFactory a {@link eu.etaxonomy.taxeditor.singlesource.ui.forms.CdmFormFactoryFacade} object.
|
53
|
* @param parentElement a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement} object.
|
54
|
* @param labelString a {@link java.lang.String} object.
|
55
|
* @param <T> a T object.
|
56
|
*/
|
57
|
public AbstractEnumComboElement(CdmFormFactoryFacade formFactory,
|
58
|
ICdmFormElement parentElement, String labelString) {
|
59
|
super(formFactory, parentElement);
|
60
|
label = formFactory.createLabel(getLayoutComposite(), labelString);
|
61
|
addControl(label);
|
62
|
|
63
|
// create combo
|
64
|
combo = new Combo(getLayoutComposite(), SWT.BORDER | SWT.READ_ONLY);
|
65
|
addControl(combo);
|
66
|
combo.setLayoutData(CdmFormFactoryFacade.FILL_HORIZONTALLY());
|
67
|
combo.setVisibleItemCount(VISIBLE_ITEMS);
|
68
|
|
69
|
populateTypes();
|
70
|
|
71
|
combo.addSelectionListener(this);
|
72
|
}
|
73
|
|
74
|
|
75
|
/**
|
76
|
* <p>populateTypes</p>
|
77
|
*/
|
78
|
protected abstract void populateTypes();
|
79
|
|
80
|
|
81
|
/**
|
82
|
* <p>Setter for the field <code>selection</code>.</p>
|
83
|
*
|
84
|
* @param selection the selection to set
|
85
|
*/
|
86
|
public void setSelection(T selection) {
|
87
|
this.selection = selection;
|
88
|
combo.select(elementTypeList.indexOf(selection));
|
89
|
}
|
90
|
|
91
|
/**
|
92
|
* <p>addSelectionListener</p>
|
93
|
*
|
94
|
* @param listener a {@link org.eclipse.swt.events.SelectionListener} object.
|
95
|
*/
|
96
|
public void addSelectionListener(SelectionListener listener){
|
97
|
combo.addSelectionListener(listener);
|
98
|
}
|
99
|
|
100
|
/**
|
101
|
* <p>removeSelectionListener</p>
|
102
|
*
|
103
|
* @param listener a {@link org.eclipse.swt.events.SelectionListener} object.
|
104
|
*/
|
105
|
public void removeSelectionListener(SelectionListener listener){
|
106
|
combo.removeSelectionListener(listener);
|
107
|
}
|
108
|
|
109
|
/** {@inheritDoc} */
|
110
|
public void setSelected(boolean selected) {
|
111
|
label.setBackground(getColor(selected));
|
112
|
}
|
113
|
|
114
|
/**
|
115
|
* <p>Getter for the field <code>selection</code>.</p>
|
116
|
*
|
117
|
* @return the selection
|
118
|
*/
|
119
|
public T getSelection() {
|
120
|
return selection;
|
121
|
}
|
122
|
|
123
|
/** {@inheritDoc} */
|
124
|
public void setEnabled(boolean enabled) {
|
125
|
combo.setEnabled(enabled);
|
126
|
}
|
127
|
|
128
|
/* (non-Javadoc)
|
129
|
* @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
|
130
|
*/
|
131
|
/** {@inheritDoc} */
|
132
|
public void widgetSelected(SelectionEvent e) {
|
133
|
selection = elementTypeList.get(combo.getSelectionIndex());
|
134
|
firePropertyChangeEvent(new CdmPropertyChangeEvent(this, e));
|
135
|
}
|
136
|
|
137
|
/** {@inheritDoc} */
|
138
|
public void setIrrelevant(boolean irrelevant) {
|
139
|
String colorId = irrelevant ? Resources.COLOR_COMPOSITE_IRRELEVANT : Resources.COLOR_COMPOSITE_BACKGROUND;
|
140
|
|
141
|
Color color = StoreUtil.getColor(colorId);
|
142
|
combo.setBackground(color);
|
143
|
}
|
144
|
|
145
|
/** {@inheritDoc} */
|
146
|
@Override
|
147
|
public void setBackground(Color color) {
|
148
|
label.setBackground(color);
|
149
|
}
|
150
|
|
151
|
/** {@inheritDoc} */
|
152
|
public void widgetDefaultSelected(SelectionEvent e) {}
|
153
|
}
|