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
.IPropertyDescriptor
;
19 import org
.eclipse
.ui
.views
.properties
.IPropertySource
;
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
.propertysheet
.reference
.IReferenceSearch
;
31 import eu
.etaxonomy
.taxeditor
.propertysheet
.reference
.ReferencePropertySource
;
32 import eu
.etaxonomy
.taxeditor
.propertysheet
.reference
.ReferenceSearchDescriptor
;
33 import eu
.etaxonomy
.taxeditor
.propertysheet
.type
.TypeCollectionPropertySource
;
34 import eu
.etaxonomy
.taxeditor
.propertysheet
.type
.TypePropertyDescriptor
;
35 import eu
.etaxonomy
.taxeditor
.store
.model
.NameUtil
;
42 public class TaxonBasePropertySource
implements IPropertySource
{
43 private static final Logger logger
= Logger
44 .getLogger(TaxonBasePropertySource
.class);
46 private TaxonBase
<?
> taxonBase
;
48 // Property unique keys
49 public static final String P_ID_TAXONNAME
= "P_ID_TAXONNAME";
50 public static final String P_ID_TAXONSEC
= "P_ID_TAXONSEC";
51 public static final String P_ID_TYPES
= "P_ID_TYPES";
53 // Property display keys
54 public String P_TAXONNAME
;
55 public static final String P_TAXONSEC
= "Secundum";
56 public String P_TYPES
= "Name Types";
58 public TaxonBasePropertySource(TaxonBase
<?
> taxon
, String nameTitle
) {
59 this.taxonBase
= taxon
;
61 this.P_TAXONNAME
= nameTitle
;
63 if (taxon
!= null && taxon
.getName() != null &&
64 !NameUtil
.isNameSupraSpecific(taxon
.getName())) {
65 P_TYPES
= "Specimen Types";
68 addDescriptor(P_ID_TAXONNAME
);
69 addDescriptor(P_ID_TAXONSEC
);
70 addDescriptor(P_ID_TYPES
);
73 protected Vector
<PropertyDescriptor
> descriptors
= new Vector
<PropertyDescriptor
>();
75 protected void addDescriptor(String id
) {
76 if (id
.equals(P_ID_TAXONNAME
)) {
77 descriptors
.addElement(
78 new PropertyDescriptor(P_ID_TAXONNAME
, P_TAXONNAME
));
80 if (id
.equals(P_ID_TAXONSEC
)) {
81 descriptors
.addElement(new ReferenceSearchDescriptor(P_ID_TAXONSEC
, P_TAXONSEC
, IReferenceSearch
.BIBREF
) {
82 protected void saveReference(ReferenceBase reference
) {
83 setPropertyValue(P_ID_TAXONSEC
, reference
);
87 if (id
.equals(P_ID_TYPES
)) {
88 descriptors
.addElement(
89 new TypePropertyDescriptor(P_ID_TYPES
, P_TYPES
, taxonBase
.getName()) {
90 protected void saveTypes(Set set
) {
91 setPropertyValue(P_ID_TYPES
, set
);
99 * @see org.eclipse.ui.views.properties.IPropertySource#getEditableValue()
101 public Object
getEditableValue() {
106 * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyDescriptors()
108 public IPropertyDescriptor
[] getPropertyDescriptors() {
109 return (IPropertyDescriptor
[]) descriptors
.toArray(
110 new IPropertyDescriptor
[descriptors
.size()]);
114 * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyValue(java.lang.Object)
116 public Object
getPropertyValue(Object id
) {
119 if (id
.equals(P_ID_TAXONNAME
)) {
121 if (taxonBase
== null) {
122 logger
.warn("no taxon");
125 TaxonNameBase
<?
, ?
> name
= taxonBase
.getName();
127 // Create taxon name as necessary
129 name
= NonViralName
.NewInstance(Rank
.SPECIES());
131 name
= CdmBase
.deproxy(name
, TaxonNameBase
.class);
132 // Send taxon name to appropriate property source for submenu
133 if (name
instanceof BotanicalName
) {
134 return new BotanicalNamePropertySource((BotanicalName
) name
);
136 if (name
instanceof ZoologicalName
) {
137 return new ZoologicalNamePropertySource((ZoologicalName
) name
);
139 if (name
instanceof NonViralName
) {
140 return new NonViralNamePropertySource((NonViralName
<?
>) name
);
145 // Edit taxon's sec. reference
146 if (id
.equals(P_ID_TAXONSEC
)) {
148 if (taxonBase
== null) {
151 ReferenceBase
<?
> sec
= taxonBase
.getSec();
153 // Create property source for submenu
154 ReferencePropertySource secPropertySource
= new ReferencePropertySource(sec
);
156 // Add listener to notify taxon of all changes to sec
157 secPropertySource
.addPropertyChangeListener(new PropertyChangeListener() {
158 public void propertyChange(PropertyChangeEvent evt
) {
159 if (evt
.getNewValue() instanceof ReferenceBase
) {
160 taxonBase
.setSec((ReferenceBase
<?
>) evt
.getNewValue());
164 return secPropertySource
;
167 if (id
.equals(P_ID_TYPES
)) {
168 if (taxonBase
.getName() != null) {
169 // TODO return NameTypeDesignations
170 TaxonNameBase
<?
, ?
> name
= taxonBase
.getName();
171 Set
<?
> typeDesignations
= null;
172 if (NameUtil
.isNameSupraSpecific(name
)) {
173 typeDesignations
= name
.getNameTypeDesignations();
175 typeDesignations
= name
.getSpecimenTypeDesignations();
177 return new TypeCollectionPropertySource(name
, typeDesignations
);
185 * @see org.eclipse.ui.views.properties.IPropertySource#isPropertySet(java.lang.Object)
187 public boolean isPropertySet(Object id
) {
192 * @see org.eclipse.ui.views.properties.IPropertySource#resetPropertyValue(java.lang.Object)
194 public void resetPropertyValue(Object id
) {}
197 * @see org.eclipse.ui.views.properties.IPropertySource#setPropertyValue(java.lang.Object, java.lang.Object)
199 public void setPropertyValue(Object id
, Object value
) {
200 if (id
.equals(P_ID_TAXONSEC
)) {
201 if (value
instanceof ReferenceBase
) {
202 taxonBase
.setSec((ReferenceBase
<?
>) value
);
208 * @return the taxonBase
210 public TaxonBase
<?
> getTaxonBase() {