Revision 97278383
Added by Patrick Plitzner about 7 years ago
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/combo/AbstractComboElement.java | ||
---|---|---|
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 |
} |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/combo/EnumComboElement.java | ||
---|---|---|
17 | 17 |
import java.util.List; |
18 | 18 |
import java.util.Map.Entry; |
19 | 19 |
|
20 |
import org.eclipse.swt.SWT; |
|
21 | 20 |
import org.eclipse.swt.events.SelectionEvent; |
22 |
import org.eclipse.swt.events.SelectionListener; |
|
23 |
import org.eclipse.swt.graphics.Color; |
|
24 |
import org.eclipse.swt.widgets.Combo; |
|
25 |
import org.eclipse.swt.widgets.Label; |
|
26 | 21 |
|
27 | 22 |
import eu.etaxonomy.cdm.model.common.IEnumTerm; |
28 | 23 |
import eu.etaxonomy.cdm.model.common.OriginalSourceType; |
... | ... | |
30 | 25 |
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType; |
31 | 26 |
import eu.etaxonomy.cdm.model.reference.ReferenceType; |
32 | 27 |
import eu.etaxonomy.taxeditor.model.AbstractUtility; |
33 |
import eu.etaxonomy.taxeditor.preference.Resources; |
|
34 |
import eu.etaxonomy.taxeditor.store.StoreUtil; |
|
35 |
import eu.etaxonomy.taxeditor.ui.element.AbstractCdmFormElement; |
|
36 | 28 |
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory; |
37 | 29 |
import eu.etaxonomy.taxeditor.ui.element.CdmPropertyChangeEvent; |
38 | 30 |
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement; |
39 |
import eu.etaxonomy.taxeditor.ui.element.IEnableableFormElement; |
|
40 |
import eu.etaxonomy.taxeditor.ui.element.ISelectable; |
|
41 |
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants; |
|
42 | 31 |
|
43 | 32 |
/** |
44 |
* <p> |
|
45 |
* Abstract AbstractEnumComboElement class. |
|
46 |
* </p> |
|
47 |
* |
|
48 | 33 |
* @author n.hoffmann |
49 | 34 |
* @created Mar 16, 2010 |
50 | 35 |
* @version 1.0 |
51 | 36 |
*/ |
52 | 37 |
public class EnumComboElement<T extends IEnumTerm<T>> extends |
53 |
AbstractCdmFormElement implements SelectionListener, |
|
54 |
IEnableableFormElement, ISelectable { |
|
38 |
AbstractComboElement<T> { |
|
55 | 39 |
|
56 | 40 |
//TODO RL |
57 | 41 |
public void setVisible(boolean b){ |
58 | 42 |
combo.setVisible(b); |
59 | 43 |
} |
60 | 44 |
|
61 |
|
|
45 |
|
|
62 | 46 |
private static CdmEnumDataHolder[] cdmEnumDataHolders = { |
63 | 47 |
new CdmEnumDataHolder<NomenclaturalCode>(){ |
64 | 48 |
|
... | ... | |
135 | 119 |
|
136 | 120 |
}; |
137 | 121 |
|
138 |
private static final int DEFAULT_VISIBLE_ITEMS = 10; |
|
139 |
|
|
140 |
protected T selection; |
|
141 |
|
|
142 | 122 |
protected List<T> elementTypeList = new ArrayList<T>(); |
143 | 123 |
|
144 |
private final Label label; |
|
145 |
protected Combo combo; |
|
146 |
|
|
147 | 124 |
private final Class<T> enumType; |
148 | 125 |
|
149 |
/** |
|
150 |
* <p> |
|
151 |
* Constructor for AbstractEnumComboElement. |
|
152 |
* </p> |
|
153 |
* |
|
154 |
* @param formFactory |
|
155 |
* a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} |
|
156 |
* object. |
|
157 |
* @param parentElement |
|
158 |
* a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} |
|
159 |
* object. |
|
160 |
* @param labelString |
|
161 |
* a {@link java.lang.String} object. |
|
162 |
* @param <T> |
|
163 |
* a T object. |
|
164 |
*/ |
|
165 | 126 |
public EnumComboElement(CdmFormFactory formFactory, |
166 | 127 |
ICdmFormElement parentElement, Class<T> enumType, int style) { |
167 | 128 |
super(formFactory, parentElement); |
168 | 129 |
this.enumType = enumType; |
169 |
label = formFactory.createLabel(getLayoutComposite(), getDefaultLabelString()); |
|
170 |
addControl(label); |
|
171 |
|
|
172 |
// create combo |
|
173 |
combo = new Combo(getLayoutComposite(), SWT.BORDER | SWT.READ_ONLY); |
|
174 |
addControl(combo); |
|
175 |
combo.setLayoutData(LayoutConstants.FILL_HORIZONTALLY()); |
|
176 |
setVisibleItemCount(DEFAULT_VISIBLE_ITEMS); |
|
130 |
label.setText(getDefaultLabelString()); |
|
177 | 131 |
|
178 | 132 |
populateTypes(); |
179 | 133 |
|
... | ... | |
193 | 147 |
return "No Label"; |
194 | 148 |
} |
195 | 149 |
|
196 |
/** |
|
197 |
* <p> |
|
198 |
* populateTypes |
|
199 |
* </p> |
|
200 |
*/ |
|
201 | 150 |
private void populateTypes(){ |
202 | 151 |
Collection<T> elementsForClass = getElementsForClass(enumType); |
203 | 152 |
// special hierarchical order for specimens |
... | ... | |
217 | 166 |
} |
218 | 167 |
} |
219 | 168 |
|
220 |
/** |
|
221 |
* <p> |
|
222 |
* Setter for the field <code>selection</code>. |
|
223 |
* </p> |
|
224 |
* |
|
225 |
* @param selection |
|
226 |
* the selection to set |
|
227 |
*/ |
|
228 |
public void setSelection(T selection) { |
|
169 |
@Override |
|
170 |
public void setSelection(T selection) { |
|
229 | 171 |
this.selection = selection; |
230 | 172 |
combo.select(elementTypeList.indexOf(selection)); |
231 | 173 |
} |
232 |
|
|
233 |
/** |
|
234 |
* <p> |
|
235 |
* addSelectionListener |
|
236 |
* </p> |
|
237 |
* |
|
238 |
* @param listener |
|
239 |
* a {@link org.eclipse.swt.events.SelectionListener} object. |
|
240 |
*/ |
|
241 |
public void addSelectionListener(SelectionListener listener) { |
|
242 |
combo.addSelectionListener(listener); |
|
243 |
} |
|
244 |
|
|
245 |
/** |
|
246 |
* <p> |
|
247 |
* removeSelectionListener |
|
248 |
* </p> |
|
249 |
* |
|
250 |
* @param listener |
|
251 |
* a {@link org.eclipse.swt.events.SelectionListener} object. |
|
252 |
*/ |
|
253 |
public void removeSelectionListener(SelectionListener listener) { |
|
254 |
combo.removeSelectionListener(listener); |
|
255 |
} |
|
256 |
|
|
257 |
/** {@inheritDoc} */ |
|
258 |
@Override |
|
259 |
public void setSelected(boolean selected) { |
|
260 |
setBackground(selected ? SELECTED : getPersistentBackground()); |
|
261 |
} |
|
262 |
|
|
263 |
/** |
|
264 |
* <p> |
|
265 |
* Getter for the field <code>selection</code>. |
|
266 |
* </p> |
|
267 |
* |
|
268 |
* @return the selection |
|
269 |
*/ |
|
270 |
public T getSelection() { |
|
271 |
return selection; |
|
272 |
} |
|
273 |
|
|
274 |
/** {@inheritDoc} */ |
|
275 |
@Override |
|
276 |
public void setEnabled(boolean enabled) { |
|
277 |
combo.setEnabled(enabled); |
|
278 |
} |
|
279 |
|
|
280 |
/* (non-Javadoc) |
|
281 |
* @see eu.etaxonomy.taxeditor.ui.element.IEnableableFormElement#isEnabled() |
|
282 |
*/ |
|
283 |
@Override |
|
284 |
public boolean isEnabled() { |
|
285 |
return combo.isEnabled(); |
|
286 |
} |
|
287 |
|
|
288 |
/* |
|
289 |
* (non-Javadoc) |
|
290 |
* |
|
291 |
* @see |
|
292 |
* org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt |
|
293 |
* .events.SelectionEvent) |
|
294 |
*/ |
|
295 | 174 |
/** {@inheritDoc} */ |
296 | 175 |
@Override |
297 | 176 |
public void widgetSelected(SelectionEvent e) { |
... | ... | |
299 | 178 |
firePropertyChangeEvent(new CdmPropertyChangeEvent(this, e)); |
300 | 179 |
} |
301 | 180 |
|
302 |
/** {@inheritDoc} */ |
|
303 |
@Override |
|
304 |
public void setIrrelevant(boolean irrelevant) { |
|
305 |
String colorId = irrelevant ? Resources.COLOR_COMPOSITE_IRRELEVANT |
|
306 |
: Resources.COLOR_COMPOSITE_BACKGROUND; |
|
307 |
|
|
308 |
Color color = StoreUtil.getColor(colorId); |
|
309 |
combo.setBackground(color); |
|
310 |
} |
|
311 |
|
|
312 |
/** {@inheritDoc} */ |
|
313 |
@Override |
|
314 |
public void setBackground(Color color) { |
|
315 |
label.setBackground(color); |
|
316 |
} |
|
317 |
|
|
318 |
/** {@inheritDoc} */ |
|
319 |
@Override |
|
320 |
public void widgetDefaultSelected(SelectionEvent e) { |
|
321 |
} |
|
322 |
|
|
323 |
public void setVisibleItemCount(int visibleItems){ |
|
324 |
combo.setVisibleItemCount(visibleItems); |
|
325 |
} |
|
326 |
|
|
327 | 181 |
private Collection<T> getElementsForClass(Class<T> clazz){ |
328 | 182 |
CdmEnumDataHolder<T> dataHolder = getCdmEnumDataHolderForClass(clazz); |
329 | 183 |
if (dataHolder != null) { |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/combo/TermComboElement.java | ||
---|---|---|
10 | 10 |
import java.util.List; |
11 | 11 |
|
12 | 12 |
import org.eclipse.jface.util.PropertyChangeEvent; |
13 |
import org.eclipse.jface.viewers.ComboViewer; |
|
14 | 13 |
import org.eclipse.swt.SWT; |
15 |
import org.eclipse.swt.events.DisposeEvent; |
|
16 |
import org.eclipse.swt.events.DisposeListener; |
|
17 | 14 |
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; |
|
22 | 15 |
import org.eclipse.swt.widgets.Listener; |
23 |
import org.eclipse.ui.forms.widgets.TableWrapData; |
|
24 | 16 |
|
25 | 17 |
import eu.etaxonomy.cdm.model.common.DefinedTermBase; |
26 | 18 |
import eu.etaxonomy.cdm.model.common.TermType; |
... | ... | |
28 | 20 |
import eu.etaxonomy.taxeditor.model.MessagingUtils; |
29 | 21 |
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys; |
30 | 22 |
import eu.etaxonomy.taxeditor.preference.PreferencesUtil; |
31 |
import eu.etaxonomy.taxeditor.preference.Resources; |
|
32 | 23 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
33 |
import eu.etaxonomy.taxeditor.store.StoreUtil; |
|
34 | 24 |
import eu.etaxonomy.taxeditor.store.TermManager; |
35 |
import eu.etaxonomy.taxeditor.ui.element.AbstractCdmFormElement; |
|
36 | 25 |
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory; |
37 | 26 |
import eu.etaxonomy.taxeditor.ui.element.CdmPropertyChangeEvent; |
38 | 27 |
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement; |
39 |
import eu.etaxonomy.taxeditor.ui.element.IEnableableFormElement; |
|
40 |
import eu.etaxonomy.taxeditor.ui.element.ISelectable; |
|
41 |
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants; |
|
42 | 28 |
|
43 | 29 |
/** |
44 |
* <p> |
|
45 |
* Abstract AbstractTermComboElement class. |
|
46 |
* </p> |
|
47 |
* |
|
48 | 30 |
* @author n.hoffmann |
49 | 31 |
* @created Nov 5, 2009 |
50 | 32 |
* @version 1.0 |
51 | 33 |
* @param <T> |
52 | 34 |
*/ |
53 | 35 |
public class TermComboElement<T extends DefinedTermBase> |
54 |
extends AbstractCdmFormElement implements SelectionListener, |
|
55 |
DisposeListener, IEnableableFormElement, ISelectable { |
|
56 |
|
|
57 |
private static final int DEFAULT_VISIBLE_ITEMS = 10; |
|
58 |
|
|
59 |
private T selection; |
|
36 |
extends AbstractComboElement<T> { |
|
60 | 37 |
|
61 | 38 |
private T emptyElement; |
62 | 39 |
private static String EMPTY_ELEMENT_LABEL = ""; |
63 | 40 |
|
64 |
protected Label label; |
|
65 |
private final Combo combo; |
|
66 |
|
|
67 | 41 |
private ArrayList<T> terms; |
68 | 42 |
|
69 | 43 |
private Comparator<T> termComparator; |
... | ... | |
105 | 79 |
this.addEmptyElement = addEmptyElement; |
106 | 80 |
|
107 | 81 |
if (labelString != null) { |
108 |
label = formFactory.createLabel(getLayoutComposite(), labelString); |
|
109 |
addControl(label); |
|
82 |
label.setText(labelString); |
|
110 | 83 |
} |
111 | 84 |
|
112 |
// create combo |
|
113 |
ComboViewer viewer = new ComboViewer(getLayoutComposite(), SWT.BORDER | SWT.READ_ONLY ); |
|
114 |
combo = viewer.getCombo(); |
|
115 |
addControl(combo); |
|
116 |
TableWrapData fill_HORIZONTALLY = LayoutConstants.FILL_HORIZONTALLY(); |
|
117 |
combo.setLayoutData(fill_HORIZONTALLY); |
|
118 |
fill_HORIZONTALLY.maxWidth = 50; |
|
119 |
combo.setVisibleItemCount(DEFAULT_VISIBLE_ITEMS); |
|
120 |
|
|
121 |
|
|
122 | 85 |
if(termType!=null){ |
123 | 86 |
//TODO try to remove generic T and avoid classes to be used |
124 | 87 |
populateTerms((List<T>) getTermManager().getPreferredTerms(termType)); |
... | ... | |
139 | 102 |
} |
140 | 103 |
} |
141 | 104 |
|
142 |
/** |
|
143 |
* <p> |
|
144 |
* Getter for the field <code>selection</code>. |
|
145 |
* </p> |
|
146 |
* |
|
147 |
* @return a T object. |
|
148 |
*/ |
|
149 |
public T getSelection() { |
|
150 |
return selection; |
|
151 |
} |
|
152 |
|
|
153 | 105 |
/** |
154 | 106 |
* <p>Sets the selection of the combo to the given T object.</p> |
155 | 107 |
* <p>Passing <code>null</code> to this method will set the selection to |
... | ... | |
158 | 110 |
* @param selection |
159 | 111 |
* a T object or <code>null</code> to clear the selection |
160 | 112 |
*/ |
161 |
public void setSelection(T selection) { |
|
113 |
@Override |
|
114 |
public void setSelection(T selection) { |
|
162 | 115 |
this.selection = selection; |
163 | 116 |
|
164 | 117 |
Listener[] listeners = combo.getListeners(SWT.Selection); |
... | ... | |
243 | 196 |
combo.select(index); |
244 | 197 |
} |
245 | 198 |
|
246 |
/* |
|
247 |
* (non-Javadoc) |
|
248 |
* @see eu.etaxonomy.taxeditor.forms.IEnableableFormElement#setEnabled(boolean) |
|
249 |
*/ |
|
250 |
/** {@inheritDoc} */ |
|
251 |
@Override |
|
252 |
public void setEnabled(boolean enabled) { |
|
253 |
combo.setEnabled(enabled); |
|
254 |
} |
|
255 |
|
|
256 |
/* (non-Javadoc) |
|
257 |
* @see eu.etaxonomy.taxeditor.ui.element.IEnableableFormElement#isEnabled() |
|
258 |
*/ |
|
259 |
@Override |
|
260 |
public boolean isEnabled() { |
|
261 |
return combo.isEnabled(); |
|
262 |
} |
|
263 |
|
|
264 |
/** |
|
265 |
* <p> |
|
266 |
* preferredTerms |
|
267 |
* </p> |
|
268 |
* |
|
269 |
* @return a {@link java.util.List} object. |
|
270 |
*/ |
|
271 | 199 |
protected List<T> getPreferredTerms(){ |
272 | 200 |
List<T> preferredTerms = new ArrayList<T>(); |
273 | 201 |
if (customPreferredTerms != null){ |
... | ... | |
326 | 254 |
populateTerms(preferredTerms); |
327 | 255 |
} |
328 | 256 |
|
329 |
/** |
|
330 |
* <p> |
|
331 |
* addSelectionListener |
|
332 |
* </p> |
|
333 |
* |
|
334 |
* @param listener |
|
335 |
* a {@link org.eclipse.swt.events.SelectionListener} object. |
|
336 |
*/ |
|
337 |
public void addSelectionListener(SelectionListener listener) { |
|
338 |
combo.addSelectionListener(listener); |
|
339 |
} |
|
340 |
|
|
341 |
/** |
|
342 |
* <p> |
|
343 |
* removeSelectionListener |
|
344 |
* </p> |
|
345 |
* |
|
346 |
* @param listener |
|
347 |
* a {@link org.eclipse.swt.events.SelectionListener} object. |
|
348 |
*/ |
|
349 |
public void removeSelectionListener(SelectionListener listener) { |
|
350 |
combo.removeSelectionListener(listener); |
|
351 |
} |
|
352 |
|
|
353 |
/* |
|
354 |
* (non-Javadoc) |
|
355 |
* |
|
356 |
* @see |
|
357 |
* org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt |
|
358 |
* .events.SelectionEvent) |
|
359 |
*/ |
|
360 | 257 |
/** {@inheritDoc} */ |
361 | 258 |
@Override |
362 | 259 |
public void widgetSelected(SelectionEvent e) { |
... | ... | |
364 | 261 |
firePropertyChangeEvent(new CdmPropertyChangeEvent(this, e)); |
365 | 262 |
} |
366 | 263 |
|
367 |
/* |
|
368 |
* (non-Javadoc) |
|
369 |
* |
|
370 |
* @see java.beans.PropertyChangeListener#propertyChange(java.beans. |
|
371 |
* PropertyChangeEvent) |
|
372 |
*/ |
|
373 | 264 |
/** {@inheritDoc} */ |
374 | 265 |
@Override |
375 | 266 |
public void propertyChange(PropertyChangeEvent event) { |
... | ... | |
381 | 272 |
} |
382 | 273 |
} |
383 | 274 |
|
384 |
/** {@inheritDoc} */ |
|
385 |
@Override |
|
386 |
public void setSelected(boolean selected) { |
|
387 |
setBackground(selected ? SELECTED : getPersistentBackground()); |
|
388 |
} |
|
389 |
|
|
390 |
/** {@inheritDoc} */ |
|
391 |
@Override |
|
392 |
public void widgetDisposed(DisposeEvent e) { |
|
393 |
PreferencesUtil.getPreferenceStore().removePropertyChangeListener(this); |
|
394 |
} |
|
395 |
|
|
396 |
// not used |
|
397 |
/** {@inheritDoc} */ |
|
398 |
@Override |
|
399 |
public void widgetDefaultSelected(SelectionEvent e) { |
|
400 |
} |
|
401 |
|
|
402 |
/** {@inheritDoc} */ |
|
403 |
@Override |
|
404 |
public void setIrrelevant(boolean irrelevant) { |
|
405 |
String colorId = irrelevant ? Resources.COLOR_COMPOSITE_IRRELEVANT |
|
406 |
: Resources.COLOR_COMPOSITE_BACKGROUND; |
|
407 |
|
|
408 |
Color color = StoreUtil.getColor(colorId); |
|
409 |
combo.setBackground(color); |
|
410 |
} |
|
411 |
|
|
412 |
/** {@inheritDoc} */ |
|
413 |
@Override |
|
414 |
public void setBackground(Color color) { |
|
415 |
if (label != null) { |
|
416 |
label.setBackground(color); |
|
417 |
} |
|
418 |
} |
|
419 |
|
|
420 |
/** |
|
421 |
* |
|
422 |
*/ |
|
423 | 275 |
protected TermManager getTermManager() { |
424 | 276 |
return CdmStore.getTermManager(); |
425 | 277 |
} |
426 | 278 |
|
427 |
/** |
|
428 |
* |
|
429 |
* @return |
|
430 |
*/ |
|
431 | 279 |
public int getVisibleItemCount(){ |
432 | 280 |
return combo.getVisibleItemCount(); |
433 | 281 |
} |
434 | 282 |
|
435 |
/** |
|
436 |
* |
|
437 |
* @param count |
|
438 |
*/ |
|
439 |
public void setVisibleItemCount(int count){ |
|
440 |
combo.setVisibleItemCount(count); |
|
441 |
} |
|
442 |
|
|
443 | 283 |
/** |
444 | 284 |
* <p>A {@link List} of term objects may be passed to this combo box. In this case, the default behaviour |
445 | 285 |
* of displaying the preferred terms for the T type will be overridden and the combo will only display the |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/combo/VocabularyComboElement.java | ||
---|---|---|
10 | 10 |
|
11 | 11 |
import org.eclipse.jface.util.PropertyChangeEvent; |
12 | 12 |
import org.eclipse.swt.SWT; |
13 |
import org.eclipse.swt.events.DisposeEvent; |
|
14 |
import org.eclipse.swt.events.DisposeListener; |
|
15 | 13 |
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 | 14 |
import org.eclipse.swt.widgets.Listener; |
21 | 15 |
|
22 | 16 |
import eu.etaxonomy.cdm.api.service.IVocabularyService; |
... | ... | |
25 | 19 |
import eu.etaxonomy.cdm.model.common.TermVocabulary; |
26 | 20 |
import eu.etaxonomy.taxeditor.model.MessagingUtils; |
27 | 21 |
import eu.etaxonomy.taxeditor.preference.PreferencesUtil; |
28 |
import eu.etaxonomy.taxeditor.preference.Resources; |
|
29 | 22 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
30 |
import eu.etaxonomy.taxeditor.store.StoreUtil; |
|
31 | 23 |
import eu.etaxonomy.taxeditor.store.TermManager; |
32 |
import eu.etaxonomy.taxeditor.ui.element.AbstractCdmFormElement; |
|
33 | 24 |
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory; |
34 | 25 |
import eu.etaxonomy.taxeditor.ui.element.CdmPropertyChangeEvent; |
35 | 26 |
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement; |
36 |
import eu.etaxonomy.taxeditor.ui.element.IEnableableFormElement; |
|
37 |
import eu.etaxonomy.taxeditor.ui.element.ISelectable; |
|
38 |
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants; |
|
39 | 27 |
|
40 | 28 |
/** |
41 |
* <p> |
|
42 |
* Abstract AbstractTermComboElement class. |
|
43 |
* </p> |
|
44 |
* |
|
45 | 29 |
* @author n.hoffmann |
46 | 30 |
* @created Nov 5, 2009 |
47 | 31 |
* @version 1.0 |
48 | 32 |
* @param <VOC> |
49 | 33 |
*/ |
50 | 34 |
public class VocabularyComboElement<TERM extends DefinedTermBase<TERM>, VOC extends TermVocabulary<TERM>> |
51 |
extends AbstractCdmFormElement implements SelectionListener, |
|
52 |
DisposeListener, IEnableableFormElement, ISelectable { |
|
53 |
|
|
54 |
private static final int DEFAULT_VISIBLE_ITEMS = 10; |
|
55 |
|
|
56 |
private VOC selection; |
|
35 |
extends AbstractComboElement<VOC> { |
|
57 | 36 |
|
58 | 37 |
private VOC emptyElement; |
59 | 38 |
private static String EMPTY_ELEMENT_LABEL = ""; |
60 | 39 |
|
61 |
protected Label label; |
|
62 |
private final Combo combo; |
|
63 |
|
|
64 | 40 |
private ArrayList<VOC> terms; |
65 | 41 |
|
66 | 42 |
private Comparator<VOC> vocComparator; |
... | ... | |
74 | 50 |
|
75 | 51 |
this.termType = termType; |
76 | 52 |
|
77 |
if (labelString != null) { |
|
78 |
label = formFactory.createLabel(getLayoutComposite(), labelString); |
|
79 |
addControl(label); |
|
80 |
} |
|
81 |
|
|
82 |
// create combo |
|
83 |
combo = new Combo(getLayoutComposite(), SWT.BORDER | SWT.READ_ONLY );//FIXME: removed this parameter seems break windows version: | style |
|
84 |
addControl(combo); |
|
85 |
combo.setLayoutData(LayoutConstants.FILL_HORIZONTALLY()); |
|
86 |
combo.setVisibleItemCount(DEFAULT_VISIBLE_ITEMS); |
|
87 |
|
|
88 | 53 |
populateTerms(getVocabularies()); |
89 | 54 |
|
90 | 55 |
combo.addSelectionListener(this); |
... | ... | |
96 | 61 |
} |
97 | 62 |
} |
98 | 63 |
|
99 |
/** |
|
100 |
* <p> |
|
101 |
* Getter for the field <code>selection</code>. |
|
102 |
* </p> |
|
103 |
* |
|
104 |
* @return a T object. |
|
105 |
*/ |
|
106 |
public VOC getSelection() { |
|
107 |
return selection; |
|
108 |
} |
|
109 |
|
|
110 | 64 |
/** |
111 | 65 |
* <p>Sets the selection of the combo to the given T object.</p> |
112 | 66 |
* <p>Passing <code>null</code> to this method will set the selection to |
... | ... | |
115 | 69 |
* @param selection |
116 | 70 |
* a T object or <code>null</code> to clear the selection |
117 | 71 |
*/ |
118 |
public void setSelection(VOC selection) { |
|
72 |
@Override |
|
73 |
public void setSelection(VOC selection) { |
|
119 | 74 |
this.selection = selection; |
120 | 75 |
|
121 | 76 |
this.selection = selection; |
... | ... | |
200 | 155 |
combo.select(index); |
201 | 156 |
} |
202 | 157 |
|
203 |
/* |
|
204 |
* (non-Javadoc) |
|
205 |
* @see eu.etaxonomy.taxeditor.forms.IEnableableFormElement#setEnabled(boolean) |
|
206 |
*/ |
|
207 |
/** {@inheritDoc} */ |
|
208 |
@Override |
|
209 |
public void setEnabled(boolean enabled) { |
|
210 |
combo.setEnabled(enabled); |
|
211 |
} |
|
212 |
|
|
213 |
/* (non-Javadoc) |
|
214 |
* @see eu.etaxonomy.taxeditor.ui.element.IEnableableFormElement#isEnabled() |
|
215 |
*/ |
|
216 |
@Override |
|
217 |
public boolean isEnabled() { |
|
218 |
return combo.isEnabled(); |
|
219 |
} |
|
220 |
|
|
221 |
/** |
|
222 |
* <p> |
|
223 |
* preferredTerms |
|
224 |
* </p> |
|
225 |
* |
|
226 |
* @return a {@link java.util.List} object. |
|
227 |
*/ |
|
228 | 158 |
protected List<VOC> getVocabularies(){ |
229 | 159 |
List<TermVocabulary<TERM>> list = CdmStore.getService(IVocabularyService.class).<TERM>findByTermType(termType); |
230 | 160 |
return (List<VOC>) list; |
... | ... | |
246 | 176 |
} |
247 | 177 |
} |
248 | 178 |
|
249 |
/** |
|
250 |
* |
|
251 |
* |
|
252 |
* @param term |
|
253 |
*/ |
|
254 | 179 |
private void createTermNotInPreferredTerms(VOC term) { |
255 | 180 |
List<VOC> preferredTerms = getVocabularies(); |
256 | 181 |
|
... | ... | |
259 | 184 |
populateTerms(preferredTerms); |
260 | 185 |
} |
261 | 186 |
|
262 |
/** |
|
263 |
* <p> |
|
264 |
* addSelectionListener |
|
265 |
* </p> |
|
266 |
* |
|
267 |
* @param listener |
|
268 |
* a {@link org.eclipse.swt.events.SelectionListener} object. |
|
269 |
*/ |
|
270 |
public void addSelectionListener(SelectionListener listener) { |
|
271 |
combo.addSelectionListener(listener); |
|
272 |
} |
|
273 |
|
|
274 |
/** |
|
275 |
* <p> |
|
276 |
* removeSelectionListener |
|
277 |
* </p> |
|
278 |
* |
|
279 |
* @param listener |
|
280 |
* a {@link org.eclipse.swt.events.SelectionListener} object. |
|
281 |
*/ |
|
282 |
public void removeSelectionListener(SelectionListener listener) { |
|
283 |
combo.removeSelectionListener(listener); |
|
284 |
} |
|
285 |
|
|
286 |
/* |
|
287 |
* (non-Javadoc) |
|
288 |
* |
|
289 |
* @see |
|
290 |
* org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt |
|
291 |
* .events.SelectionEvent) |
|
292 |
*/ |
|
293 | 187 |
/** {@inheritDoc} */ |
294 | 188 |
@Override |
295 | 189 |
public void widgetSelected(SelectionEvent e) { |
... | ... | |
297 | 191 |
firePropertyChangeEvent(new CdmPropertyChangeEvent(this, e)); |
298 | 192 |
} |
299 | 193 |
|
300 |
/* |
|
301 |
* (non-Javadoc) |
|
302 |
* |
|
303 |
* @see java.beans.PropertyChangeListener#propertyChange(java.beans. |
|
304 |
* PropertyChangeEvent) |
|
305 |
*/ |
|
306 | 194 |
/** {@inheritDoc} */ |
307 | 195 |
@Override |
308 | 196 |
public void propertyChange(PropertyChangeEvent event) { |
... | ... | |
314 | 202 |
} |
315 | 203 |
} |
316 | 204 |
|
317 |
/** {@inheritDoc} */ |
|
318 |
@Override |
|
319 |
public void setSelected(boolean selected) { |
|
320 |
setBackground(selected ? SELECTED : getPersistentBackground()); |
|
321 |
} |
|
322 |
|
|
323 |
/** {@inheritDoc} */ |
|
324 |
@Override |
|
325 |
public void widgetDisposed(DisposeEvent e) { |
|
326 |
PreferencesUtil.getPreferenceStore().removePropertyChangeListener(this); |
|
327 |
} |
|
328 |
|
|
329 |
// not used |
|
330 |
/** {@inheritDoc} */ |
|
331 |
@Override |
|
332 |
public void widgetDefaultSelected(SelectionEvent e) { |
|
333 |
} |
|
334 |
|
|
335 |
/** {@inheritDoc} */ |
|
336 |
@Override |
|
337 |
public void setIrrelevant(boolean irrelevant) { |
|
338 |
String colorId = irrelevant ? Resources.COLOR_COMPOSITE_IRRELEVANT |
|
339 |
: Resources.COLOR_COMPOSITE_BACKGROUND; |
|
340 |
|
|
341 |
Color color = StoreUtil.getColor(colorId); |
|
342 |
combo.setBackground(color); |
|
343 |
} |
|
344 |
|
|
345 |
/** {@inheritDoc} */ |
|
346 |
@Override |
|
347 |
public void setBackground(Color color) { |
|
348 |
if (label != null) { |
|
349 |
label.setBackground(color); |
|
350 |
} |
|
351 |
} |
|
352 |
|
|
353 |
/** |
|
354 |
* |
|
355 |
*/ |
|
356 | 205 |
protected TermManager getTermManager() { |
357 | 206 |
return CdmStore.getTermManager(); |
358 | 207 |
} |
359 | 208 |
|
360 |
/** |
|
361 |
* |
|
362 |
* @return |
|
363 |
*/ |
|
364 | 209 |
public int getVisibleItemCount(){ |
365 | 210 |
return combo.getVisibleItemCount(); |
366 | 211 |
} |
367 | 212 |
|
368 |
/** |
|
369 |
* |
|
370 |
* @param count |
|
371 |
*/ |
|
372 |
public void setVisibleItemCount(int count){ |
|
373 |
combo.setVisibleItemCount(count); |
|
374 |
} |
|
375 |
|
|
376 | 213 |
public void removeEmptyElement(){ |
377 | 214 |
terms.remove(emptyElement); |
378 | 215 |
combo.remove(EMPTY_ELEMENT_LABEL); |
Also available in: Unified diff
ref #5305 Refactored combo elements