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
;
15 import java
.util
.Vector
;
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
;
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
.ReferencePropertySource
;
39 import eu
.etaxonomy
.taxeditor
.propertysheet
.reference
.ReferenceSearchDescriptor
;
40 import eu
.etaxonomy
.taxeditor
.propertysheet
.type
.TypeCollectionPropertySource
;
41 import eu
.etaxonomy
.taxeditor
.propertysheet
.type
.TypePropertyDescriptor
;
48 public class TaxonBasePropertySource
implements ICdmBasePropertySource
{
49 private static final Logger logger
= Logger
50 .getLogger(TaxonBasePropertySource
.class);
52 private TaxonBase
<?
> taxonBase
;
54 // Property unique keys
55 public static final String P_ID_TAXONNAME
= "P_ID_TAXONNAME";
56 public static final String P_ID_TAXONSEC
= "P_ID_TAXONSEC";
57 public static final String P_ID_TYPES
= "P_ID_TYPES";
58 public static final String P_ID_DOUBTFUL
= "P_ID_DOUBTFUL";
59 public static final String P_ID_TAXON_MARKERS
= "P_ID_TAXON_MARKERS";
60 public static final String P_ID_EXTENSIONS
= "P_ID_EXTENSIONS";
61 public static final String P_ID_TAXON_ANNOTATIONS
= "P_ID_TAXON_ANNOTATIONS";
63 // Property display keys
64 public String P_TAXONNAME
;
65 public static final String P_TAXONSEC
= "Secundum";
66 public String P_TYPES
= "Name Types";
67 public static final String P_DOUBTFUL
= "Doubtful?";
68 public static final String P_TAXON_MARKERS
= "Markers";
69 public static final String P_EXTENSIONS
= "Extensions";
70 public static final String P_TAXON_ANNOTATIONS
= "Annotations";
72 private static final int NOT_DOUBTFUL
= 0;
73 private static final int DOUBTFUL
= 1;
75 public TaxonBasePropertySource(TaxonBase
<?
> taxon
, String nameTitle
) {
76 this.taxonBase
= taxon
;
78 this.P_TAXONNAME
= nameTitle
;
80 if (taxon
!= null && taxon
.getName() != null &&
81 !taxon
.getName().isSupraSpecific()) {
82 P_TYPES
= "Specimen Types";
85 addDescriptor(P_ID_TAXONNAME
);
86 addDescriptor(P_ID_TAXONSEC
);
87 addDescriptor(P_ID_TYPES
);
88 addDescriptor(P_ID_DOUBTFUL
);
89 addDescriptor(P_ID_TAXON_ANNOTATIONS
);
90 addDescriptor(P_ID_TAXON_MARKERS
);
91 addDescriptor(P_ID_EXTENSIONS
);
94 protected Vector
<PropertyDescriptor
> descriptors
= new Vector
<PropertyDescriptor
>();
96 protected void addDescriptor(String id
) {
97 if (id
.equals(P_ID_TAXONNAME
)) {
98 descriptors
.addElement(
99 new PropertyDescriptor(P_ID_TAXONNAME
, P_TAXONNAME
));
101 if (id
.equals(P_ID_TAXONSEC
)) {
102 descriptors
.addElement(new ReferenceSearchDescriptor(P_ID_TAXONSEC
, P_TAXONSEC
, taxonBase
.getSec()) {
103 protected void saveReference(ReferenceBase reference
) {
104 setPropertyValue(P_ID_TAXONSEC
, reference
);
108 if (id
.equals(P_ID_TYPES
)) {
109 descriptors
.addElement(
110 new TypePropertyDescriptor(P_ID_TYPES
, P_TYPES
, taxonBase
.getName()) {
111 protected void saveTypes(Set set
) {
112 setPropertyValue(P_ID_TYPES
, set
);
118 if (id
.equals(P_ID_DOUBTFUL
)) {
119 descriptors
.addElement(
120 new ComboBoxPropertyDescriptor(P_ID_DOUBTFUL
, P_DOUBTFUL
,
121 new String
[] {"no", "yes"}));
124 if (id
.equals(P_ID_TAXON_MARKERS
)) {
125 descriptors
.addElement(
126 new MarkersPropertyDescriptor(P_ID_TAXON_MARKERS
, P_TAXON_MARKERS
, taxonBase
));
129 if (id
.equals(P_ID_EXTENSIONS
)) {
130 descriptors
.addElement(
131 new ExtensionsPropertyDescriptor(P_ID_EXTENSIONS
, P_EXTENSIONS
, taxonBase
));
134 // Annotations, listed in custom property descriptor
135 if (id
.equals(P_ID_TAXON_ANNOTATIONS
)) {
136 descriptors
.addElement(
137 new AnnotationsPropertyDescriptor(P_ID_TAXON_ANNOTATIONS
, P_TAXON_ANNOTATIONS
, taxonBase
) {
138 protected void saveAnnotations(Set set
) {
139 setPropertyValue(P_ID_TAXON_ANNOTATIONS
, set
);
147 * @see org.eclipse.ui.views.properties.IPropertySource#getEditableValue()
149 public Object
getEditableValue() {
154 * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyDescriptors()
156 public IPropertyDescriptor
[] getPropertyDescriptors() {
157 return (IPropertyDescriptor
[]) descriptors
.toArray(
158 new IPropertyDescriptor
[descriptors
.size()]);
162 * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyValue(java.lang.Object)
164 public Object
getPropertyValue(Object id
) {
167 if (id
.equals(P_ID_TAXONNAME
)) {
169 if (taxonBase
== null) {
170 logger
.warn("no taxon");
173 TaxonNameBase
<?
, ?
> name
= taxonBase
.getName();
175 // Create taxon name as necessary
177 name
= NonViralName
.NewInstance(Rank
.SPECIES());
179 name
= CdmBase
.deproxy(name
, TaxonNameBase
.class);
180 // Send taxon name to appropriate property source for submenu
181 if (name
instanceof BotanicalName
) {
182 return new BotanicalNamePropertySource((BotanicalName
) name
);
184 if (name
instanceof ZoologicalName
) {
185 return new ZoologicalNamePropertySource((ZoologicalName
) name
);
187 if (name
instanceof NonViralName
) {
188 return new NonViralNamePropertySource((NonViralName
<?
>) name
);
193 // Edit taxon's sec. reference
194 if (id
.equals(P_ID_TAXONSEC
)) {
196 if (taxonBase
== null) {
199 ReferenceBase
<?
> sec
= taxonBase
.getSec();
201 // Create property source for submenu
202 ReferencePropertySource secPropertySource
= new ReferencePropertySource(sec
);
204 // Add listener to notify taxon of all changes to sec
205 secPropertySource
.addPropertyChangeListener(new PropertyChangeListener() {
206 public void propertyChange(PropertyChangeEvent evt
) {
207 if (evt
.getNewValue() instanceof ReferenceBase
) {
208 taxonBase
.setSec((ReferenceBase
<?
>) evt
.getNewValue());
212 return secPropertySource
;
215 if (id
.equals(P_ID_TYPES
)) {
216 if (taxonBase
.getName() != null) {
217 // TODO return NameTypeDesignations
218 TaxonNameBase
<?
, ?
> name
= taxonBase
.getName();
219 Set
<?
> typeDesignations
= null;
220 if (name
.isSupraSpecific()) {
221 typeDesignations
= name
.getNameTypeDesignations();
223 typeDesignations
= name
.getSpecimenTypeDesignations();
225 return new TypeCollectionPropertySource(name
, typeDesignations
);
229 // Edit doubtful flag
230 if (id
.equals(P_ID_DOUBTFUL
)) {
231 if (taxonBase
.isDoubtful()) {
238 if (id
.equals(P_ID_TAXON_MARKERS
)) {
239 return new MarkerPropertySource(taxonBase
);
242 if (id
.equals(P_ID_EXTENSIONS
)) {
243 return new ExtensionPropertySource(taxonBase
);
246 if (id
.equals(P_ID_TAXON_ANNOTATIONS
)) {
247 return new AnnotationPropertySource(taxonBase
);
254 * @see org.eclipse.ui.views.properties.IPropertySource#isPropertySet(java.lang.Object)
256 public boolean isPropertySet(Object id
) {
261 * @see org.eclipse.ui.views.properties.IPropertySource#resetPropertyValue(java.lang.Object)
263 public void resetPropertyValue(Object id
) {}
266 * @see org.eclipse.ui.views.properties.IPropertySource#setPropertyValue(java.lang.Object, java.lang.Object)
268 public void setPropertyValue(Object id
, Object value
) {
269 if (id
.equals(P_ID_TAXONSEC
)) {
270 if (value
instanceof ReferenceBase
) {
271 taxonBase
.setSec((ReferenceBase
<?
>) value
);
275 if (id
.equals(P_ID_DOUBTFUL
)) {
276 if (((Integer
) value
).intValue() == DOUBTFUL
) {
277 taxonBase
.setDoubtful(true);
279 taxonBase
.setDoubtful(false);
285 * @return the taxonBase
287 public TaxonBase
<?
> getTaxonBase() {