1) Added import / export dummy functionality (i.e. CDM library not yet functional...
[taxeditor.git] / eclipseprojects / eu.etaxonomy.taxeditor / src / eu / etaxonomy / taxeditor / propertysheet / name / TaxonBasePropertySource.java
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.Vector;
15
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;
20
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;
30
31 /**
32 * @author p.ciardelli
33 * @created 11.11.2008
34 * @version 1.0
35 */
36 public class TaxonBasePropertySource implements IPropertySource {
37 private static final Logger logger = Logger
38 .getLogger(TaxonBasePropertySource.class);
39
40 private TaxonBase taxon;
41
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";
45
46 // Property display keys
47 public static final String P_TAXONNAME = "00:Misapplied Name";
48 public static final String P_TAXONSEC = "01:Sec";
49
50 public TaxonBasePropertySource(TaxonBase taxon) {
51 this.taxon = taxon;
52
53 addDescriptor(P_ID_TAXONNAME);
54 addDescriptor(P_ID_TAXONSEC);
55 }
56
57 protected Vector<PropertyDescriptor> descriptors = new Vector<PropertyDescriptor>();
58
59 protected void addDescriptor(String id) {
60 if (id.equals(P_ID_TAXONNAME)) {
61 descriptors.addElement(
62 new PropertyDescriptor(P_ID_TAXONNAME, P_TAXONNAME));
63 }
64
65 if (id.equals(P_ID_TAXONSEC)) {
66 descriptors.addElement(
67 new PropertyDescriptor(P_ID_TAXONSEC, P_TAXONSEC));
68 }
69 }
70
71 /* (non-Javadoc)
72 * @see org.eclipse.ui.views.properties.IPropertySource#getEditableValue()
73 */
74 public Object getEditableValue() {
75 return null;
76 }
77
78 /* (non-Javadoc)
79 * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyDescriptors()
80 */
81 public IPropertyDescriptor[] getPropertyDescriptors() {
82 return (IPropertyDescriptor[]) descriptors.toArray(
83 new IPropertyDescriptor[descriptors.size()]);
84 }
85
86 /* (non-Javadoc)
87 * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyValue(java.lang.Object)
88 */
89 public Object getPropertyValue(Object id) {
90
91 // Edit taxon's name
92 if (id.equals(P_ID_TAXONNAME)) {
93
94 TaxonNameBase name = taxon.getName();
95
96 // Create taxon name as necessary
97 if (name == null) {
98 name = NonViralName.NewInstance(Rank.SPECIES());
99 }
100
101 // Send taxon name to appropriate property source for submenu
102 if (name instanceof BotanicalName) {
103 return new BotanicalNamePropertySource((BotanicalName) name);
104 }
105 if (name instanceof ZoologicalName) {
106 return new ZoologicalNamePropertySource((ZoologicalName) name);
107 }
108 if (name instanceof NonViralName) {
109 return new NonViralNamePropertySource((NonViralName) name);
110 }
111
112 }
113
114 // Edit taxon's sec. reference
115 if (id.equals(P_ID_TAXONSEC)) {
116
117 ReferenceBase sec = taxon.getSec();
118
119 // Create sec reference as necessary
120 if (sec == null) {
121 sec = Generic.NewInstance();
122 }
123
124 // Create property source for submenu
125 ReferencePropertySource secPropertySource = new ReferencePropertySource(sec);
126
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());
132 }
133 }
134 });
135 return secPropertySource;
136 }
137
138 return null;
139 }
140
141 /* (non-Javadoc)
142 * @see org.eclipse.ui.views.properties.IPropertySource#isPropertySet(java.lang.Object)
143 */
144 public boolean isPropertySet(Object id) {
145 return false;
146 }
147
148 /* (non-Javadoc)
149 * @see org.eclipse.ui.views.properties.IPropertySource#resetPropertyValue(java.lang.Object)
150 */
151 public void resetPropertyValue(Object id) {}
152
153 /* (non-Javadoc)
154 * @see org.eclipse.ui.views.properties.IPropertySource#setPropertyValue(java.lang.Object, java.lang.Object)
155 */
156 public void setPropertyValue(Object id, Object value) {
157 // All setting done in submenus
158 }
159 }