Project

General

Profile

Download (4.85 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2019 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.section.name.type;
10

    
11
import java.util.Collection;
12

    
13
import org.eclipse.jface.viewers.ArrayContentProvider;
14
import org.eclipse.jface.viewers.ISelectionChangedListener;
15
import org.eclipse.jface.viewers.LabelProvider;
16
import org.eclipse.jface.viewers.SelectionChangedEvent;
17
import org.eclipse.jface.viewers.StructuredSelection;
18
import org.eclipse.jface.wizard.WizardPage;
19
import org.eclipse.swt.SWT;
20
import org.eclipse.swt.events.ModifyEvent;
21
import org.eclipse.swt.events.ModifyListener;
22
import org.eclipse.swt.events.SelectionAdapter;
23
import org.eclipse.swt.events.SelectionEvent;
24
import org.eclipse.swt.widgets.Composite;
25

    
26
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
27
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignationStatus;
28
import eu.etaxonomy.taxeditor.ui.dialog.selection.CollectionSelectionDialog;
29

    
30
/**
31
 * @author pplitzner
32
 * @since Mar 13, 2019
33
 *
34
 */
35
public class CloneTypeWizardPage extends WizardPage implements ISelectionChangedListener, ModifyListener {
36

    
37
    private CloneTypeWizardComposite composite;
38

    
39
    private eu.etaxonomy.cdm.model.occurrence.Collection selectedCollection = null;
40
    private SpecimenTypeDesignation baseDesignation = null;
41

    
42
    private final Collection<SpecimenTypeDesignation> typeDesignations;
43

    
44
    protected CloneTypeWizardPage(Collection<SpecimenTypeDesignation> typeDesignations) {
45
        super("Duplicate Type");
46
        setTitle("Duplicate Type");
47
        setDescription("Create a type duplicate based on an existing type specimen.");
48
        this.typeDesignations = typeDesignations;
49
    }
50

    
51
    @Override
52
    public void createControl(Composite parent) {
53

    
54
        composite = new CloneTypeWizardComposite(parent, SWT.NONE);
55

    
56
        // fill combo with available types
57
        composite.getComboViewerBaseType().setContentProvider(new ArrayContentProvider());
58
        composite.getComboViewerBaseType().setLabelProvider(new LabelProvider(){
59
            @Override
60
            public String getText(Object element) {
61
                if(element instanceof SpecimenTypeDesignation){
62
                    return ((SpecimenTypeDesignation) element).getTypeSpecimen().getTitleCache();
63
                }
64
                return super.getText(element);
65
            }
66
        });
67
        composite.getComboViewerBaseType().setInput(typeDesignations);
68
        if(typeDesignations.size()==1){
69
            SpecimenTypeDesignation next = typeDesignations.iterator().next();
70
            baseDesignation = next;
71
            composite.getComboViewerBaseType().setSelection(new StructuredSelection(next));
72
        }
73
        composite.getComboViewerBaseType().addSelectionChangedListener(e->{
74
            baseDesignation = (SpecimenTypeDesignation) ((StructuredSelection) e.getSelection()).getFirstElement();
75
            getWizard().getContainer().updateButtons();
76
        });
77

    
78
        composite.getBtnBrowseCollection().addSelectionListener(new SelectionAdapter() {
79
            @Override
80
            public void widgetSelected(SelectionEvent e) {
81
                selectedCollection = CollectionSelectionDialog.select(getShell(), selectedCollection);
82
                composite.getTxtCollection().setText(selectedCollection.getTitleCache());
83
                getWizard().getContainer().updateButtons();
84
            }
85
        });
86

    
87
        // add listeners for update buttons
88
        composite.getTxtAccNumber().addModifyListener(this);
89
        composite.getComboTypeStatus().addSelectionChangedListener(this);
90

    
91
        setControl(composite);
92
    }
93

    
94
    @Override
95
    public boolean isPageComplete() {
96
        return composite.getComboViewerBaseType().getSelection()!=null
97
                && selectedCollection!=null
98
                && composite.getComboTypeStatus().getSelection()!=null;
99
    }
100

    
101
    @Override
102
    public void selectionChanged(SelectionChangedEvent event) {
103
        getWizard().getContainer().updateButtons();
104
    }
105

    
106
    @Override
107
    public void modifyText(ModifyEvent e) {
108
        getWizard().getContainer().updateButtons();
109

    
110
    }
111

    
112
    public SpecimenTypeDesignation getBaseTypeDesignation() {
113
        return baseDesignation;
114
    }
115

    
116
    public String getAccessionNumber() {
117
        return composite.getTxtAccNumber().getText();
118
    }
119

    
120
    public String getBarcode() {
121
        return composite.getTextBarcode().getText();
122
    }
123

    
124
    public String getCatalogNumber() {
125
        return composite.getTextCatalogNumber().getText();
126
    }
127

    
128
    public eu.etaxonomy.cdm.model.occurrence.Collection getCollection() {
129
        return selectedCollection;
130
    }
131

    
132
    public SpecimenTypeDesignationStatus getTypeStatus() {
133
        return (SpecimenTypeDesignationStatus) composite.getComboTypeStatus().getSelection();
134
    }
135

    
136
}
(3-3/3)