2 * Copyright (C) 2017 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
.jface
.viewers
.ILabelProvider
;
13 import org
.eclipse
.jface
.viewers
.ISelectionChangedListener
;
14 import org
.eclipse
.jface
.viewers
.IStructuredContentProvider
;
15 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
16 import org
.eclipse
.swt
.SWT
;
17 import org
.eclipse
.swt
.custom
.CCombo
;
18 import org
.eclipse
.swt
.layout
.FillLayout
;
19 import org
.eclipse
.swt
.widgets
.Composite
;
23 * Abstract generic combo.
28 * @param <T> the type of the elements to show in the combo
30 public abstract class AbstractComboComposite
<T
> extends Composite
{
32 private ComboViewer viewer
;
34 public AbstractComboComposite(Composite parent
, int style
){
36 setLayout(new FillLayout());
37 viewer
= new ComboViewer(new CCombo(this, SWT
.READ_ONLY
| SWT
.SINGLE
));
38 viewer
.setContentProvider(getContentProvider());
39 viewer
.setLabelProvider(getLabelProvider());
42 public void setInput(Object input
){
43 viewer
.setInput(input
);
46 public T
getSelection(){
47 IStructuredSelection structuredSelection
= viewer
.getStructuredSelection();
48 if(structuredSelection
!=null && !structuredSelection
.isEmpty()){
49 return (T
) structuredSelection
.getFirstElement();
54 public void setElement(T element
){
55 int index
= viewer
.getCCombo().indexOf(getElementLabel(element
));
56 viewer
.getCCombo().select(index
);
60 public void addSelectionChangedListener(ISelectionChangedListener listener
){
61 viewer
.addSelectionChangedListener(listener
);
64 public abstract String
getElementLabel(T element
);
65 public abstract IStructuredContentProvider
getContentProvider();
66 public abstract ILabelProvider
getLabelProvider();