Project

General

Profile

« Previous | Next » 

Revision 09b45523

Added by Patrick Plitzner about 6 years ago

ref #7095 Add taxon filter combo to specimen selection dialog

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/matrix/SpecimenSelectionDialog.java
30 30
import org.eclipse.swt.widgets.Control;
31 31
import org.eclipse.swt.widgets.Shell;
32 32
import org.eclipse.swt.widgets.Table;
33
import org.eclipse.swt.widgets.Text;
33 34

  
34 35
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
35 36
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
......
40 41
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
41 42
import eu.etaxonomy.taxeditor.model.ImageResources;
42 43
import eu.etaxonomy.taxeditor.store.CdmStore;
44
import eu.etaxonomy.taxeditor.ui.combo.taxon.TaxonNodeCombo;
43 45

  
44 46
/**
45 47
 * Dialog to choose specimens for the character matrix.<br>
......
54 56

  
55 57
    private Collection<SpecimenOrObservationBase> selectedSpecimens = new ArrayList<>();
56 58
    private CharacterMatrix matrix;
59
    private Text txtTextFilter;
60

  
61
    private TaxonNodeCombo comboTaxon;
57 62

  
58 63
    protected SpecimenSelectionDialog(Shell parentShell, CharacterMatrix matrix) {
59 64
        super(parentShell);
......
63 68
    @Override
64 69
    protected Control createDialogArea(Composite parent) {
65 70
        Composite composite = (Composite) super.createDialogArea(parent);
66
        composite.setLayout(new GridLayout());
71
        GridLayout gl_composite = new GridLayout();
72
        composite.setLayout(gl_composite);
67 73

  
68
        Button btnRefreshButton = new Button(composite, SWT.NONE);
69
        btnRefreshButton.setToolTipText(Messages.SpecimenSelectionDialog_REFRESH);
74
        Composite composite_1 = new Composite(composite, SWT.NONE);
75
        composite_1.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));
76
        composite_1.setLayout(new GridLayout(3, false));
77

  
78
        txtTextFilter = new Text(composite_1, SWT.BORDER);
79
        txtTextFilter.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
80

  
81
        comboTaxon = new TaxonNodeCombo(composite_1, SWT.NONE);
82
        comboTaxon.setInput(matrix.getWorkingSet().getTaxonSubtreeFilter());
83

  
84
        Button btnRefreshButton = new Button(composite_1, SWT.NONE);
70 85
        btnRefreshButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
86
        btnRefreshButton.setToolTipText(Messages.SpecimenSelectionDialog_REFRESH);
71 87
        btnRefreshButton.setImage(ImageResources.getImage(ImageResources.REFRESH));
72 88
        btnRefreshButton.addSelectionListener(new SelectionAdapter() {
73 89
            @Override
eu.etaxonomy.taxeditor.store/META-INF/MANIFEST.MF
40 40
 eu.etaxonomy.taxeditor.ui,
41 41
 eu.etaxonomy.taxeditor.ui.bar,
42 42
 eu.etaxonomy.taxeditor.ui.combo,
43
 eu.etaxonomy.taxeditor.ui.combo.taxon,
43 44
 eu.etaxonomy.taxeditor.ui.dialog,
44 45
 eu.etaxonomy.taxeditor.ui.dialog.configurator,
45 46
 eu.etaxonomy.taxeditor.ui.dialog.configurator.deleteConfigurator,
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/combo/taxon/TaxonNodeCombo.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.taxon;
10

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

  
19
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
20

  
21
/**
22
 *
23
 * @author pplitzner
24
 * @since Apr 10, 2018
25
 *
26
 */
27
public class TaxonNodeCombo extends Composite{
28

  
29
    private ComboViewer viewer;
30

  
31
    public TaxonNodeCombo(Composite parent, int style){
32
        super(parent, style);
33
        setLayout(new FillLayout());
34
        viewer = new ComboViewer(new CCombo(this, SWT.READ_ONLY | SWT.SINGLE));
35
        viewer.setContentProvider(new TaxonNodeComboContentProvider());
36
        viewer.setLabelProvider(new TaxonNodeComboLabelProvider());
37
    }
38

  
39
    public void setInput(Object input){
40
        viewer.setInput(input);
41
    }
42

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

  
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);
58
    }
59

  
60
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/combo/taxon/TaxonNodeComboContentProvider.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.taxon;
10

  
11
import java.util.ArrayList;
12
import java.util.Collection;
13
import java.util.List;
14

  
15
import org.eclipse.jface.viewers.IStructuredContentProvider;
16

  
17
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
18
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
19
import eu.etaxonomy.taxeditor.store.CdmStore;
20

  
21
/**
22
 * @author pplitzner
23
 * @since Nov 24, 2017
24
 *
25
 */
26
public class TaxonNodeComboContentProvider implements IStructuredContentProvider {
27

  
28
    @Override
29
    public Object[] getElements(Object inputElement) {
30
        Collection<TaxonNode> nodes = (Collection<TaxonNode>)inputElement;
31
        List<TaxonNode> allNodes = new ArrayList<>();
32
        nodes.forEach(node->{
33
            allNodes.add(node);
34
            allNodes.addAll(CdmStore.getService(ITaxonNodeService.class).loadChildNodesOfTaxonNode(node, null, true, null));
35
        });
36
        return allNodes.toArray();
37
    }
38

  
39
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/combo/taxon/TaxonNodeComboLabelProvider.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.taxon;
10

  
11
import org.eclipse.jface.viewers.LabelProvider;
12

  
13
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
14

  
15
/**
16
 * @author pplitzner
17
 * @since Nov 24, 2017
18
 *
19
 */
20
public class TaxonNodeComboLabelProvider extends LabelProvider {
21

  
22
    /**
23
     * {@inheritDoc}
24
     */
25
    @Override
26
    public String getText(Object element) {
27
        if(element instanceof TaxonNode){
28
            return ((TaxonNode) element).getTaxon().getTitleCache();
29
        }
30
        return super.getText(element);
31
    }
32

  
33
}

Also available in: Unified diff