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.common.CdmUtils;
|
27
|
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
|
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
|
|
41
|
private final Collection<SpecimenTypeDesignation> typeDesignations;
|
42
|
|
43
|
protected CloneTypeWizardPage(Collection<SpecimenTypeDesignation> typeDesignations) {
|
44
|
super("Duplicate Type");
|
45
|
setTitle("Duplicate Type");
|
46
|
setDescription("Create a type duplicate based on an existing type specimen.");
|
47
|
this.typeDesignations = typeDesignations;
|
48
|
}
|
49
|
|
50
|
@Override
|
51
|
public void createControl(Composite parent) {
|
52
|
|
53
|
composite = new CloneTypeWizardComposite(parent, SWT.NONE);
|
54
|
|
55
|
// fill combo with available types
|
56
|
composite.getComboViewerBaseType().setContentProvider(new ArrayContentProvider());
|
57
|
composite.getComboViewerBaseType().setLabelProvider(new LabelProvider(){
|
58
|
@Override
|
59
|
public String getText(Object element) {
|
60
|
if(element instanceof SpecimenTypeDesignation){
|
61
|
return ((SpecimenTypeDesignation) element).getTypeSpecimen().getTitleCache();
|
62
|
}
|
63
|
return super.getText(element);
|
64
|
}
|
65
|
});
|
66
|
composite.getComboViewerBaseType().setInput(typeDesignations);
|
67
|
if(typeDesignations.size()==1){
|
68
|
composite.getComboViewerBaseType().setSelection(new StructuredSelection(typeDesignations.iterator().next()));
|
69
|
}
|
70
|
|
71
|
composite.getBtnBrowseCollection().addSelectionListener(new SelectionAdapter() {
|
72
|
@Override
|
73
|
public void widgetSelected(SelectionEvent e) {
|
74
|
selectedCollection = CollectionSelectionDialog.select(getShell(), selectedCollection);
|
75
|
composite.getTxtCollection().setText(selectedCollection.getTitleCache());
|
76
|
getWizard().getContainer().updateButtons();
|
77
|
}
|
78
|
});
|
79
|
|
80
|
// add listeners for update buttons
|
81
|
composite.getComboViewerBaseType().addSelectionChangedListener(this);
|
82
|
composite.getTxtAccNumber().addModifyListener(this);
|
83
|
composite.getComboTypeStatus().addSelectionChangedListener(this);
|
84
|
|
85
|
setControl(composite);
|
86
|
}
|
87
|
|
88
|
@Override
|
89
|
public boolean isPageComplete() {
|
90
|
return composite.getComboViewerBaseType().getSelection()!=null
|
91
|
&& CdmUtils.isNotBlank(composite.getTxtAccNumber().getText())
|
92
|
&& selectedCollection!=null
|
93
|
&& composite.getComboTypeStatus().getSelection()!=null;
|
94
|
}
|
95
|
|
96
|
@Override
|
97
|
public void selectionChanged(SelectionChangedEvent event) {
|
98
|
getWizard().getContainer().updateButtons();
|
99
|
}
|
100
|
|
101
|
@Override
|
102
|
public void modifyText(ModifyEvent e) {
|
103
|
getWizard().getContainer().updateButtons();
|
104
|
|
105
|
}
|
106
|
|
107
|
}
|