1
|
/**
|
2
|
* Copyright (C) 2009 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
|
|
10
|
package eu.etaxonomy.taxeditor.propertysheet.type.wizard;
|
11
|
|
12
|
import org.apache.log4j.Logger;
|
13
|
import org.eclipse.core.databinding.beans.BeansObservables;
|
14
|
import org.eclipse.core.databinding.observable.list.WritableList;
|
15
|
import org.eclipse.core.databinding.observable.map.IObservableMap;
|
16
|
import org.eclipse.jface.databinding.viewers.ObservableListContentProvider;
|
17
|
import org.eclipse.jface.databinding.viewers.ObservableMapLabelProvider;
|
18
|
import org.eclipse.jface.viewers.DoubleClickEvent;
|
19
|
import org.eclipse.jface.viewers.IDoubleClickListener;
|
20
|
import org.eclipse.jface.viewers.StructuredSelection;
|
21
|
import org.eclipse.jface.viewers.TableViewer;
|
22
|
import org.eclipse.jface.wizard.Wizard;
|
23
|
import org.eclipse.jface.wizard.WizardDialog;
|
24
|
import org.eclipse.jface.wizard.WizardPage;
|
25
|
import org.eclipse.swt.SWT;
|
26
|
import org.eclipse.swt.events.SelectionAdapter;
|
27
|
import org.eclipse.swt.events.SelectionEvent;
|
28
|
import org.eclipse.swt.graphics.Image;
|
29
|
import org.eclipse.swt.layout.GridData;
|
30
|
import org.eclipse.swt.layout.GridLayout;
|
31
|
import org.eclipse.swt.widgets.Button;
|
32
|
import org.eclipse.swt.widgets.Composite;
|
33
|
import org.eclipse.swt.widgets.Table;
|
34
|
import org.eclipse.swt.widgets.TableItem;
|
35
|
|
36
|
import eu.etaxonomy.cdm.model.name.NameTypeDesignation;
|
37
|
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
|
38
|
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
|
39
|
import eu.etaxonomy.cdm.model.name.TypeDesignationBase;
|
40
|
import eu.etaxonomy.taxeditor.editor.EditorUtil;
|
41
|
import eu.etaxonomy.taxeditor.store.model.NameUtil;
|
42
|
|
43
|
/**
|
44
|
* @author p.ciardelli
|
45
|
* @created 11.02.2009
|
46
|
* @version 1.0
|
47
|
*/
|
48
|
public class ListTypeWizardPage extends WizardPage {
|
49
|
private static Logger logger = Logger.getLogger(ListTypeWizardPage.class);
|
50
|
private TaxonNameBase name;
|
51
|
|
52
|
/**
|
53
|
* @param name
|
54
|
*/
|
55
|
public ListTypeWizardPage(TaxonNameBase name, WritableList typeDesignationsList) {
|
56
|
super("");
|
57
|
this.name = name;
|
58
|
|
59
|
this.typeDesignationsList = typeDesignationsList;
|
60
|
|
61
|
setTitle("Type designations for \""
|
62
|
+ NameUtil.getDisplayName(name) + "\".");
|
63
|
setDescription("Select a type designation and click \"Edit ...\" or \"Remove\", or click \"Add ...\" to create a new designation.");
|
64
|
}
|
65
|
|
66
|
private Table typeDesignationsTable;
|
67
|
private WritableList typeDesignationsList = new WritableList();
|
68
|
|
69
|
private Button btnRemove;
|
70
|
private Button btnEdit;
|
71
|
|
72
|
private TypeDesignationBase typeDesignation;
|
73
|
private TableViewer tableViewer;
|
74
|
|
75
|
|
76
|
public void createControl(Composite parent) {
|
77
|
Composite container = new Composite(parent, SWT.NULL);
|
78
|
final GridLayout gridLayout = new GridLayout();
|
79
|
gridLayout.numColumns = 3;
|
80
|
container.setLayout(gridLayout);
|
81
|
|
82
|
setControl(container);
|
83
|
|
84
|
btnEdit = new Button(container, SWT.NONE);
|
85
|
btnEdit.setText("Edit ...");
|
86
|
btnEdit.addSelectionListener(new SelectionAdapter() {
|
87
|
public void widgetSelected(SelectionEvent e) {
|
88
|
if (getSelectedTypeDesignation() != null) {
|
89
|
createTypeDesignationWizard(getSelectedTypeDesignation());
|
90
|
}
|
91
|
}
|
92
|
});
|
93
|
|
94
|
btnRemove = new Button(container, SWT.NONE);
|
95
|
btnRemove.setText("Remove");
|
96
|
btnRemove.addSelectionListener(new SelectionAdapter() {
|
97
|
public void widgetSelected(SelectionEvent e) {
|
98
|
if (getSelectedTypeDesignation() != null) {
|
99
|
typeDesignationsList.remove(getSelectedTypeDesignation());
|
100
|
setSelectedTypeDesignation(null);
|
101
|
}
|
102
|
}
|
103
|
});
|
104
|
|
105
|
setEnableTypeDesignationButtons(false);
|
106
|
|
107
|
final Button btnAdd = new Button(container, SWT.NONE);
|
108
|
final GridData gd_btnAdd = new GridData(SWT.RIGHT, SWT.CENTER, true,
|
109
|
false);
|
110
|
btnAdd.setLayoutData(gd_btnAdd);
|
111
|
btnAdd.setText("Add ...");
|
112
|
btnAdd.addSelectionListener(new SelectionAdapter() {
|
113
|
public void widgetSelected(SelectionEvent e) {
|
114
|
createTypeDesignationWizard(null);
|
115
|
}
|
116
|
});
|
117
|
|
118
|
tableViewer = new TableViewer(container, SWT.BORDER | SWT.SINGLE);
|
119
|
|
120
|
typeDesignationsTable = tableViewer.getTable();
|
121
|
typeDesignationsTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,
|
122
|
true, 3, 1));
|
123
|
typeDesignationsTable.addSelectionListener(new SelectionAdapter() {
|
124
|
public void widgetSelected(SelectionEvent e) {
|
125
|
setEnableTypeDesignationButtons(true);
|
126
|
TableItem[] selectedItem = typeDesignationsTable.getSelection();
|
127
|
if (e.item.getData() instanceof TypeDesignationBase) {
|
128
|
setSelectedTypeDesignation((TypeDesignationBase) e.item.getData());
|
129
|
}
|
130
|
}
|
131
|
});
|
132
|
|
133
|
ObservableListContentProvider providerList = new ObservableListContentProvider();
|
134
|
tableViewer.setContentProvider(providerList);
|
135
|
|
136
|
// IObservableMap[] providerMaps = BeansObservables.observeMaps(
|
137
|
// providerList.getKnownElements(), SpecimenTypeDesignation.class,
|
138
|
// new String[] { "typeSpecimen", "typeStatus" });
|
139
|
IObservableMap[] providerMaps = BeansObservables.observeMaps(
|
140
|
providerList.getKnownElements(), TypeDesignationBase.class,
|
141
|
new String[] { });
|
142
|
tableViewer.setLabelProvider(new ObservableMapLabelProvider(
|
143
|
providerMaps) {
|
144
|
public String getColumnText(Object element, int columnIndex) {
|
145
|
if (element instanceof TypeDesignationBase) {
|
146
|
return getTypeDesignationString((TypeDesignationBase) element);
|
147
|
}
|
148
|
return "";
|
149
|
}
|
150
|
|
151
|
public Image getColumnImage(Object element, int columnIndex) {
|
152
|
if (element instanceof TypeDesignationBase) {
|
153
|
return getTypeDesignationImage((TypeDesignationBase) element);
|
154
|
}
|
155
|
return null;
|
156
|
}
|
157
|
});
|
158
|
|
159
|
tableViewer.setInput(typeDesignationsList);
|
160
|
tableViewer.addDoubleClickListener(new IDoubleClickListener() {
|
161
|
public void doubleClick(DoubleClickEvent event) {
|
162
|
if (((StructuredSelection) event.getSelection())
|
163
|
.getFirstElement() instanceof TypeDesignationBase) {
|
164
|
TypeDesignationBase typeDesignation = (TypeDesignationBase)
|
165
|
((StructuredSelection) event.getSelection()).getFirstElement();
|
166
|
createTypeDesignationWizard(typeDesignation);
|
167
|
}
|
168
|
}
|
169
|
});
|
170
|
}
|
171
|
|
172
|
private void setSelectedTypeDesignation(TypeDesignationBase typeDesignation) {
|
173
|
this.typeDesignation = typeDesignation;
|
174
|
}
|
175
|
|
176
|
private TypeDesignationBase getSelectedTypeDesignation() {
|
177
|
return typeDesignation;
|
178
|
}
|
179
|
|
180
|
private void createTypeDesignationWizard(TypeDesignationBase typeDesignation) {
|
181
|
Wizard wizard = new TypeDesignationWizard(typeDesignation, name, typeDesignationsList);
|
182
|
|
183
|
WizardDialog dialog = new WizardDialog(EditorUtil.getShell(), wizard);
|
184
|
dialog.create();
|
185
|
dialog.open();
|
186
|
// if (dialog.open() == Window.OK) ...
|
187
|
}
|
188
|
|
189
|
protected void setEnableTypeDesignationButtons(boolean enabled) {
|
190
|
btnRemove.setEnabled(enabled);
|
191
|
btnEdit.setEnabled(enabled);
|
192
|
}
|
193
|
|
194
|
private Image getTypeDesignationImage(TypeDesignationBase typeDesignation) {
|
195
|
return null;
|
196
|
}
|
197
|
|
198
|
private String getTypeDesignationString(TypeDesignationBase typeDesignation) {
|
199
|
String str = "";
|
200
|
if (typeDesignation instanceof SpecimenTypeDesignation) {
|
201
|
if (((SpecimenTypeDesignation) typeDesignation).getTypeSpecimen() != null) {
|
202
|
str += ((SpecimenTypeDesignation) typeDesignation).getTypeSpecimen().getTitleCache();
|
203
|
} else {
|
204
|
str += "UNDEFINED";
|
205
|
}
|
206
|
if (typeDesignation.getTypeStatus() != null) {
|
207
|
str += " [" + typeDesignation.getTypeStatus().getLabel() + "]";
|
208
|
}
|
209
|
}
|
210
|
|
211
|
if (typeDesignation instanceof NameTypeDesignation) {
|
212
|
if (((NameTypeDesignation) typeDesignation).getTypeName() != null) {
|
213
|
str = ((NameTypeDesignation) typeDesignation).getTypeName().getTitleCache();
|
214
|
}
|
215
|
|
216
|
if (((NameTypeDesignation) typeDesignation).isLectoType()) {
|
217
|
str += " (Lectotype)";
|
218
|
}
|
219
|
}
|
220
|
|
221
|
return str;
|
222
|
}
|
223
|
}
|