1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2016 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
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.
|
9
|
*/
|
10
|
package eu.etaxonomy.taxeditor.ui.combo;
|
11
|
|
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;
|
22
|
|
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;
|
32
|
|
33
|
/**
|
34
|
* @author pplitzner
|
35
|
* @date Aug 11, 2016
|
36
|
*
|
37
|
*/
|
38
|
public abstract class AbstractComboElement<T> extends
|
39
|
AbstractCdmFormElement implements SelectionListener,
|
40
|
IEnableableFormElement, ISelectable,
|
41
|
DisposeListener {
|
42
|
|
43
|
protected static final int DEFAULT_VISIBLE_ITEMS = 10;
|
44
|
|
45
|
protected T selection;
|
46
|
|
47
|
protected Label label;
|
48
|
|
49
|
protected final Combo combo;
|
50
|
|
51
|
|
52
|
public AbstractComboElement(CdmFormFactory formFactory, ICdmFormElement formElement) {
|
53
|
super(formFactory, formElement);
|
54
|
|
55
|
label = formFactory.createLabel(getLayoutComposite(), "");
|
56
|
addControl(label);
|
57
|
|
58
|
// create combo
|
59
|
ComboViewer viewer = new ComboViewer(getLayoutComposite(), SWT.BORDER | SWT.READ_ONLY );
|
60
|
combo = viewer.getCombo();
|
61
|
addControl(combo);
|
62
|
TableWrapData fill_HORIZONTALLY = LayoutConstants.FILL_HORIZONTALLY();
|
63
|
combo.setLayoutData(fill_HORIZONTALLY);
|
64
|
fill_HORIZONTALLY.maxWidth = 50;
|
65
|
combo.setVisibleItemCount(DEFAULT_VISIBLE_ITEMS);
|
66
|
}
|
67
|
|
68
|
/** {@inheritDoc} */
|
69
|
@Override
|
70
|
public void setBackground(Color color) {
|
71
|
if (label != null) {
|
72
|
label.setBackground(color);
|
73
|
}
|
74
|
}
|
75
|
|
76
|
/** {@inheritDoc} */
|
77
|
@Override
|
78
|
public void setIrrelevant(boolean irrelevant) {
|
79
|
String colorId = irrelevant ? Resources.COLOR_COMPOSITE_IRRELEVANT
|
80
|
: Resources.COLOR_COMPOSITE_BACKGROUND;
|
81
|
|
82
|
Color color = AbstractUtility.getColor(colorId);
|
83
|
combo.setBackground(color);
|
84
|
}
|
85
|
|
86
|
public void setVisibleItemCount(int count){
|
87
|
combo.setVisibleItemCount(count);
|
88
|
}
|
89
|
|
90
|
/** {@inheritDoc} */
|
91
|
@Override
|
92
|
public void setSelected(boolean selected) {
|
93
|
setBackground(selected ? SELECTED : getPersistentBackground());
|
94
|
}
|
95
|
|
96
|
public T getSelection() {
|
97
|
return selection;
|
98
|
}
|
99
|
|
100
|
public void addSelectionListener(SelectionListener listener) {
|
101
|
combo.addSelectionListener(listener);
|
102
|
}
|
103
|
|
104
|
public void removeSelectionListener(SelectionListener listener) {
|
105
|
combo.removeSelectionListener(listener);
|
106
|
}
|
107
|
|
108
|
/** {@inheritDoc} */
|
109
|
@Override
|
110
|
public void widgetDisposed(DisposeEvent e) {
|
111
|
PreferencesUtil.getPreferenceStore().removePropertyChangeListener(this);
|
112
|
}
|
113
|
|
114
|
@Override
|
115
|
public void widgetDefaultSelected(SelectionEvent e) {
|
116
|
}
|
117
|
|
118
|
@Override
|
119
|
public boolean isEnabled() {
|
120
|
return combo.isEnabled();
|
121
|
}
|
122
|
|
123
|
/** {@inheritDoc} */
|
124
|
@Override
|
125
|
public void setEnabled(boolean enabled) {
|
126
|
combo.setEnabled(enabled);
|
127
|
}
|
128
|
|
129
|
public abstract void setSelection(T selection);
|
130
|
}
|