Revision 49aad4b2
Added by Patrick Plitzner over 6 years ago
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/WorkingSetComposite.java | ||
---|---|---|
9 | 9 |
package eu.etaxonomy.taxeditor.editor.workingSet; |
10 | 10 |
|
11 | 11 |
import org.eclipse.jface.viewers.ComboViewer; |
12 |
import org.eclipse.jface.viewers.LabelProvider; |
|
13 | 12 |
import org.eclipse.jface.viewers.TreeViewer; |
14 | 13 |
import org.eclipse.swt.SWT; |
15 |
import org.eclipse.swt.graphics.Image; |
|
16 | 14 |
import org.eclipse.swt.layout.FillLayout; |
17 | 15 |
import org.eclipse.swt.layout.GridData; |
18 | 16 |
import org.eclipse.swt.layout.GridLayout; |
... | ... | |
22 | 20 |
import org.eclipse.swt.widgets.Text; |
23 | 21 |
import org.eclipse.swt.widgets.Tree; |
24 | 22 |
|
23 |
import eu.etaxonomy.cdm.model.common.TermType; |
|
24 |
import eu.etaxonomy.taxeditor.ui.combo.TermUuidComboViewer; |
|
25 |
|
|
25 | 26 |
/** |
26 | 27 |
* @author pplitzner |
27 | 28 |
* @since Nov 21, 2017 |
28 | 29 |
* |
29 | 30 |
*/ |
30 | 31 |
public class WorkingSetComposite extends Composite { |
31 |
private static class ViewerLabelProvider extends LabelProvider { |
|
32 |
@Override |
|
33 |
public Image getImage(Object element) { |
|
34 |
return super.getImage(element); |
|
35 |
} |
|
36 |
@Override |
|
37 |
public String getText(Object element) { |
|
38 |
return super.getText(element); |
|
39 |
} |
|
40 |
} |
|
41 | 32 |
private Text txt_label; |
42 | 33 |
|
43 |
/** |
|
44 |
* Create the composite. |
|
45 |
* @param parent |
|
46 |
* @param style |
|
47 |
*/ |
|
48 | 34 |
public WorkingSetComposite(Composite parent, int style) { |
49 | 35 |
super(parent, style); |
50 | 36 |
setLayout(new GridLayout(3, false)); |
... | ... | |
62 | 48 |
lblNewLabel_2.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); |
63 | 49 |
lblNewLabel_2.setText("Rank min"); |
64 | 50 |
|
65 |
Combo combo = new Combo(this, SWT.NONE); |
|
66 |
combo.setItems(new String[] {"Genus", "Species", "Subspecies"}); |
|
51 |
TermUuidComboViewer combo = new TermUuidComboViewer(this, SWT.NONE); |
|
52 |
combo.setInput(TermType.Rank); |
|
53 |
// Combo combo = new Combo(this, SWT.NONE); |
|
54 |
// combo.setItems(new String[] {"Genus", "Species", "Subspecies"}); |
|
67 | 55 |
combo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1)); |
68 | 56 |
|
69 | 57 |
Composite composite = new Composite(this, SWT.NONE); |
... | ... | |
77 | 65 |
lblNewLabel_3.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); |
78 | 66 |
lblNewLabel_3.setText("Rank max"); |
79 | 67 |
|
80 |
Combo combo_1 = new Combo(this, SWT.NONE); |
|
81 |
combo_1.setItems(new String[] {"Genus", "Species", "Subspecies"}); |
|
68 |
// Combo combo_1 = new Combo(this, SWT.NONE); |
|
69 |
TermUuidComboViewer combo_1 = new TermUuidComboViewer(this, SWT.NONE); |
|
70 |
// combo_1.setItems(new String[] {"Genus", "Species", "Subspecies"}); |
|
82 | 71 |
combo_1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1)); |
83 | 72 |
|
84 | 73 |
Label lblNewLabel_4 = new Label(this, SWT.NONE); |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/combo/TermUuidComboViewer.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2017 EDIT |
|
3 |
* European Distributed Institute of Taxonomy |
|
4 |
* http://www.e-taxonomy.eu |
|
5 |
* |
|
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. |
|
8 |
*/ |
|
9 |
package eu.etaxonomy.taxeditor.ui.combo; |
|
10 |
|
|
11 |
import org.eclipse.jface.viewers.ComboViewer; |
|
12 |
import org.eclipse.jface.viewers.IStructuredSelection; |
|
13 |
import org.eclipse.swt.SWT; |
|
14 |
import org.eclipse.swt.custom.CCombo; |
|
15 |
import org.eclipse.swt.layout.FillLayout; |
|
16 |
import org.eclipse.swt.widgets.Composite; |
|
17 |
|
|
18 |
import eu.etaxonomy.cdm.model.common.DefinedTerm; |
|
19 |
|
|
20 |
/** |
|
21 |
* @author pplitzner |
|
22 |
* @since Nov 24, 2017 |
|
23 |
* |
|
24 |
*/ |
|
25 |
public class TermUuidComboViewer extends Composite{ |
|
26 |
|
|
27 |
private ComboViewer viewer; |
|
28 |
|
|
29 |
public TermUuidComboViewer(Composite parent, int style){ |
|
30 |
super(parent, style); |
|
31 |
setLayout(new FillLayout()); |
|
32 |
viewer = new ComboViewer(new CCombo(this, SWT.READ_ONLY | SWT.SINGLE)); |
|
33 |
viewer.setContentProvider(new TermUuidContentProvider()); |
|
34 |
viewer.setLabelProvider(new TermUuidLabelProvider()); |
|
35 |
} |
|
36 |
|
|
37 |
public void setInput(Object input){ |
|
38 |
viewer.setInput(input); |
|
39 |
} |
|
40 |
|
|
41 |
public DefinedTerm getSelection(){ |
|
42 |
IStructuredSelection structuredSelection = viewer.getStructuredSelection(); |
|
43 |
if(structuredSelection!=null && !structuredSelection.isEmpty()){ |
|
44 |
return (DefinedTerm) structuredSelection.getFirstElement(); |
|
45 |
} |
|
46 |
return null; |
|
47 |
} |
|
48 |
|
|
49 |
} |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/combo/TermUuidContentProvider.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2017 EDIT |
|
3 |
* European Distributed Institute of Taxonomy |
|
4 |
* http://www.e-taxonomy.eu |
|
5 |
* |
|
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. |
|
8 |
*/ |
|
9 |
package eu.etaxonomy.taxeditor.ui.combo; |
|
10 |
|
|
11 |
import java.util.List; |
|
12 |
|
|
13 |
import org.eclipse.jface.viewers.IStructuredContentProvider; |
|
14 |
|
|
15 |
import eu.etaxonomy.cdm.api.service.ITermService; |
|
16 |
import eu.etaxonomy.cdm.model.common.DefinedTermBase; |
|
17 |
import eu.etaxonomy.cdm.model.common.TermType; |
|
18 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
|
19 |
|
|
20 |
/** |
|
21 |
* @author pplitzner |
|
22 |
* @since Nov 24, 2017 |
|
23 |
* |
|
24 |
*/ |
|
25 |
public class TermUuidContentProvider implements IStructuredContentProvider { |
|
26 |
|
|
27 |
@Override |
|
28 |
public Object[] getElements(Object inputElement) { |
|
29 |
if(inputElement instanceof TermType){ |
|
30 |
List<DefinedTermBase> terms = CdmStore.getService(ITermService.class).listByTermType((TermType) inputElement, null, null, null, null); |
|
31 |
return terms.toArray(); |
|
32 |
} |
|
33 |
return null; |
|
34 |
} |
|
35 |
|
|
36 |
} |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/combo/TermUuidLabelProvider.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2017 EDIT |
|
3 |
* European Distributed Institute of Taxonomy |
|
4 |
* http://www.e-taxonomy.eu |
|
5 |
* |
|
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. |
|
8 |
*/ |
|
9 |
package eu.etaxonomy.taxeditor.ui.combo; |
|
10 |
|
|
11 |
import org.eclipse.jface.viewers.LabelProvider; |
|
12 |
|
|
13 |
import eu.etaxonomy.cdm.model.common.DefinedTerm; |
|
14 |
|
|
15 |
/** |
|
16 |
* @author pplitzner |
|
17 |
* @since Nov 24, 2017 |
|
18 |
* |
|
19 |
*/ |
|
20 |
public class TermUuidLabelProvider extends LabelProvider { |
|
21 |
|
|
22 |
/** |
|
23 |
* {@inheritDoc} |
|
24 |
*/ |
|
25 |
@Override |
|
26 |
public String getText(Object element) { |
|
27 |
if(element instanceof DefinedTerm){ |
|
28 |
return ((DefinedTerm) element).getLabel(); |
|
29 |
} |
|
30 |
return super.getText(element); |
|
31 |
} |
|
32 |
|
|
33 |
} |
Also available in: Unified diff
ref #7086 Add term combo viewer to working set editor