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
.util
.Vector
;
16 import org
.apache
.log4j
.Logger
;
17 import org
.eclipse
.ui
.views
.properties
.IPropertyDescriptor
;
18 import org
.eclipse
.ui
.views
.properties
.IPropertySource
;
19 import org
.eclipse
.ui
.views
.properties
.PropertyDescriptor
;
21 import eu
.etaxonomy
.cdm
.model
.name
.BotanicalName
;
22 import eu
.etaxonomy
.cdm
.model
.name
.NonViralName
;
23 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
24 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
25 import eu
.etaxonomy
.cdm
.model
.name
.ZoologicalName
;
26 import eu
.etaxonomy
.cdm
.model
.reference
.Generic
;
27 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceBase
;
28 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
29 import eu
.etaxonomy
.taxeditor
.propertysheet
.reference
.ReferencePropertySource
;
36 public class TaxonBasePropertySource
implements IPropertySource
{
37 private static final Logger logger
= Logger
38 .getLogger(TaxonBasePropertySource
.class);
40 private TaxonBase taxon
;
42 // Property unique keys
43 public static final String P_ID_TAXONNAME
= "P_ID_TAXONNAME";
44 public static final String P_ID_TAXONSEC
= "P_ID_TAXONSEC";
46 // Property display keys
47 public static final String P_TAXONNAME
= "00:Misapplied Name";
48 public static final String P_TAXONSEC
= "01:Sec";
50 public TaxonBasePropertySource(TaxonBase taxon
) {
53 addDescriptor(P_ID_TAXONNAME
);
54 addDescriptor(P_ID_TAXONSEC
);
57 protected Vector
<PropertyDescriptor
> descriptors
= new Vector
<PropertyDescriptor
>();
59 protected void addDescriptor(String id
) {
60 if (id
.equals(P_ID_TAXONNAME
)) {
61 descriptors
.addElement(
62 new PropertyDescriptor(P_ID_TAXONNAME
, P_TAXONNAME
));
65 if (id
.equals(P_ID_TAXONSEC
)) {
66 descriptors
.addElement(
67 new PropertyDescriptor(P_ID_TAXONSEC
, P_TAXONSEC
));
72 * @see org.eclipse.ui.views.properties.IPropertySource#getEditableValue()
74 public Object
getEditableValue() {
79 * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyDescriptors()
81 public IPropertyDescriptor
[] getPropertyDescriptors() {
82 return (IPropertyDescriptor
[]) descriptors
.toArray(
83 new IPropertyDescriptor
[descriptors
.size()]);
87 * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyValue(java.lang.Object)
89 public Object
getPropertyValue(Object id
) {
92 if (id
.equals(P_ID_TAXONNAME
)) {
94 TaxonNameBase name
= taxon
.getName();
96 // Create taxon name as necessary
98 name
= NonViralName
.NewInstance(Rank
.SPECIES());
101 // Send taxon name to appropriate property source for submenu
102 if (name
instanceof BotanicalName
) {
103 return new BotanicalNamePropertySource((BotanicalName
) name
);
105 if (name
instanceof ZoologicalName
) {
106 return new ZoologicalNamePropertySource((ZoologicalName
) name
);
108 if (name
instanceof NonViralName
) {
109 return new NonViralNamePropertySource((NonViralName
) name
);
114 // Edit taxon's sec. reference
115 if (id
.equals(P_ID_TAXONSEC
)) {
117 ReferenceBase sec
= taxon
.getSec();
119 // Create sec reference as necessary
121 sec
= Generic
.NewInstance();
124 // Create property source for submenu
125 ReferencePropertySource secPropertySource
= new ReferencePropertySource(sec
);
127 // Add listener to notify taxon of all changes to sec
128 secPropertySource
.addPropertyChangeListener(new PropertyChangeListener() {
129 public void propertyChange(PropertyChangeEvent evt
) {
130 if (evt
.getNewValue() instanceof ReferenceBase
) {
131 taxon
.setSec((ReferenceBase
) evt
.getNewValue());
135 return secPropertySource
;
142 * @see org.eclipse.ui.views.properties.IPropertySource#isPropertySet(java.lang.Object)
144 public boolean isPropertySet(Object id
) {
149 * @see org.eclipse.ui.views.properties.IPropertySource#resetPropertyValue(java.lang.Object)
151 public void resetPropertyValue(Object id
) {}
154 * @see org.eclipse.ui.views.properties.IPropertySource#setPropertyValue(java.lang.Object, java.lang.Object)
156 public void setPropertyValue(Object id
, Object value
) {
157 // All setting done in submenus