3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
11 package eu
.etaxonomy
.taxeditor
.forms
.term
;
13 import java
.util
.ArrayList
;
14 import java
.util
.List
;
16 import org
.apache
.log4j
.Logger
;
17 import org
.eclipse
.swt
.SWT
;
18 import org
.eclipse
.swt
.events
.SelectionEvent
;
19 import org
.eclipse
.swt
.events
.SelectionListener
;
20 import org
.eclipse
.swt
.graphics
.Color
;
21 import org
.eclipse
.swt
.layout
.GridData
;
22 import org
.eclipse
.swt
.widgets
.Combo
;
23 import org
.eclipse
.swt
.widgets
.Label
;
25 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
26 import eu
.etaxonomy
.taxeditor
.forms
.AbstractCdmFormElement
;
27 import eu
.etaxonomy
.taxeditor
.forms
.CdmFormFactory
;
28 import eu
.etaxonomy
.taxeditor
.forms
.CdmPropertyChangeEvent
;
29 import eu
.etaxonomy
.taxeditor
.forms
.ICdmFormElement
;
30 import eu
.etaxonomy
.taxeditor
.forms
.IEnableableFormElement
;
31 import eu
.etaxonomy
.taxeditor
.preference
.Resources
;
34 * <p>Abstract AbstractEnumComboElement class.</p>
37 * @created Mar 16, 2010
40 public abstract class AbstractEnumComboElement
<T
extends Enum
> extends AbstractCdmFormElement
implements SelectionListener
, IEnableableFormElement
{
43 private static final Logger logger
= Logger
44 .getLogger(AbstractEnumComboElement
.class);
46 private static final int VISIBLE_ITEMS
= 10;
48 protected T selection
;
50 protected List
<T
> elementTypeList
= new ArrayList
<T
>();
53 protected Combo combo
;
56 * <p>Constructor for AbstractEnumComboElement.</p>
58 * @param formFactory a {@link eu.etaxonomy.taxeditor.forms.CdmFormFactory} object.
59 * @param parentElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
60 * @param labelString a {@link java.lang.String} object.
61 * @param <T> a T object.
63 public AbstractEnumComboElement(CdmFormFactory formFactory
,
64 ICdmFormElement parentElement
, String labelString
) {
65 super(formFactory
, parentElement
);
66 label
= formFactory
.createLabel(getLayoutComposite(), labelString
);
70 combo
= new Combo(getLayoutComposite(), SWT
.BORDER
| SWT
.READ_ONLY
);
72 combo
.setLayoutData(CdmFormFactory
.FILL_HORIZONTALLY());
73 combo
.setVisibleItemCount(VISIBLE_ITEMS
);
77 combo
.addSelectionListener(this);
82 * <p>populateTypes</p>
84 protected abstract void populateTypes();
88 * <p>Setter for the field <code>selection</code>.</p>
90 * @param selection the selection to set
92 public void setSelection(T selection
) {
93 this.selection
= selection
;
94 combo
.select(elementTypeList
.indexOf(selection
));
98 * <p>addSelectionListener</p>
100 * @param listener a {@link org.eclipse.swt.events.SelectionListener} object.
102 public void addSelectionListener(SelectionListener listener
){
103 combo
.addSelectionListener(listener
);
107 * <p>removeSelectionListener</p>
109 * @param listener a {@link org.eclipse.swt.events.SelectionListener} object.
111 public void removeSelectionListener(SelectionListener listener
){
112 combo
.removeSelectionListener(listener
);
116 public void setSelected(boolean selected
) {
117 label
.setBackground(getColor(selected
));
121 * <p>Getter for the field <code>selection</code>.</p>
123 * @return the selection
125 public T
getSelection() {
130 public void setEnabled(boolean enabled
) {
131 combo
.setEnabled(enabled
);
135 * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
138 public void widgetSelected(SelectionEvent e
) {
139 selection
= elementTypeList
.get(combo
.getSelectionIndex());
140 firePropertyChangeEvent(new CdmPropertyChangeEvent(this, e
));
144 public void setIrrelevant(boolean irrelevant
) {
145 String colorId
= irrelevant ? Resources
.COLOR_COMPOSITE_IRRELEVANT
: Resources
.COLOR_COMPOSITE_BACKGROUND
;
147 Color color
= EditorUtil
.getColor(colorId
);
148 combo
.setBackground(color
);
153 public void setBackground(Color color
) {
154 label
.setBackground(color
);
158 public void widgetDefaultSelected(SelectionEvent e
) {}