2 * Copyright (C) 2016 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
9 package eu
.etaxonomy
.taxeditor
.ui
.combo
;
11 import org
.eclipse
.jface
.viewers
.ComboViewer
;
12 import org
.eclipse
.swt
.SWT
;
13 import org
.eclipse
.swt
.events
.DisposeEvent
;
14 import org
.eclipse
.swt
.events
.DisposeListener
;
15 import org
.eclipse
.swt
.events
.SelectionEvent
;
16 import org
.eclipse
.swt
.events
.SelectionListener
;
17 import org
.eclipse
.swt
.graphics
.Color
;
18 import org
.eclipse
.swt
.widgets
.Combo
;
19 import org
.eclipse
.swt
.widgets
.Label
;
20 import org
.eclipse
.ui
.forms
.widgets
.TableWrapData
;
22 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
23 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
24 import eu
.etaxonomy
.taxeditor
.preference
.Resources
;
25 import eu
.etaxonomy
.taxeditor
.ui
.element
.AbstractCdmFormElement
;
26 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
27 import eu
.etaxonomy
.taxeditor
.ui
.element
.ICdmFormElement
;
28 import eu
.etaxonomy
.taxeditor
.ui
.element
.IEnableableFormElement
;
29 import eu
.etaxonomy
.taxeditor
.ui
.element
.ISelectable
;
30 import eu
.etaxonomy
.taxeditor
.ui
.element
.LayoutConstants
;
37 public abstract class AbstractComboElement
<T
> extends
38 AbstractCdmFormElement
implements SelectionListener
,
39 IEnableableFormElement
, ISelectable
,
42 protected static final int DEFAULT_VISIBLE_ITEMS
= 10;
44 protected T selection
;
46 protected Label label
;
48 protected final Combo combo
;
51 public AbstractComboElement(CdmFormFactory formFactory
, ICdmFormElement formElement
) {
52 super(formFactory
, formElement
);
54 label
= formFactory
.createLabel(getLayoutComposite(), "");
58 ComboViewer viewer
= new ComboViewer(getLayoutComposite(), SWT
.BORDER
| SWT
.READ_ONLY
);
59 combo
= viewer
.getCombo();
61 TableWrapData fill_HORIZONTALLY
= LayoutConstants
.FILL_HORIZONTALLY();
62 combo
.setLayoutData(fill_HORIZONTALLY
);
63 fill_HORIZONTALLY
.maxWidth
= 50;
64 combo
.setVisibleItemCount(DEFAULT_VISIBLE_ITEMS
);
69 public void setBackground(Color color
) {
71 label
.setBackground(color
);
77 public void setIrrelevant(boolean irrelevant
) {
78 String colorId
= irrelevant ? Resources
.COLOR_COMPOSITE_IRRELEVANT
79 : Resources
.COLOR_COMPOSITE_BACKGROUND
;
81 Color color
= AbstractUtility
.getColor(colorId
);
82 combo
.setBackground(color
);
85 public void setVisibleItemCount(int count
){
86 combo
.setVisibleItemCount(count
);
91 public void setSelected(boolean selected
) {
92 setBackground(selected ? SELECTED
: getPersistentBackground());
95 public T
getSelection() {
99 public void addSelectionListener(SelectionListener listener
) {
100 combo
.addSelectionListener(listener
);
103 public void removeSelectionListener(SelectionListener listener
) {
104 combo
.removeSelectionListener(listener
);
109 public void widgetDisposed(DisposeEvent e
) {
110 PreferencesUtil
.getPreferenceStore().removePropertyChangeListener(this);
114 public void widgetDefaultSelected(SelectionEvent e
) {
118 public boolean isEnabled() {
119 return combo
.isEnabled();
124 public void setEnabled(boolean enabled
) {
125 combo
.setEnabled(enabled
);
128 public abstract void setSelection(T selection
);