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
.description
;
12 import java
.beans
.PropertyChangeEvent
;
13 import java
.beans
.PropertyChangeListener
;
14 import java
.util
.HashMap
;
16 import java
.util
.Vector
;
18 import org
.apache
.log4j
.Logger
;
19 import org
.eclipse
.ui
.views
.properties
.ComboBoxPropertyDescriptor
;
20 import org
.eclipse
.ui
.views
.properties
.IPropertyDescriptor
;
21 import org
.eclipse
.ui
.views
.properties
.IPropertySource
;
22 import org
.eclipse
.ui
.views
.properties
.PropertyDescriptor
;
23 import org
.eclipse
.ui
.views
.properties
.TextPropertyDescriptor
;
25 import eu
.etaxonomy
.cdm
.common
.CdmUtils
;
26 import eu
.etaxonomy
.cdm
.model
.description
.CommonTaxonName
;
27 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
28 import eu
.etaxonomy
.cdm
.model
.description
.Distribution
;
29 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
30 import eu
.etaxonomy
.cdm
.model
.description
.IndividualsAssociation
;
31 import eu
.etaxonomy
.cdm
.model
.description
.QuantitativeData
;
32 import eu
.etaxonomy
.cdm
.model
.description
.TaxonInteraction
;
33 import eu
.etaxonomy
.cdm
.model
.description
.TextData
;
34 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceBase
;
35 import eu
.etaxonomy
.taxeditor
.propertysheet
.reference
.ReferencePropertySource
;
36 import eu
.etaxonomy
.taxeditor
.store
.model
.DescriptionUtil
;
37 import eu
.etaxonomy
.taxeditor
.store
.model
.ReferenceUtil
;
44 public class DescriptionElementPropertySource
implements IPropertySource
{
45 private static final Logger logger
= Logger
46 .getLogger(DescriptionElementPropertySource
.class);
49 * The DescriptionElement whose properties are being displayed
51 private DescriptionElementBase descriptionElement
;
54 * If this is a property with a parent, the parent's property ID
56 private String parentid
;
59 * Property unique keys
61 public static final String P_ID_ELEMENT_CLASS
= "element_class";
62 public static final String P_ID_ELEMENT_TEXT
= "text";
63 public static final String P_ID_FEATURE
= "feature";
64 public static final String P_ID_BIBREF
= "bibref";
65 public static final String P_ID_MICROREF
= "microref";
68 * Property display keys
70 public static final String P_ELEMENT_CLASS
= "Save element as";
71 public static final String P_ELEMENT_TEXT
= "Element";
72 public static final String P_FEATURE
= "Feature";
73 public static final String P_BIBREF
= "Bibliographic Reference";
74 public static final String P_MICROREF
= "Reference Detail";
76 protected static final String
[] TOP_LEVEL_PROPERTIES
= new String
[] {
82 private String
[] P_FEATURE_CLASS_NAME_MENU
;
83 private Class
[] P_FEATURE_CLASSES
;
86 * Constructor for top level property fields. All fields that are not subfields
87 * should be listed here.
90 public DescriptionElementPropertySource(DescriptionElementBase descriptionElement
) {
91 this(descriptionElement
, null, TOP_LEVEL_PROPERTIES
);
94 public DescriptionElementPropertySource(DescriptionElementBase descriptionElement
, String parentid
,
96 this.descriptionElement
= descriptionElement
;
97 this.parentid
= parentid
;
98 for (String key
: keys
) {
103 protected Vector
<PropertyDescriptor
> descriptors
= new Vector
<PropertyDescriptor
>();
105 * Add descriptor for a given property.
107 * Notes on Descriptor:
109 * PropertyDescriptor - uneditable cell value
110 * ComboBoxPropertyDescriptor - dropdown list, property supplied must be integer-based
111 * TextPropertyDescriptor - editable cell value
113 * If any descriptor calls setCategory, all descriptors w/out a category are put in
116 * descriptor.setFilterFlags (new String[] { IPropertySheetEntry.FILTER_ID_EXPERT }) -
117 * this descriptor shown under advanced properties
121 protected void addDescriptor(String id
) {
122 if (id
.equals(P_ID_ELEMENT_CLASS
)) {
124 Feature feature
= descriptionElement
.getFeature();
125 Map
<Class
, String
> supportedClasses
= new HashMap
<Class
, String
>();
127 // Populate feature class arrays with classes supported by this feature
128 if (feature
.supportsCommonTaxonName()) {
129 supportedClasses
.put(CommonTaxonName
.class, "Common name");
131 if (feature
.supportsDistribution()) {
132 supportedClasses
.put(Distribution
.class, "Distribution");
134 if (feature
.supportsIndividualAssociation()) {
135 supportedClasses
.put(IndividualsAssociation
.class, "Individual association");
137 if (feature
.supportsQuantitativeData()) {
138 supportedClasses
.put(QuantitativeData
.class, "Quantitative data");
140 if (feature
.supportsTaxonInteraction()) {
141 supportedClasses
.put(TaxonInteraction
.class, "Taxon interaction");
143 if (feature
.supportsTextData()) {
144 supportedClasses
.put(TextData
.class, "Text");
147 P_FEATURE_CLASS_NAME_MENU
= supportedClasses
.values().toArray((new String
[supportedClasses
.size()]));
148 P_FEATURE_CLASSES
= supportedClasses
.keySet().toArray(new Class
[supportedClasses
.size()]);
150 descriptors
.addElement(
151 new ComboBoxPropertyDescriptor(P_ID_ELEMENT_CLASS
, P_ELEMENT_CLASS
, P_FEATURE_CLASS_NAME_MENU
)
155 if (id
.equals(P_ID_FEATURE
)) {
156 descriptors
.addElement(new PropertyDescriptor(P_ID_FEATURE
, P_FEATURE
));
159 if (id
.equals(P_ID_BIBREF
)) {
160 descriptors
.addElement(new PropertyDescriptor(P_ID_BIBREF
, P_BIBREF
));
163 if (id
.equals(P_ID_ELEMENT_TEXT
)) {
164 descriptors
.addElement(new TextPropertyDescriptor(P_ID_ELEMENT_TEXT
, P_ELEMENT_TEXT
));
167 if (id
.equals(P_ID_MICROREF
)) {
168 descriptors
.addElement(new TextPropertyDescriptor(P_ID_MICROREF
, P_MICROREF
));
173 * @see org.eclipse.ui.views.properties.IPropertySource#getEditableValue()
175 public Object
getEditableValue() {
180 * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyDescriptors()
182 public IPropertyDescriptor
[] getPropertyDescriptors() {
183 return (IPropertyDescriptor
[]) descriptors
.toArray(
184 new IPropertyDescriptor
[descriptors
.size()]);
188 * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyValue(java.lang.Object)
190 public Object
getPropertyValue(Object id
) {
191 if (id
.equals(P_ID_ELEMENT_CLASS
)) {
192 if (descriptionElement
instanceof TextData
) {
195 if (descriptionElement
instanceof CommonTaxonName
) {
198 if (descriptionElement
instanceof Distribution
) {
203 if (id
.equals(P_ID_FEATURE
)) {
204 Feature feature
= descriptionElement
.getFeature();
205 if (feature
!= null) {
206 return feature
.getLabel();
212 if (id
.equals(P_ID_BIBREF
)) {
213 ReferenceBase citation
= descriptionElement
.getCitation();
214 ReferencePropertySource bibRefPropertySource
= new ReferencePropertySource(citation
);
215 bibRefPropertySource
.addPropertyChangeListener(new PropertyChangeListener() {
216 public void propertyChange(PropertyChangeEvent evt
) {
217 descriptionElement
.setCitation((ReferenceBase
) evt
.getNewValue());
220 return bibRefPropertySource
;
223 if (id
.equals(P_ID_ELEMENT_TEXT
)) {
224 return DescriptionUtil
.getCache(descriptionElement
);
227 if (id
.equals(P_ID_MICROREF
)) {
228 return CdmUtils
.Nz(descriptionElement
.getCitationMicroReference());
235 * @see org.eclipse.ui.views.properties.IPropertySource#isPropertySet(java.lang.Object)
237 public boolean isPropertySet(Object id
) {
242 * @see org.eclipse.ui.views.properties.IPropertySource#resetPropertyValue(java.lang.Object)
244 public void resetPropertyValue(Object id
) {}
247 * @see org.eclipse.ui.views.properties.IPropertySource#setPropertyValue(java.lang.Object, java.lang.Object)
249 public void setPropertyValue(Object id
, Object value
) {
250 if (id
.equals(P_ID_ELEMENT_CLASS
)) {
254 if (id
.equals(P_ID_BIBREF
)) {
255 if (value
instanceof ReferenceBase
) {
256 descriptionElement
.setCitation((ReferenceBase
) value
);
260 if (id
.equals(P_ID_ELEMENT_TEXT
)) {
261 DescriptionUtil
.setCache(descriptionElement
, (String
) value
);
264 if (id
.equals(P_ID_MICROREF
)) {
265 descriptionElement
.setCitationMicroReference((String
) value
);
268 // descriptionElement.firePropertyChange(ITaxEditorConstants.PROPERTY_SHEET_CHANGE, null, null);
274 public DescriptionElementBase
getDescriptionElement() {
275 return descriptionElement
;