1
|
/**
|
2
|
* Copyright (C) 2007 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.name;
|
11
|
|
12
|
import java.beans.PropertyChangeEvent;
|
13
|
import java.beans.PropertyChangeListener;
|
14
|
import java.util.Set;
|
15
|
import java.util.Vector;
|
16
|
|
17
|
import org.apache.log4j.Logger;
|
18
|
import org.eclipse.ui.views.properties.ComboBoxPropertyDescriptor;
|
19
|
import org.eclipse.ui.views.properties.IPropertyDescriptor;
|
20
|
import org.eclipse.ui.views.properties.PropertyDescriptor;
|
21
|
|
22
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
23
|
import eu.etaxonomy.cdm.model.name.BotanicalName;
|
24
|
import eu.etaxonomy.cdm.model.name.NonViralName;
|
25
|
import eu.etaxonomy.cdm.model.name.Rank;
|
26
|
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
|
27
|
import eu.etaxonomy.cdm.model.name.ZoologicalName;
|
28
|
import eu.etaxonomy.cdm.model.reference.ReferenceBase;
|
29
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
30
|
import eu.etaxonomy.taxeditor.model.NameHelper;
|
31
|
import eu.etaxonomy.taxeditor.propertysheet.AnnotationPropertySource;
|
32
|
import eu.etaxonomy.taxeditor.propertysheet.AnnotationsPropertyDescriptor;
|
33
|
import eu.etaxonomy.taxeditor.propertysheet.ExtensionPropertySource;
|
34
|
import eu.etaxonomy.taxeditor.propertysheet.ExtensionsPropertyDescriptor;
|
35
|
import eu.etaxonomy.taxeditor.propertysheet.ICdmBasePropertySource;
|
36
|
import eu.etaxonomy.taxeditor.propertysheet.MarkerPropertySource;
|
37
|
import eu.etaxonomy.taxeditor.propertysheet.MarkersPropertyDescriptor;
|
38
|
import eu.etaxonomy.taxeditor.propertysheet.reference.IReferenceSearch;
|
39
|
import eu.etaxonomy.taxeditor.propertysheet.reference.ReferencePropertySource;
|
40
|
import eu.etaxonomy.taxeditor.propertysheet.reference.ReferenceSearchDescriptor;
|
41
|
import eu.etaxonomy.taxeditor.propertysheet.type.TypeCollectionPropertySource;
|
42
|
import eu.etaxonomy.taxeditor.propertysheet.type.TypePropertyDescriptor;
|
43
|
|
44
|
/**
|
45
|
* @author p.ciardelli
|
46
|
* @created 11.11.2008
|
47
|
* @version 1.0
|
48
|
*/
|
49
|
public class TaxonBasePropertySource implements ICdmBasePropertySource {
|
50
|
private static final Logger logger = Logger
|
51
|
.getLogger(TaxonBasePropertySource.class);
|
52
|
|
53
|
private TaxonBase<?> taxonBase;
|
54
|
|
55
|
// Property unique keys
|
56
|
public static final String P_ID_TAXONNAME = "P_ID_TAXONNAME";
|
57
|
public static final String P_ID_TAXONSEC = "P_ID_TAXONSEC";
|
58
|
public static final String P_ID_TYPES = "P_ID_TYPES";
|
59
|
public static final String P_ID_DOUBTFUL = "P_ID_DOUBTFUL";
|
60
|
public static final String P_ID_MARKERS = "P_ID_MARKERS";
|
61
|
public static final String P_ID_EXTENSIONS = "P_ID_EXTENSIONS";
|
62
|
public static final String P_ID_TAXON_ANNOTATIONS = "P_ID_TAXON_ANNOTATIONS";
|
63
|
|
64
|
// Property display keys
|
65
|
public String P_TAXONNAME;
|
66
|
public static final String P_TAXONSEC = "Secundum";
|
67
|
public String P_TYPES = "Name Types";
|
68
|
public static final String P_DOUBTFUL = "Doubtful?";
|
69
|
public static final String P_MARKERS = "Markers";
|
70
|
public static final String P_EXTENSIONS = "Extensions";
|
71
|
public static final String P_TAXON_ANNOTATIONS = "Annotations";
|
72
|
|
73
|
private static final int NOT_DOUBTFUL = 0;
|
74
|
private static final int DOUBTFUL = 1;
|
75
|
|
76
|
public TaxonBasePropertySource(TaxonBase<?> taxon, String nameTitle) {
|
77
|
this.taxonBase = taxon;
|
78
|
|
79
|
this.P_TAXONNAME = nameTitle;
|
80
|
|
81
|
if (taxon != null && taxon.getName() != null &&
|
82
|
!NameHelper.isNameSupraSpecific(taxon.getName())) {
|
83
|
P_TYPES = "Specimen Types";
|
84
|
}
|
85
|
|
86
|
addDescriptor(P_ID_TAXONNAME);
|
87
|
addDescriptor(P_ID_TAXONSEC);
|
88
|
addDescriptor(P_ID_TYPES);
|
89
|
addDescriptor(P_ID_DOUBTFUL);
|
90
|
addDescriptor(P_ID_TAXON_ANNOTATIONS);
|
91
|
addDescriptor(P_ID_MARKERS);
|
92
|
addDescriptor(P_ID_EXTENSIONS);
|
93
|
}
|
94
|
|
95
|
protected Vector<PropertyDescriptor> descriptors = new Vector<PropertyDescriptor>();
|
96
|
|
97
|
protected void addDescriptor(String id) {
|
98
|
if (id.equals(P_ID_TAXONNAME)) {
|
99
|
descriptors.addElement(
|
100
|
new PropertyDescriptor(P_ID_TAXONNAME, P_TAXONNAME));
|
101
|
}
|
102
|
if (id.equals(P_ID_TAXONSEC)) {
|
103
|
descriptors.addElement(new ReferenceSearchDescriptor(P_ID_TAXONSEC, P_TAXONSEC, IReferenceSearch.BIBREF, taxonBase.getSec()) {
|
104
|
protected void saveReference(ReferenceBase reference) {
|
105
|
setPropertyValue(P_ID_TAXONSEC, reference);
|
106
|
}
|
107
|
});
|
108
|
}
|
109
|
if (id.equals(P_ID_TYPES)) {
|
110
|
descriptors.addElement(
|
111
|
new TypePropertyDescriptor(P_ID_TYPES, P_TYPES, taxonBase.getName()) {
|
112
|
protected void saveTypes(Set set) {
|
113
|
setPropertyValue(P_ID_TYPES, set);
|
114
|
}
|
115
|
}
|
116
|
);
|
117
|
};
|
118
|
|
119
|
if (id.equals(P_ID_DOUBTFUL)) {
|
120
|
descriptors.addElement(
|
121
|
new ComboBoxPropertyDescriptor(P_ID_DOUBTFUL, P_DOUBTFUL,
|
122
|
new String[] {"no", "yes"}));
|
123
|
}
|
124
|
|
125
|
if (id.equals(P_ID_MARKERS)) {
|
126
|
descriptors.addElement(
|
127
|
new MarkersPropertyDescriptor(P_ID_MARKERS, P_MARKERS, taxonBase));
|
128
|
}
|
129
|
|
130
|
if (id.equals(P_ID_EXTENSIONS)) {
|
131
|
descriptors.addElement(
|
132
|
new ExtensionsPropertyDescriptor(P_ID_EXTENSIONS, P_EXTENSIONS, taxonBase));
|
133
|
}
|
134
|
|
135
|
// Annotations, listed in custom property descriptor
|
136
|
if (id.equals(P_ID_TAXON_ANNOTATIONS)) {
|
137
|
descriptors.addElement(
|
138
|
new AnnotationsPropertyDescriptor(P_ID_TAXON_ANNOTATIONS, P_TAXON_ANNOTATIONS, taxonBase) {
|
139
|
protected void saveAnnotations(Set set) {
|
140
|
setPropertyValue(P_ID_TAXON_ANNOTATIONS, set);
|
141
|
}
|
142
|
}
|
143
|
);
|
144
|
};
|
145
|
}
|
146
|
|
147
|
/* (non-Javadoc)
|
148
|
* @see org.eclipse.ui.views.properties.IPropertySource#getEditableValue()
|
149
|
*/
|
150
|
public Object getEditableValue() {
|
151
|
return null;
|
152
|
}
|
153
|
|
154
|
/* (non-Javadoc)
|
155
|
* @see org.eclipse.ui.views.properties.IPropertySource#getPropertyDescriptors()
|
156
|
*/
|
157
|
public IPropertyDescriptor[] getPropertyDescriptors() {
|
158
|
return (IPropertyDescriptor[]) descriptors.toArray(
|
159
|
new IPropertyDescriptor[descriptors.size()]);
|
160
|
}
|
161
|
|
162
|
/* (non-Javadoc)
|
163
|
* @see org.eclipse.ui.views.properties.IPropertySource#getPropertyValue(java.lang.Object)
|
164
|
*/
|
165
|
public Object getPropertyValue(Object id) {
|
166
|
|
167
|
// Edit taxon's name
|
168
|
if (id.equals(P_ID_TAXONNAME)) {
|
169
|
|
170
|
if (taxonBase == null) {
|
171
|
logger.warn("no taxon");
|
172
|
return null;
|
173
|
}
|
174
|
TaxonNameBase<?, ?> name = taxonBase.getName();
|
175
|
|
176
|
// Create taxon name as necessary
|
177
|
if (name == null) {
|
178
|
name = NonViralName.NewInstance(Rank.SPECIES());
|
179
|
}
|
180
|
name = CdmBase.deproxy(name, TaxonNameBase.class);
|
181
|
// Send taxon name to appropriate property source for submenu
|
182
|
if (name instanceof BotanicalName) {
|
183
|
return new BotanicalNamePropertySource((BotanicalName) name);
|
184
|
}
|
185
|
if (name instanceof ZoologicalName) {
|
186
|
return new ZoologicalNamePropertySource((ZoologicalName) name);
|
187
|
}
|
188
|
if (name instanceof NonViralName) {
|
189
|
return new NonViralNamePropertySource((NonViralName<?>) name);
|
190
|
}
|
191
|
|
192
|
}
|
193
|
|
194
|
// Edit taxon's sec. reference
|
195
|
if (id.equals(P_ID_TAXONSEC)) {
|
196
|
|
197
|
if (taxonBase == null) {
|
198
|
return null;
|
199
|
}
|
200
|
ReferenceBase<?> sec = taxonBase.getSec();
|
201
|
|
202
|
// Create property source for submenu
|
203
|
ReferencePropertySource secPropertySource = new ReferencePropertySource(sec);
|
204
|
|
205
|
// Add listener to notify taxon of all changes to sec
|
206
|
secPropertySource.addPropertyChangeListener(new PropertyChangeListener() {
|
207
|
public void propertyChange(PropertyChangeEvent evt) {
|
208
|
if (evt.getNewValue() instanceof ReferenceBase) {
|
209
|
taxonBase.setSec((ReferenceBase<?>) evt.getNewValue());
|
210
|
}
|
211
|
}
|
212
|
});
|
213
|
return secPropertySource;
|
214
|
}
|
215
|
|
216
|
if (id.equals(P_ID_TYPES)) {
|
217
|
if (taxonBase.getName() != null) {
|
218
|
// TODO return NameTypeDesignations
|
219
|
TaxonNameBase<?, ?> name = taxonBase.getName();
|
220
|
Set<?> typeDesignations = null;
|
221
|
if (NameHelper.isNameSupraSpecific(name)) {
|
222
|
typeDesignations = name.getNameTypeDesignations();
|
223
|
} else {
|
224
|
typeDesignations = name.getSpecimenTypeDesignations();
|
225
|
}
|
226
|
return new TypeCollectionPropertySource(name, typeDesignations);
|
227
|
}
|
228
|
}
|
229
|
|
230
|
// Edit doubtful flag
|
231
|
if (id.equals(P_ID_DOUBTFUL)) {
|
232
|
if (taxonBase.isDoubtful()) {
|
233
|
return DOUBTFUL;
|
234
|
} else {
|
235
|
return NOT_DOUBTFUL;
|
236
|
}
|
237
|
}
|
238
|
|
239
|
if (id.equals(P_ID_MARKERS)) {
|
240
|
return new MarkerPropertySource(taxonBase);
|
241
|
}
|
242
|
|
243
|
if (id.equals(P_ID_EXTENSIONS)) {
|
244
|
return new ExtensionPropertySource(taxonBase);
|
245
|
}
|
246
|
|
247
|
if (id.equals(P_ID_TAXON_ANNOTATIONS)) {
|
248
|
return new AnnotationPropertySource(taxonBase);
|
249
|
}
|
250
|
|
251
|
return null;
|
252
|
}
|
253
|
|
254
|
/* (non-Javadoc)
|
255
|
* @see org.eclipse.ui.views.properties.IPropertySource#isPropertySet(java.lang.Object)
|
256
|
*/
|
257
|
public boolean isPropertySet(Object id) {
|
258
|
return false;
|
259
|
}
|
260
|
|
261
|
/* (non-Javadoc)
|
262
|
* @see org.eclipse.ui.views.properties.IPropertySource#resetPropertyValue(java.lang.Object)
|
263
|
*/
|
264
|
public void resetPropertyValue(Object id) {}
|
265
|
|
266
|
/* (non-Javadoc)
|
267
|
* @see org.eclipse.ui.views.properties.IPropertySource#setPropertyValue(java.lang.Object, java.lang.Object)
|
268
|
*/
|
269
|
public void setPropertyValue(Object id, Object value) {
|
270
|
if (id.equals(P_ID_TAXONSEC)) {
|
271
|
if (value instanceof ReferenceBase) {
|
272
|
taxonBase.setSec((ReferenceBase<?>) value);
|
273
|
}
|
274
|
}
|
275
|
|
276
|
if (id.equals(P_ID_DOUBTFUL)) {
|
277
|
if (((Integer) value).intValue() == DOUBTFUL) {
|
278
|
taxonBase.setDoubtful(true);
|
279
|
} else {
|
280
|
taxonBase.setDoubtful(false);
|
281
|
}
|
282
|
}
|
283
|
}
|
284
|
|
285
|
/**
|
286
|
* @return the taxonBase
|
287
|
*/
|
288
|
public TaxonBase<?> getTaxonBase() {
|
289
|
return taxonBase;
|
290
|
}
|
291
|
}
|