Project

General

Profile

Revision 5cea1626

ID5cea1626b6bc40da66449cb443c92fdc5f67068e
Parent 09b45523
Child 2ccbcf35

Added by Patrick Plitzner over 2 years ago

ref #7095 Implement generic abstract combo class

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/WorkingSetComposite.java
127 127
    }
128 128

  
129 129
    public void setRankMin(Rank min) {
130
        comboRankMin.setTerm(min);
130
        comboRankMin.setElement(min);
131 131
    }
132 132
    public void setRankMax(Rank max) {
133
        comboRankMax.setTerm(max);
133
        comboRankMax.setElement(max);
134 134
    }
135 135

  
136 136
    public FeatureTreeEditorComposite getFeatureTreeEditorComposite() {
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/combo/AbstractComboComposite.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.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;
20

  
21
/**
22
 *
23
 * Abstract generic combo.
24
 *
25
 * @author pplitzner
26
 * @since Apr 10, 2018
27
 *
28
 * @param <T> the type of the elements to show in the combo
29
 */
30
public abstract class AbstractComboComposite<T> extends Composite{
31

  
32
    private ComboViewer viewer;
33

  
34
    public AbstractComboComposite(Composite parent, int style){
35
        super(parent, 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());
40
    }
41

  
42
    public void setInput(Object input){
43
        viewer.setInput(input);
44
    }
45

  
46
    public T getSelection(){
47
        IStructuredSelection structuredSelection = viewer.getStructuredSelection();
48
        if(structuredSelection!=null && !structuredSelection.isEmpty()){
49
            return (T) structuredSelection.getFirstElement();
50
        }
51
        return null;
52
    }
53

  
54
    public void setElement(T element){
55
        int index = viewer.getCCombo().indexOf(getElementLabel(element));
56
        viewer.getCCombo().select(index);
57
    }
58

  
59

  
60
    public void addSelectionChangedListener(ISelectionChangedListener listener){
61
        viewer.addSelectionChangedListener(listener);
62
    }
63

  
64
    public abstract String getElementLabel(T element);
65
    public abstract IStructuredContentProvider getContentProvider();
66
    public abstract ILabelProvider getLabelProvider();
67

  
68
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/combo/TermUuidComboViewer.java
9 9
package eu.etaxonomy.taxeditor.ui.combo;
10 10

  
11 11
import org.eclipse.jface.viewers.ComboViewer;
12
import org.eclipse.jface.viewers.ISelectionChangedListener;
13
import org.eclipse.jface.viewers.IStructuredSelection;
12
import org.eclipse.jface.viewers.ILabelProvider;
13
import org.eclipse.jface.viewers.IStructuredContentProvider;
14 14
import org.eclipse.swt.SWT;
15 15
import org.eclipse.swt.custom.CCombo;
16 16
import org.eclipse.swt.layout.FillLayout;
......
23 23
 * @since Nov 24, 2017
24 24
 *
25 25
 */
26
public class TermUuidComboViewer extends Composite{
26
public class TermUuidComboViewer extends AbstractComboComposite<DefinedTermBase>{
27 27

  
28 28
    private ComboViewer viewer;
29 29

  
......
35 35
        viewer.setLabelProvider(new TermUuidLabelProvider());
36 36
    }
37 37

  
38
    public void setInput(Object input){
39
        viewer.setInput(input);
38
    @Override
39
    public String getElementLabel(DefinedTermBase element) {
40
        return element.getLabel();
40 41
    }
41 42

  
42
    public DefinedTermBase getSelection(){
43
        IStructuredSelection structuredSelection = viewer.getStructuredSelection();
44
        if(structuredSelection!=null && !structuredSelection.isEmpty()){
45
            return (DefinedTermBase) structuredSelection.getFirstElement();
46
        }
47
        return null;
43
    @Override
44
    public IStructuredContentProvider getContentProvider() {
45
        return new TermUuidContentProvider();
48 46
    }
49 47

  
50
    public void setTerm(DefinedTermBase term){
51
        int index = viewer.getCCombo().indexOf(term.getLabel());
52
        viewer.getCCombo().select(index);
53
    }
54

  
55
    public void addSelectionChangedListener(ISelectionChangedListener listener){
56
        viewer.addSelectionChangedListener(listener);
48
    @Override
49
    public ILabelProvider getLabelProvider() {
50
        return new TermUuidLabelProvider();
57 51
    }
58 52

  
59 53
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/combo/taxon/TaxonNodeCombo.java
9 9
package eu.etaxonomy.taxeditor.ui.combo.taxon;
10 10

  
11 11
import org.eclipse.jface.viewers.ComboViewer;
12
import org.eclipse.jface.viewers.ISelectionChangedListener;
13
import org.eclipse.jface.viewers.IStructuredSelection;
12
import org.eclipse.jface.viewers.ILabelProvider;
13
import org.eclipse.jface.viewers.IStructuredContentProvider;
14 14
import org.eclipse.swt.SWT;
15 15
import org.eclipse.swt.custom.CCombo;
16 16
import org.eclipse.swt.layout.FillLayout;
17 17
import org.eclipse.swt.widgets.Composite;
18 18

  
19 19
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
20
import eu.etaxonomy.taxeditor.ui.combo.AbstractComboComposite;
20 21

  
21 22
/**
22 23
 *
......
24 25
 * @since Apr 10, 2018
25 26
 *
26 27
 */
27
public class TaxonNodeCombo extends Composite{
28
public class TaxonNodeCombo extends AbstractComboComposite<TaxonNode>{
28 29

  
29 30
    private ComboViewer viewer;
30 31

  
......
36 37
        viewer.setLabelProvider(new TaxonNodeComboLabelProvider());
37 38
    }
38 39

  
39
    public void setInput(Object input){
40
        viewer.setInput(input);
40
    @Override
41
    public String getElementLabel(TaxonNode element) {
42
        return element.getTaxon().getTitleCache();
41 43
    }
42 44

  
43
    public TaxonNode getSelection(){
44
        IStructuredSelection structuredSelection = viewer.getStructuredSelection();
45
        if(structuredSelection!=null && !structuredSelection.isEmpty()){
46
            return (TaxonNode) structuredSelection.getFirstElement();
47
        }
48
        return null;
45
    @Override
46
    public IStructuredContentProvider getContentProvider() {
47
        return new TaxonNodeComboContentProvider();
49 48
    }
50 49

  
51
    public void setElement(TaxonNode element){
52
        int index = viewer.getCCombo().indexOf(element.getTaxon().getTitleCache());
53
        viewer.getCCombo().select(index);
54
    }
55

  
56
    public void addSelectionChangedListener(ISelectionChangedListener listener){
57
        viewer.addSelectionChangedListener(listener);
50
    @Override
51
    public ILabelProvider getLabelProvider() {
52
        return new TaxonNodeComboLabelProvider();
58 53
    }
59 54

  
60 55
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)