2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.propertysheet
.name
;
12 import java
.beans
.PropertyChangeEvent
;
13 import java
.beans
.PropertyChangeListener
;
14 import java
.beans
.PropertyChangeSupport
;
15 import java
.util
.ArrayList
;
16 import java
.util
.Date
;
17 import java
.util
.List
;
19 import java
.util
.Vector
;
21 import org
.apache
.log4j
.Logger
;
22 import org
.eclipse
.ui
.views
.properties
.ComboBoxPropertyDescriptor
;
23 import org
.eclipse
.ui
.views
.properties
.IPropertyDescriptor
;
24 import org
.eclipse
.ui
.views
.properties
.IPropertySource
;
25 import org
.eclipse
.ui
.views
.properties
.PropertyDescriptor
;
26 import org
.eclipse
.ui
.views
.properties
.TextPropertyDescriptor
;
28 import eu
.etaxonomy
.cdm
.common
.CdmUtils
;
29 import eu
.etaxonomy
.cdm
.model
.common
.Annotation
;
30 import eu
.etaxonomy
.cdm
.model
.common
.TermVocabulary
;
31 import eu
.etaxonomy
.cdm
.model
.common
.TimePeriod
;
32 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalStatus
;
33 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalStatusType
;
34 import eu
.etaxonomy
.cdm
.model
.name
.NonViralName
;
35 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
36 import eu
.etaxonomy
.cdm
.model
.reference
.Article
;
37 import eu
.etaxonomy
.cdm
.model
.reference
.BibtexReference
;
38 import eu
.etaxonomy
.cdm
.model
.reference
.Book
;
39 import eu
.etaxonomy
.cdm
.model
.reference
.BookSection
;
40 import eu
.etaxonomy
.cdm
.model
.reference
.Generic
;
41 import eu
.etaxonomy
.cdm
.model
.reference
.INomenclaturalReference
;
42 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceBase
;
43 import eu
.etaxonomy
.taxeditor
.ITaxEditorConstants
;
44 import eu
.etaxonomy
.taxeditor
.TaxEditorPlugin
;
45 import eu
.etaxonomy
.taxeditor
.UiUtil
;
46 import eu
.etaxonomy
.taxeditor
.model
.CdmUtil
;
47 import eu
.etaxonomy
.taxeditor
.propertysheet
.AnnotationPropertySource
;
48 import eu
.etaxonomy
.taxeditor
.propertysheet
.AnnotationsPropertyDescriptor
;
49 import eu
.etaxonomy
.taxeditor
.propertysheet
.MarkersPropertySource
;
50 import eu
.etaxonomy
.taxeditor
.propertysheet
.reference
.NomenclaturalReferencePropertySource
;
51 import eu
.etaxonomy
.taxeditor
.propertysheet
.reference
.ReferencePropertySource
;
58 public class NonViralNamePropertySource
implements IPropertySource
{
59 private static final Logger logger
= Logger
60 .getLogger(NonViralNamePropertySource
.class);
62 // The name whose properties are being displayed
65 // If this is a property with a parent, the parent's property ID
66 private String parentid
= "";
68 PropertyChangeSupport propertyChangeSupport
;
70 // Property unique keys
71 public static final String P_ID_PARSED
= "parsed";
72 public static final String P_ID_RANK
= "rank";
73 public static final String P_ID_TITLECACHE
= "titlecache";
74 public static final String P_ID_UNINOMIAL
= "uninomial";
75 public static final String P_ID_INFRAGENERICEP
= "infragenericep";
76 public static final String P_ID_SPECIESEP
= "speciesep";
77 public static final String P_ID_INFRASPECIFICEP
= "infraspecificep";
78 public static final String P_ID_APPENDEDPHRASE
= "appendedphrase";
79 public static final String P_ID_HOMOTYPICALGROUP
= "homogroup";
80 public static final String P_ID_AUTHORSHIPCACHE
= "authorshipcache";
81 public static final String P_ID_NAMERELATIONS
= "namerelations";
82 public static final String P_ID_TYPE
= "type";
83 public static final String P_ID_ANNOTATIONS
= "annotations";
84 public static final String P_ID_NOMSTATUS
= "nomstatus";
85 public static final String P_ID_UUID
= "uuid";
86 public static final String P_ID_NUM_OF_BASES
= "numberofbases";
87 public static final String P_ID_MARKERS
= "markers";
88 public static final String P_ID_CREATED
= "created";
89 public static final String P_ID_CREATEDBY
= "createdby";
90 public static final String P_ID_NOMENCLATURAL_CODE
= "nomenclaturalcode";
91 public static final String P_ID_NOMENCLATURAL_REF
= "nomenclaturalref";
92 public static final String P_ID_NOMENCLATURAL_MICROREF
= "nomenclaturalmicroref";
93 public static final String P_ID_REFERENCEYEAR
= "referenceyear";
94 public static final String P_ID_NOMREF_TYPE
= "nomreftype";
95 public static final String P_ID_NOMREF_YEAR
= "nomrefyear";
96 public static final String P_ID_NOMREF_TITLE
= "nomreftitle";
98 // Property display keys
99 // Note: for an explanation of the sorting prefixes ("04:"),
100 // @see eu.etaxonomy.taxeditor.propertysheet.CustomSortPropertySheetEntry
101 public static final String P_PARSED
= "00:Parsing Status";
102 public static final String P_RANK
= "02:Rank";
103 public static final String P_TITLECACHE
= "03:Name Cache";
104 public static final String P_UNINOMIAL
= "04:Uninomial";
105 public static final String P_INFRAGENERICEP
= "05:Infrageneric Epithet";
106 public static final String P_SPECIESEP
= "06:Specific Epithet";
107 public static final String P_INFRASPECIFICEP
= "07:Infraspecific Epithet";
108 public static final String P_APPENDEDPHRASE
= "09:Appended Phrase";
109 public static final String P_HOMOTYPICALGROUP
= "09:Homotypical Group";
110 public static final String P_AUTHORSHIPCACHE
= "08:Authorship";
111 public static final String P_NAMERELATIONS
= "11:Name Relations";
112 public static final String P_TYPE
= "12:Type";
113 public static final String P_ANNOTATIONS
= "14:Annotations";
114 public static final String P_NOMSTATUS
= "10:Nomenclatural Status";
115 public static final String P_UUID
= "01:UUID";
116 public static final String P_NUM_OF_BASES
= "12:Number of Bases";
117 public static final String P_MARKERS
= "13:Markers";
118 public static final String P_CREATED
= "15:Created";
119 public static final String P_CREATEDBY
= "16:Created By";
120 public static final String P_NOMENCLATURAL_CODE
= "02:Nomenclatural Code";
121 public static final String P_NOMENCLATURAL_REF
= "09:Nomenclatural Reference";
122 public static final String P_NOMENCLATURAL_MICROREF
= "10:Micro Reference";
123 public static final String P_NOMREF_TYPE
= "00:Reference Type";
124 public static final String P_NOMREF_YEAR
= "02:Year";
125 public static final String P_NOMREF_TITLE
= "01:Title";
127 protected static final String
[] TOP_LEVEL_PROPERTIES
= new String
[] {P_ID_PARSED
, P_ID_RANK
, P_ID_TITLECACHE
,
128 P_ID_ANNOTATIONS
, P_ID_NOMSTATUS
, P_ID_NAMERELATIONS
, P_ID_UUID
, P_ID_NOMENCLATURAL_REF
,
129 P_ID_TYPE
, P_ID_CREATED
, P_ID_CREATEDBY
, P_ID_NOMENCLATURAL_CODE
};
131 // ***********************************************************
133 // ***********************************************************
135 String
[] P_RANK_MENU
= null;
136 private void populateRanks() {
138 // Get terms from rank vocabulary
139 List
<Rank
> ranksList
= new ArrayList
<Rank
>();
140 ranksList
.addAll(UiUtil
.getPreferredRanks());
142 // Populate ranks menu labels
143 List
<String
> ranksMenuList
= new ArrayList
<String
>();
144 for (Rank rank
: ranksList
) {
145 ranksMenuList
.add(rank
.getLabel());
148 // Add an empty element for "nothing selected" in the rank drop-down
149 ranksList
.add(0, null);
150 ranksMenuList
.add(0, "");
152 // Convert rank lists to array
153 ranks
= ranksList
.toArray(new Rank
[ranksList
.size()]);
154 P_RANK_MENU
= ranksMenuList
.toArray(new String
[ranksMenuList
.size()]);
157 static String
[] P_NOMENCLATURALCODE_MENU
= new String
[] { "ICZN", "ICBN" };
158 static String
[] P_NOMREF_TYPE_MENU
= new String
[] { "Article", "Bibtex", "Book", "Book Section", "Generic" };
160 // ***********************************************************
161 // NOMENCLATURAL STATUS
162 // ***********************************************************
163 static TermVocabulary
<NomenclaturalStatusType
> nomStatusVocabulary
=
164 TaxEditorPlugin
.getDefault().getNomStatusVocabulary();
165 static NomenclaturalStatusType
[] nomStatusTypes
= null;
166 static String
[] P_NOMSTATUS_MENU
= null;
167 private static void populateNomStatusTypes() {
169 // Get terms from nom status vocabulary
170 List
<NomenclaturalStatusType
> nomStatusTypesList
= new ArrayList
<NomenclaturalStatusType
>();
171 nomStatusTypesList
.addAll(nomStatusVocabulary
.getTerms());
173 // Populate nom status type menu labels
174 List
<String
> nomStatusTypesMenuList
= new ArrayList
<String
>();
175 for (NomenclaturalStatusType nomStatusType
: nomStatusTypesList
) {
176 nomStatusTypesMenuList
.add(nomStatusType
.getLabel());
179 // Add an empty element for "nothing selected" in the rank drop-down
180 nomStatusTypesList
.add(0, null);
181 nomStatusTypesMenuList
.add(0, "");
183 // Convert rank lists to array
184 nomStatusTypes
= nomStatusTypesList
.toArray(new NomenclaturalStatusType
[nomStatusTypesList
.size()]);
185 P_NOMSTATUS_MENU
= nomStatusTypesMenuList
.toArray(new String
[nomStatusTypesMenuList
.size()]);
188 protected Vector
<PropertyDescriptor
> descriptors
= new Vector
<PropertyDescriptor
>();
190 * Add descriptor for a given property.
192 * Notes on Descriptor:
195 * <li>PropertyDescriptor - uneditable cell value</li>
196 * <li>ComboBoxPropertyDescriptor - dropdown list, property supplied must be integer-based</li>
197 * <li>TextPropertyDescriptor - editable cell value</li>
200 * If any descriptor calls setCategory, all descriptors w/out a category are put in
203 * <code>descriptor.setFilterFlags (new String[] { IPropertySheetEntry.FILTER_ID_EXPERT })</code> -
204 * this descriptor shown under advanced properties
208 protected void addDescriptor(String id
) {
209 if (id
.equals(P_ID_PARSED
)) {
210 descriptors
.addElement(
211 new PropertyDescriptor(P_ID_PARSED
, P_PARSED
));
213 if (id
.equals(P_ID_RANK
)) {
217 descriptors
.addElement(
218 new ComboBoxPropertyDescriptor(P_ID_RANK
, P_RANK
, P_RANK_MENU
));
220 if (id
.equals(P_ID_TITLECACHE
)) {
221 descriptors
.addElement(
222 new PropertyDescriptor(P_ID_TITLECACHE
, P_TITLECACHE
));
224 if (id
.equals(P_ID_UNINOMIAL
)) {
225 descriptors
.addElement(
226 new TextPropertyDescriptor(P_ID_UNINOMIAL
, P_UNINOMIAL
));
228 if (id
.equals(P_ID_INFRAGENERICEP
)) {
229 descriptors
.addElement(
230 new TextPropertyDescriptor(P_ID_INFRAGENERICEP
, P_INFRAGENERICEP
));
232 if (id
.equals(P_ID_SPECIESEP
)) {
233 descriptors
.addElement(
234 new TextPropertyDescriptor(P_ID_SPECIESEP
, P_SPECIESEP
));
236 if (id
.equals(P_ID_INFRASPECIFICEP
)) {
237 descriptors
.addElement(
238 new TextPropertyDescriptor(P_ID_INFRASPECIFICEP
, P_INFRASPECIFICEP
));
240 if (id
.equals(P_ID_APPENDEDPHRASE
)) {
241 descriptors
.addElement(
242 new TextPropertyDescriptor(P_ID_APPENDEDPHRASE
, P_APPENDEDPHRASE
));
244 if (id
.equals(P_ID_AUTHORSHIPCACHE
)) {
245 descriptors
.addElement(
246 new TextPropertyDescriptor(P_ID_AUTHORSHIPCACHE
, P_AUTHORSHIPCACHE
));
248 if (id
.equals(P_ID_HOMOTYPICALGROUP
)) {
249 descriptors
.addElement(
250 new PropertyDescriptor(P_ID_HOMOTYPICALGROUP
, P_HOMOTYPICALGROUP
));
252 if (id
.equals(P_ID_NAMERELATIONS
)) {
253 descriptors
.addElement(
254 new NameRelationsPropertyDescriptor(P_ID_NAMERELATIONS
, P_NAMERELATIONS
, name
) {
255 protected void saveNameRelations(Set set
) {
256 setPropertyValue(P_ID_NAMERELATIONS
, set
);
262 if (id
.equals(P_ID_TYPE
)) {
263 descriptors
.addElement(
264 new PropertyDescriptor(P_ID_TYPE
, P_TYPE
));
266 if (id
.equals(P_ID_ANNOTATIONS
)) {
267 descriptors
.addElement(
268 new AnnotationsPropertyDescriptor(P_ID_ANNOTATIONS
, P_ANNOTATIONS
, name
) {
269 protected void saveAnnotations(Set set
) {
270 setPropertyValue(P_ID_ANNOTATIONS
, set
);
275 if (id
.equals(P_ID_NOMSTATUS
)) {
276 if (nomStatusTypes
== null) {
277 populateNomStatusTypes();
279 descriptors
.addElement(
280 new ComboBoxPropertyDescriptor(P_ID_NOMSTATUS
, P_NOMSTATUS
, P_NOMSTATUS_MENU
));
282 if (id
.equals(P_ID_UUID
)) {
283 descriptors
.addElement(
284 new PropertyDescriptor(P_ID_UUID
, P_UUID
));
286 if (id
.equals(P_ID_MARKERS
)) {
287 descriptors
.addElement(
288 new PropertyDescriptor(P_ID_MARKERS
, P_MARKERS
));
290 if (id
.equals(P_ID_NUM_OF_BASES
)) {
291 descriptors
.addElement(
292 new PropertyDescriptor(P_ID_NUM_OF_BASES
, P_NUM_OF_BASES
));
294 if (id
.equals(P_ID_CREATED
)) {
295 descriptors
.addElement(
296 new PropertyDescriptor(P_ID_CREATED
, P_CREATED
));
298 if (id
.equals(P_ID_CREATEDBY
)) {
299 descriptors
.addElement(
300 new PropertyDescriptor(P_ID_CREATEDBY
, P_CREATEDBY
));
302 if (id
.equals(P_ID_NOMENCLATURAL_CODE
)) {
303 descriptors
.addElement(
304 new PropertyDescriptor(P_ID_NOMENCLATURAL_CODE
, P_NOMENCLATURAL_CODE
));
305 // Assuming the ability to change a name's code is not a burning priority ...
306 // new ComboBoxPropertyDescriptor(P_ID_NOMENCLATURAL_CODE, P_NOMENCLATURAL_CODE, P_NOMENCLATURALCODE_MENU));
308 if (id
.equals(P_ID_NOMENCLATURAL_REF
)) {
309 descriptors
.addElement(
310 // new TextPropertyDescriptor(P_ID_NOMENCLATURAL_REF, P_NOMENCLATURAL_REF));
311 new PropertyDescriptor(P_ID_NOMENCLATURAL_REF
, P_NOMENCLATURAL_REF
));
313 if (id
.equals(P_ID_NOMENCLATURAL_MICROREF
)) {
314 descriptors
.addElement(
315 new TextPropertyDescriptor(P_ID_NOMENCLATURAL_MICROREF
,P_NOMENCLATURAL_MICROREF
));
317 if (id
.equals(P_ID_NOMREF_TYPE
)) {
318 descriptors
.addElement(
319 new PropertyDescriptor(P_ID_NOMREF_TYPE
, P_NOMREF_TYPE
));
320 // new ComboBoxPropertyDescriptor(P_ID_NOMREF_TYPE, P_NOMREF_TYPE, P_NOMREF_TYPE_MENU));
322 if (id
.equals(P_ID_NOMREF_YEAR
)) {
323 descriptors
.addElement(
324 new TextPropertyDescriptor(P_ID_NOMREF_YEAR
, P_NOMREF_YEAR
));
326 if (id
.equals(P_ID_NOMREF_TITLE
)) {
327 descriptors
.addElement(
328 new TextPropertyDescriptor(P_ID_NOMREF_TITLE
, P_NOMREF_TITLE
));
333 * Constructor for top level property fields. All fields that are not subfields
334 * should be listed here.
337 public NonViralNamePropertySource(NonViralName name
) {
338 this(name
, null, TOP_LEVEL_PROPERTIES
);
341 public NonViralNamePropertySource(NonViralName name
,
342 String parentid
, String
[] keys
) {
344 this.parentid
= parentid
;
345 for (String key
: keys
) {
350 public Object
getEditableValue() {
354 public IPropertyDescriptor
[] getPropertyDescriptors() {
355 return (IPropertyDescriptor
[]) descriptors
.toArray(
356 new IPropertyDescriptor
[descriptors
.size()]);
359 public Object
getPropertyValue(Object id
) {
360 if (id
.equals(P_ID_PARSED
)) {
361 return name
.getHasProblem() == true ?
"problem" : "parsed" ;
363 if (id
.equals(P_ID_RANK
)) {
364 if (this.name
.getRank() == null) {
367 Rank rank
= this.name
.getRank();
368 for (int i
= 0; i
< ranks
.length
; i
++) {
369 if (ranks
[i
] == null) continue;
370 if (rank
.getUuid().equals(ranks
[i
].getUuid()))
375 if (id
.equals(P_ID_TITLECACHE
)) {
377 // If the name has not been parsed, only show the title cache
378 // if (name.getHasProblem()) {
379 if (name
.getRank() == null) {
380 return CdmUtils
.Nz(name
.getTitleCache());
382 return new NonViralNamePropertySource(name
, P_ID_TITLECACHE
, getNameFields());
385 if (id
.equals(P_ID_UNINOMIAL
)) {
386 return CdmUtils
.Nz(name
.getGenusOrUninomial());
388 if (id
.equals(P_ID_INFRAGENERICEP
)) {
389 return CdmUtils
.Nz(name
.getInfraGenericEpithet());
391 if (id
.equals(P_ID_SPECIESEP
)) {
392 return CdmUtils
.Nz(name
.getSpecificEpithet());
394 if (id
.equals(P_ID_INFRASPECIFICEP
)) {
395 return CdmUtils
.Nz(name
.getInfraSpecificEpithet());
397 if (id
.equals(P_ID_APPENDEDPHRASE
)) {
398 return CdmUtils
.Nz(name
.getAppendedPhrase());
400 if (id
.equals(P_ID_AUTHORSHIPCACHE
)) {
401 return CdmUtils
.Nz(name
.getAuthorshipCache());
403 if (id
.equals(P_ID_HOMOTYPICALGROUP
)) {
404 return CdmUtils
.Nz(name
.getHomotypicalGroup().getUuid().toString());
406 if (id
.equals(P_ID_ANNOTATIONS
)) {
407 return new AnnotationPropertySource(name
.getAnnotations());
409 if (id
.equals(P_ID_NOMSTATUS
)) {
410 // return new NomStatusPropertySource(name.getStatus());
411 // if (this.name.getRank() == null) return 0;
412 Set
<NomenclaturalStatus
> nomStatusSet
= this.name
.getStatus();
414 if (nomStatusSet
== null || nomStatusSet
.size() == 0) {
417 // TODO for now, only showing first nom status - change!
418 NomenclaturalStatus nomStatus
= (NomenclaturalStatus
) nomStatusSet
.toArray()[0];
419 for (int i
= 0; i
< nomStatusTypes
.length
; i
++) {
420 if (nomStatusTypes
[i
] == null) continue;
421 if (nomStatus
.getType().getUuid().equals(nomStatusTypes
[i
].getUuid()))
426 if (id
.equals(P_ID_NAMERELATIONS
)) {
427 return new NameRelationsPropertySource(name
, name
.getNameRelations());
429 // TODO Button to link to type module
430 if (id
.equals(P_ID_TYPE
)) {
433 if (id
.equals(P_ID_UUID
)) {
434 return CdmUtils
.Nz(name
.getUuid().toString());
436 if (id
.equals(P_ID_MARKERS
)) {
437 return new MarkersPropertySource(name
.getMarkers());
439 if (id
.equals(P_ID_NUM_OF_BASES
)) {
440 return name
.getTaxonBases().size();
442 if (id
.equals(P_ID_CREATED
)) {
443 if (name
.getCreated() == null) {
446 return formatDate(name
.getCreated().toDate());
449 if (id
.equals(P_ID_CREATEDBY
)) {
450 if (name
.getCreatedBy() == null) {
453 return CdmUtils
.Nz(name
.getCreatedBy().generateTitle());
456 if (id
.equals(P_ID_NOMENCLATURAL_CODE
)) {
457 // Only shown if extending classes don't handle P_ID_NOMENCLATURAL_CODE
458 return "none (nonviral name)";
460 if (id
.equals(P_ID_NOMENCLATURAL_REF
)) {
462 // INomenclaturalReference nomenclaturalReference = (INomenclaturalReference) name.getNomenclaturalReference();
463 // if (name.getNomenclaturalReference() == null) {
466 // return new NonViralNamePropertySource(name, P_ID_NOMENCLATURAL_REF, getReferenceFields());
469 ReferenceBase nomRef
= (ReferenceBase
) name
.getNomenclaturalReference();
471 // Create nom. reference as necessary
472 if (nomRef
== null) {
473 nomRef
= Generic
.NewInstance();
476 // Create property source for submenu
477 ReferencePropertySource nomRefPropertySource
= new NomenclaturalReferencePropertySource(nomRef
);
479 // Add listener to notify name of all changes to nom. reference
480 nomRefPropertySource
.addPropertyChangeListener(new PropertyChangeListener() {
481 public void propertyChange(PropertyChangeEvent evt
) {
482 if (evt
.getNewValue() instanceof INomenclaturalReference
) {
483 name
.setNomenclaturalReference((INomenclaturalReference
) evt
.getNewValue());
487 return nomRefPropertySource
;
490 if (id
.equals(P_ID_NOMENCLATURAL_MICROREF
)) {
491 return CdmUtils
.Nz(name
.getNomenclaturalMicroReference());
493 INomenclaturalReference nomenclaturalReference
= (INomenclaturalReference
) name
.getNomenclaturalReference();
494 if (id
.equals(P_ID_NOMREF_TYPE
)) {
495 if (nomenclaturalReference
instanceof Article
) {
498 if (nomenclaturalReference
instanceof BibtexReference
) {
501 if (nomenclaturalReference
instanceof Book
) {
504 if (nomenclaturalReference
instanceof BookSection
) {
505 return "Book Section";
507 if (nomenclaturalReference
instanceof Generic
) {
512 if (id
.equals(P_ID_NOMREF_YEAR
)) {
513 return CdmUtils
.Nz(nomenclaturalReference
.getYear());
515 if (id
.equals(P_ID_NOMREF_TITLE
)) {
516 if (nomenclaturalReference
instanceof Article
) {
517 return CdmUtils
.Nz(((Article
) nomenclaturalReference
).getTitle());
519 if (nomenclaturalReference
instanceof BibtexReference
) {
520 return CdmUtils
.Nz(((BibtexReference
) nomenclaturalReference
).getTitle());
522 if (nomenclaturalReference
instanceof Book
) {
523 return CdmUtils
.Nz(((Book
) nomenclaturalReference
).getTitle());
525 if (nomenclaturalReference
instanceof BookSection
) {
526 return CdmUtils
.Nz(((BookSection
) nomenclaturalReference
).getTitle());
528 if (nomenclaturalReference
instanceof Generic
) {
529 return CdmUtils
.Nz(((Generic
) nomenclaturalReference
).getTitle());
536 * The fields displayed under the title cache are dependent on rank.
540 private String
[] getNameFields() {
542 // An unparsed name has no name fields, only a cache.
543 // Therefore, if rank is null, the name is unparsed.
544 if (name
.getRank() == null) {
548 List
<String
> nameFields
= new ArrayList
<String
>();
549 nameFields
.add(P_ID_UNINOMIAL
);
550 if (name
.isSupraGeneric() || name
.isGenus()) { // Rank is higher than GENUS or equals GENUS
552 else if (name
.isInfraGeneric()) { // lower than GENUS and higher than SPECIES
553 nameFields
.add(P_ID_INFRAGENERICEP
);
555 else if (name
.isSpecies()) { // Rank equals SPECIES
556 nameFields
.add(P_ID_SPECIESEP
);
558 else if (name
.isInfraSpecific()) { // Rank is lower than SPECIES
559 nameFields
.add(P_ID_SPECIESEP
);
560 nameFields
.add(P_ID_INFRASPECIFICEP
);
562 nameFields
.add(P_ID_SPECIESEP
);
564 nameFields
.add(P_ID_AUTHORSHIPCACHE
);
565 nameFields
.add(P_ID_APPENDEDPHRASE
);
566 return nameFields
.toArray(new String
[nameFields
.size()]);
569 private String
[] getReferenceFields() {
570 List
<String
> referenceFields
= new ArrayList
<String
>();
572 INomenclaturalReference reference
= (INomenclaturalReference
) name
.getNomenclaturalReference();
573 if (reference
== null) {
577 referenceFields
.add(P_ID_NOMREF_TYPE
);
578 referenceFields
.add(P_ID_NOMREF_YEAR
);
579 referenceFields
.add(P_ID_NOMENCLATURAL_MICROREF
);
580 referenceFields
.add(P_ID_NOMREF_TITLE
);
582 if (reference
instanceof Article
) {
585 if (reference
instanceof BibtexReference
) {
588 if (reference
instanceof Book
) {
591 if (reference
instanceof BookSection
) {
594 if (reference
instanceof Generic
) {
598 return referenceFields
.toArray(new String
[referenceFields
.size()]);
601 private Object
formatDate(Date date
) {
602 return String
.format("%1$tm-%1$td-%1$tY %1$tH:%1$tM:%1$tS", date
);
605 public boolean isPropertySet(Object id
) {
609 public void resetPropertyValue(Object id
) {}
612 * Any editable fields are set in the object here.
614 * @see org.eclipse.ui.views.properties.IPropertySource#setPropertyValue(java.lang.Object, java.lang.Object)
616 public void setPropertyValue(Object id
, Object value
) {
618 // Since this is only called when the property value changes,
619 // it is a reliable place to fire the name's property change
621 name
.firePropertyChange(ITaxEditorConstants
.PROPERTY_SHEET_CHANGE
, null, null);
623 if (id
.equals(P_ID_RANK
)) {
624 int index
= ((Integer
) value
).intValue();
625 name
.setRank(ranks
[index
]);
627 if (id
.equals(P_ID_UNINOMIAL
)) {
628 name
.setGenusOrUninomial((String
) value
);
630 if (id
.equals(P_ID_INFRAGENERICEP
)) {
631 name
.setInfraGenericEpithet((String
) value
);
633 if (id
.equals(P_ID_SPECIESEP
)) {
634 name
.setSpecificEpithet((String
) value
);
636 if (id
.equals(P_ID_INFRASPECIFICEP
)) {
637 name
.setInfraSpecificEpithet((String
) value
);
639 if (id
.equals(P_ID_APPENDEDPHRASE
)) {
640 name
.setAppendedPhrase((String
) value
);
642 if (id
.equals(P_ID_AUTHORSHIPCACHE
)) {
643 name
.setAuthorshipCache((String
) value
);
645 if (id
.equals(P_ID_ANNOTATIONS
)) {
646 Set annotations
= name
.getAnnotations();
647 if (value
instanceof Set
) {
648 for (Object object
: (Set
) value
) {
649 if (object
instanceof Annotation
&& !annotations
.contains(object
)) {
650 name
.addAnnotation((Annotation
) object
);
655 if (id
.equals(P_ID_NAMERELATIONS
)) {
656 // TODO set name relations
658 if (id
.equals(P_ID_NOMSTATUS
)) {
659 NomenclaturalStatus nomStatus
;
660 int index
= ((Integer
) value
).intValue();
661 Set
<NomenclaturalStatus
> nomStatusSet
= name
.getStatus();
663 if (nomStatusSet
.size() > 0) {
664 nomStatus
= (NomenclaturalStatus
) nomStatusSet
.toArray()[0];
667 nomStatusSet
.remove(nomStatus
);
669 nomStatus
.setType(nomStatusTypes
[index
]);
673 nomStatus
= NomenclaturalStatus
.NewInstance(nomStatusTypes
[index
]);
674 name
.addStatus(nomStatus
);
677 if (id
.equals(P_ID_MARKERS
)) {
680 if (id
.equals(P_ID_NOMENCLATURAL_REF
)) {
681 // TODO ask Andreas M. how best to set nom. ref
683 if (id
.equals(P_ID_NOMENCLATURAL_MICROREF
)) {
684 name
.setNomenclaturalMicroReference((String
) value
);
686 if (id
.equals(P_ID_NOMREF_YEAR
)) {
687 INomenclaturalReference reference
= name
.getNomenclaturalReference();
689 if (reference
instanceof BibtexReference
) {
690 ((BibtexReference
) reference
).setYear((String
) value
);
692 TimePeriod datePublished
= CdmUtil
.getDatePublished((String
) value
);
693 if (reference
instanceof Article
) {
694 ((Article
) reference
).setDatePublished(datePublished
);
696 if (reference
instanceof Book
) {
697 ((Book
) reference
).setDatePublished(datePublished
);
699 if (reference
instanceof BookSection
) {
700 ((BookSection
) reference
).setDatePublished(datePublished
);
702 if (reference
instanceof Generic
) {
703 ((Generic
) reference
).setDatePublished(datePublished
);
706 if (id
.equals(P_ID_NOMREF_TITLE
)) {
707 INomenclaturalReference reference
= name
.getNomenclaturalReference();
709 if (reference
instanceof BibtexReference
) {
710 ((BibtexReference
) reference
).setTitle((String
) value
);
712 if (reference
instanceof Article
) {
713 ((Article
) reference
).setTitle((String
) value
);
715 if (reference
instanceof Book
) {
716 ((Book
) reference
).setTitle((String
) value
);
718 if (reference
instanceof BookSection
) {
719 ((BookSection
) reference
).setTitle((String
) value
);
721 if (reference
instanceof Generic
) {
722 ((Generic
) reference
).setTitle((String
) value
);
726 // Reset both caches to reflect property sheet changes
727 name
.setTitleCache(name
.generateTitle(), false);
728 name
.setFullTitleCache(name
.generateFullTitle(), false);
730 name
.firePropertyChange(ITaxEditorConstants
.REFRESH_NAMEVIEWER
, null, null);
734 * Any node with children must override {@link java.lang.Object#toString()}
735 * to display its name correctly
737 * @see java.lang.Object#toString()
739 public String
toString() {
740 if (parentid
== null || parentid
.equals("")) {
743 if (parentid
.equals(P_ID_TITLECACHE
)) {
744 return name
.getTitleCache();
746 if (parentid
.equals(P_ID_NOMENCLATURAL_REF
)) {
747 INomenclaturalReference nomenclaturalReference
= name
.getNomenclaturalReference();
748 if (nomenclaturalReference
== null) {
751 String microReference
= name
.getNomenclaturalMicroReference();
752 return CdmUtils
.Nz(nomenclaturalReference
.getNomenclaturalCitation(microReference
));
754 return super.toString();
757 public void addPropertyChangeListener(
758 PropertyChangeListener listener
) {
759 this.propertyChangeSupport
.addPropertyChangeListener(listener
);