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
.swt
.SWT
;
12 import org
.eclipse
.swt
.custom
.CCombo
;
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
.Label
;
19 import org
.eclipse
.ui
.forms
.widgets
.TableWrapData
;
21 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
22 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
23 import eu
.etaxonomy
.taxeditor
.preference
.Resources
;
24 import eu
.etaxonomy
.taxeditor
.ui
.element
.AbstractCdmFormElement
;
25 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
26 import eu
.etaxonomy
.taxeditor
.ui
.element
.ICdmFormElement
;
27 import eu
.etaxonomy
.taxeditor
.ui
.element
.IEnableableFormElement
;
28 import eu
.etaxonomy
.taxeditor
.ui
.element
.ISelectable
;
29 import eu
.etaxonomy
.taxeditor
.ui
.element
.LayoutConstants
;
36 public abstract class AbstractComboElement
<T
> extends
37 AbstractCdmFormElement
implements SelectionListener
,
38 IEnableableFormElement
, ISelectable
,
41 protected static final int DEFAULT_VISIBLE_ITEMS
= 10;
43 protected T selection
;
45 protected Label label
;
47 protected final CCombo combo
;
50 public AbstractComboElement(CdmFormFactory formFactory
, ICdmFormElement formElement
) {
51 super(formFactory
, formElement
);
53 label
= formFactory
.createLabel(getLayoutComposite(), "");
57 combo
= new CCombo(getLayoutComposite(), SWT
.READ_ONLY
|SWT
.BORDER
);
60 TableWrapData fill_HORIZONTALLY
= LayoutConstants
.FILL_HORIZONTALLY();
61 combo
.setLayoutData(fill_HORIZONTALLY
);
62 fill_HORIZONTALLY
.maxWidth
= 50;
63 combo
.setVisibleItemCount(DEFAULT_VISIBLE_ITEMS
);
65 //disable mouse-wheel selection
66 combo
.addListener(SWT
.MouseWheel
, e
->e
.doit
=false);
71 public void setBackground(Color color
) {
73 label
.setBackground(color
);
79 public void setIrrelevant(boolean irrelevant
) {
80 String colorId
= irrelevant ? Resources
.COLOR_COMPOSITE_IRRELEVANT
81 : Resources
.COLOR_COMPOSITE_BACKGROUND
;
83 Color color
= AbstractUtility
.getColor(colorId
);
84 combo
.setBackground(color
);
86 label
.setBackground(color
);
91 public void setVisibleItemCount(int count
){
92 combo
.setVisibleItemCount(count
);
97 public void setSelected(boolean selected
) {
98 setBackground(selected ? SELECTED
: getPersistentBackground());
101 public T
getSelection() {
105 public void addSelectionListener(SelectionListener listener
) {
106 combo
.addSelectionListener(listener
);
109 public void removeSelectionListener(SelectionListener listener
) {
110 combo
.removeSelectionListener(listener
);
115 public void widgetDisposed(DisposeEvent e
) {
116 PreferencesUtil
.getPreferenceStore().removePropertyChangeListener(this);
120 public void widgetDefaultSelected(SelectionEvent e
) {
124 public boolean isEnabled() {
125 return combo
.isEnabled();
130 public void setEnabled(boolean enabled
) {
131 combo
.setEnabled(enabled
);
134 public abstract void setSelection(T selection
);