3 * Copyright (C) 2016 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.
10 package eu
.etaxonomy
.taxeditor
.ui
.combo
;
12 import org
.eclipse
.jface
.viewers
.ComboViewer
;
13 import org
.eclipse
.swt
.SWT
;
14 import org
.eclipse
.swt
.events
.DisposeEvent
;
15 import org
.eclipse
.swt
.events
.DisposeListener
;
16 import org
.eclipse
.swt
.events
.SelectionEvent
;
17 import org
.eclipse
.swt
.events
.SelectionListener
;
18 import org
.eclipse
.swt
.graphics
.Color
;
19 import org
.eclipse
.swt
.widgets
.Combo
;
20 import org
.eclipse
.swt
.widgets
.Label
;
21 import org
.eclipse
.ui
.forms
.widgets
.TableWrapData
;
23 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
24 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
25 import eu
.etaxonomy
.taxeditor
.preference
.Resources
;
26 import eu
.etaxonomy
.taxeditor
.ui
.element
.AbstractCdmFormElement
;
27 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
28 import eu
.etaxonomy
.taxeditor
.ui
.element
.ICdmFormElement
;
29 import eu
.etaxonomy
.taxeditor
.ui
.element
.IEnableableFormElement
;
30 import eu
.etaxonomy
.taxeditor
.ui
.element
.ISelectable
;
31 import eu
.etaxonomy
.taxeditor
.ui
.element
.LayoutConstants
;
38 public abstract class AbstractComboElement
<T
> extends
39 AbstractCdmFormElement
implements SelectionListener
,
40 IEnableableFormElement
, ISelectable
,
43 protected static final int DEFAULT_VISIBLE_ITEMS
= 10;
45 protected T selection
;
47 protected Label label
;
49 protected final Combo combo
;
52 public AbstractComboElement(CdmFormFactory formFactory
, ICdmFormElement formElement
) {
53 super(formFactory
, formElement
);
55 label
= formFactory
.createLabel(getLayoutComposite(), "");
59 ComboViewer viewer
= new ComboViewer(getLayoutComposite(), SWT
.BORDER
| SWT
.READ_ONLY
);
60 combo
= viewer
.getCombo();
62 TableWrapData fill_HORIZONTALLY
= LayoutConstants
.FILL_HORIZONTALLY();
63 combo
.setLayoutData(fill_HORIZONTALLY
);
64 fill_HORIZONTALLY
.maxWidth
= 50;
65 combo
.setVisibleItemCount(DEFAULT_VISIBLE_ITEMS
);
70 public void setBackground(Color color
) {
72 label
.setBackground(color
);
78 public void setIrrelevant(boolean irrelevant
) {
79 String colorId
= irrelevant ? Resources
.COLOR_COMPOSITE_IRRELEVANT
80 : Resources
.COLOR_COMPOSITE_BACKGROUND
;
82 Color color
= AbstractUtility
.getColor(colorId
);
83 combo
.setBackground(color
);
86 public void setVisibleItemCount(int count
){
87 combo
.setVisibleItemCount(count
);
92 public void setSelected(boolean selected
) {
93 setBackground(selected ? SELECTED
: getPersistentBackground());
96 public T
getSelection() {
100 public void addSelectionListener(SelectionListener listener
) {
101 combo
.addSelectionListener(listener
);
104 public void removeSelectionListener(SelectionListener listener
) {
105 combo
.removeSelectionListener(listener
);
110 public void widgetDisposed(DisposeEvent e
) {
111 PreferencesUtil
.getPreferenceStore().removePropertyChangeListener(this);
115 public void widgetDefaultSelected(SelectionEvent e
) {
119 public boolean isEnabled() {
120 return combo
.isEnabled();
125 public void setEnabled(boolean enabled
) {
126 combo
.setEnabled(enabled
);
129 public abstract void setSelection(T selection
);