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
.ui
.term
;
13 import java
.util
.ArrayList
;
14 import java
.util
.List
;
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
;
23 import eu
.etaxonomy
.taxeditor
.preference
.Resources
;
24 import eu
.etaxonomy
.taxeditor
.store
.StoreUtil
;
25 import eu
.etaxonomy
.taxeditor
.ui
.forms
.AbstractCdmFormElement
;
26 import eu
.etaxonomy
.taxeditor
.ui
.forms
.CdmFormFactory
;
27 import eu
.etaxonomy
.taxeditor
.ui
.forms
.CdmPropertyChangeEvent
;
28 import eu
.etaxonomy
.taxeditor
.ui
.forms
.ICdmFormElement
;
29 import eu
.etaxonomy
.taxeditor
.ui
.forms
.IEnableableFormElement
;
32 * <p>Abstract AbstractEnumComboElement class.</p>
35 * @created Mar 16, 2010
38 public abstract class AbstractEnumComboElement
<T
extends Enum
> extends AbstractCdmFormElement
implements SelectionListener
, IEnableableFormElement
{
40 private static final int VISIBLE_ITEMS
= 10;
42 protected T selection
;
44 protected List
<T
> elementTypeList
= new ArrayList
<T
>();
47 protected Combo combo
;
50 * <p>Constructor for AbstractEnumComboElement.</p>
52 * @param formFactory a {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory} 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.
57 public AbstractEnumComboElement(CdmFormFactory formFactory
,
58 ICdmFormElement parentElement
, String labelString
) {
59 super(formFactory
, parentElement
);
60 label
= formFactory
.createLabel(getLayoutComposite(), labelString
);
64 combo
= new Combo(getLayoutComposite(), SWT
.BORDER
| SWT
.READ_ONLY
);
66 combo
.setLayoutData(CdmFormFactory
.FILL_HORIZONTALLY());
67 combo
.setVisibleItemCount(VISIBLE_ITEMS
);
71 combo
.addSelectionListener(this);
76 * <p>populateTypes</p>
78 protected abstract void populateTypes();
82 * <p>Setter for the field <code>selection</code>.</p>
84 * @param selection the selection to set
86 public void setSelection(T selection
) {
87 this.selection
= selection
;
88 combo
.select(elementTypeList
.indexOf(selection
));
92 * <p>addSelectionListener</p>
94 * @param listener a {@link org.eclipse.swt.events.SelectionListener} object.
96 public void addSelectionListener(SelectionListener listener
){
97 combo
.addSelectionListener(listener
);
101 * <p>removeSelectionListener</p>
103 * @param listener a {@link org.eclipse.swt.events.SelectionListener} object.
105 public void removeSelectionListener(SelectionListener listener
){
106 combo
.removeSelectionListener(listener
);
110 public void setSelected(boolean selected
) {
111 label
.setBackground(getColor(selected
));
115 * <p>Getter for the field <code>selection</code>.</p>
117 * @return the selection
119 public T
getSelection() {
124 public void setEnabled(boolean enabled
) {
125 combo
.setEnabled(enabled
);
129 * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
132 public void widgetSelected(SelectionEvent e
) {
133 selection
= elementTypeList
.get(combo
.getSelectionIndex());
134 firePropertyChangeEvent(new CdmPropertyChangeEvent(this, e
));
138 public void setIrrelevant(boolean irrelevant
) {
139 String colorId
= irrelevant ? Resources
.COLOR_COMPOSITE_IRRELEVANT
: Resources
.COLOR_COMPOSITE_BACKGROUND
;
141 Color color
= StoreUtil
.getColor(colorId
);
142 combo
.setBackground(color
);
147 public void setBackground(Color color
) {
148 label
.setBackground(color
);
152 public void widgetDefaultSelected(SelectionEvent e
) {}