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
.eclipse
.ui
.views
.properties
.ComboBoxPropertyDescriptor
;
19 import org
.eclipse
.ui
.views
.properties
.IPropertyDescriptor
;
20 import org
.eclipse
.ui
.views
.properties
.IPropertySource
;
21 import org
.eclipse
.ui
.views
.properties
.PropertyDescriptor
;
22 import org
.eclipse
.ui
.views
.properties
.TextPropertyDescriptor
;
24 import eu
.etaxonomy
.cdm
.common
.CdmUtils
;
25 import eu
.etaxonomy
.cdm
.model
.description
.CommonTaxonName
;
26 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
27 import eu
.etaxonomy
.cdm
.model
.description
.Distribution
;
28 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
29 import eu
.etaxonomy
.cdm
.model
.description
.IndividualsAssociation
;
30 import eu
.etaxonomy
.cdm
.model
.description
.QuantitativeData
;
31 import eu
.etaxonomy
.cdm
.model
.description
.TaxonInteraction
;
32 import eu
.etaxonomy
.cdm
.model
.description
.TextData
;
33 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceBase
;
34 import eu
.etaxonomy
.taxeditor
.propertysheet
.reference
.ReferencePropertySource
;
35 import eu
.etaxonomy
.taxeditor
.store
.model
.DescriptionUtil
;
42 public class DescriptionElementPropertySource
implements IPropertySource
{
45 * The DescriptionElement whose properties are being displayed
47 private DescriptionElementBase descriptionElement
;
50 * If this is a property with a parent, the parent's property ID
52 private String parentid
;
55 * Property unique keys
57 public static final String P_ID_ELEMENT_CLASS
= "element_class";
58 public static final String P_ID_ELEMENT_TEXT
= "text";
59 public static final String P_ID_FEATURE
= "feature";
60 public static final String P_ID_BIBREF
= "bibref";
61 public static final String P_ID_MICROREF
= "microref";
64 * Property display keys
66 public static final String P_ELEMENT_CLASS
= "Save element as";
67 public static final String P_ELEMENT_TEXT
= "Element";
68 public static final String P_FEATURE
= "Feature";
69 public static final String P_BIBREF
= "Bibliographic Reference";
70 public static final String P_MICROREF
= "Reference Detail";
72 protected static final String
[] TOP_LEVEL_PROPERTIES
= new String
[] {
78 private String
[] P_FEATURE_CLASS_NAME_MENU
;
81 * Constructor for top level property fields. All fields that are not subfields
82 * should be listed here.
85 public DescriptionElementPropertySource(DescriptionElementBase descriptionElement
) {
86 this(descriptionElement
, null, TOP_LEVEL_PROPERTIES
);
89 public DescriptionElementPropertySource(DescriptionElementBase descriptionElement
, String parentid
,
91 this.descriptionElement
= descriptionElement
;
92 this.setParentid(parentid
);
93 for (String key
: keys
) {
98 protected Vector
<PropertyDescriptor
> descriptors
= new Vector
<PropertyDescriptor
>();
100 * Add descriptor for a given property.
102 * Notes on Descriptor:
104 * PropertyDescriptor - uneditable cell value
105 * ComboBoxPropertyDescriptor - dropdown list, property supplied must be integer-based
106 * TextPropertyDescriptor - editable cell value
108 * If any descriptor calls setCategory, all descriptors w/out a category are put in
111 * descriptor.setFilterFlags (new String[] { IPropertySheetEntry.FILTER_ID_EXPERT }) -
112 * this descriptor shown under advanced properties
116 protected void addDescriptor(String id
) {
117 if (id
.equals(P_ID_ELEMENT_CLASS
)) {
119 Feature feature
= descriptionElement
.getFeature();
120 Map
<Class
<?
>, String
> supportedClasses
= new HashMap
<Class
<?
>, String
>();
122 // Populate feature class arrays with classes supported by this feature
123 if (feature
.supportsCommonTaxonName()) {
124 supportedClasses
.put(CommonTaxonName
.class, "Common name");
126 if (feature
.supportsDistribution()) {
127 supportedClasses
.put(Distribution
.class, "Distribution");
129 if (feature
.supportsIndividualAssociation()) {
130 supportedClasses
.put(IndividualsAssociation
.class, "Individual association");
132 if (feature
.supportsQuantitativeData()) {
133 supportedClasses
.put(QuantitativeData
.class, "Quantitative data");
135 if (feature
.supportsTaxonInteraction()) {
136 supportedClasses
.put(TaxonInteraction
.class, "Taxon interaction");
138 if (feature
.supportsTextData()) {
139 supportedClasses
.put(TextData
.class, "Text");
142 P_FEATURE_CLASS_NAME_MENU
= supportedClasses
.values().toArray((new String
[supportedClasses
.size()]));
143 supportedClasses
.keySet().toArray(new Class
[supportedClasses
.size()]);
145 descriptors
.addElement(
146 new ComboBoxPropertyDescriptor(P_ID_ELEMENT_CLASS
, P_ELEMENT_CLASS
, P_FEATURE_CLASS_NAME_MENU
)
150 if (id
.equals(P_ID_FEATURE
)) {
151 descriptors
.addElement(new PropertyDescriptor(P_ID_FEATURE
, P_FEATURE
));
154 if (id
.equals(P_ID_BIBREF
)) {
155 descriptors
.addElement(new PropertyDescriptor(P_ID_BIBREF
, P_BIBREF
));
158 if (id
.equals(P_ID_ELEMENT_TEXT
)) {
159 descriptors
.addElement(new TextPropertyDescriptor(P_ID_ELEMENT_TEXT
, P_ELEMENT_TEXT
));
162 if (id
.equals(P_ID_MICROREF
)) {
163 descriptors
.addElement(new TextPropertyDescriptor(P_ID_MICROREF
, P_MICROREF
));
168 * @see org.eclipse.ui.views.properties.IPropertySource#getEditableValue()
170 public Object
getEditableValue() {
175 * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyDescriptors()
177 public IPropertyDescriptor
[] getPropertyDescriptors() {
178 return descriptors
.toArray(
179 new IPropertyDescriptor
[descriptors
.size()]);
183 * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyValue(java.lang.Object)
185 public Object
getPropertyValue(Object id
) {
186 if (id
.equals(P_ID_ELEMENT_CLASS
)) {
187 if (descriptionElement
instanceof TextData
) {
190 if (descriptionElement
instanceof CommonTaxonName
) {
193 if (descriptionElement
instanceof Distribution
) {
198 if (id
.equals(P_ID_FEATURE
)) {
199 Feature feature
= descriptionElement
.getFeature();
200 if (feature
!= null) {
201 return feature
.getLabel();
207 if (id
.equals(P_ID_BIBREF
)) {
208 ReferenceBase
<?
> citation
= descriptionElement
.getCitation();
209 ReferencePropertySource bibRefPropertySource
= new ReferencePropertySource(citation
);
210 bibRefPropertySource
.addPropertyChangeListener(new PropertyChangeListener() {
211 public void propertyChange(PropertyChangeEvent evt
) {
212 descriptionElement
.setCitation((ReferenceBase
<?
>) evt
.getNewValue());
215 return bibRefPropertySource
;
218 if (id
.equals(P_ID_ELEMENT_TEXT
)) {
219 return DescriptionUtil
.getCache(descriptionElement
);
222 if (id
.equals(P_ID_MICROREF
)) {
223 return CdmUtils
.Nz(descriptionElement
.getCitationMicroReference());
230 * @see org.eclipse.ui.views.properties.IPropertySource#isPropertySet(java.lang.Object)
232 public boolean isPropertySet(Object id
) {
237 * @see org.eclipse.ui.views.properties.IPropertySource#resetPropertyValue(java.lang.Object)
239 public void resetPropertyValue(Object id
) {}
242 * @see org.eclipse.ui.views.properties.IPropertySource#setPropertyValue(java.lang.Object, java.lang.Object)
244 public void setPropertyValue(Object id
, Object value
) {
245 if (id
.equals(P_ID_ELEMENT_CLASS
)) {
249 if (id
.equals(P_ID_BIBREF
)) {
250 if (value
instanceof ReferenceBase
) {
251 descriptionElement
.setCitation((ReferenceBase
<?
>) value
);
255 if (id
.equals(P_ID_ELEMENT_TEXT
)) {
256 DescriptionUtil
.setCache(descriptionElement
, (String
) value
);
259 if (id
.equals(P_ID_MICROREF
)) {
260 descriptionElement
.setCitationMicroReference((String
) value
);
263 // descriptionElement.firePropertyChange(ITaxEditorConstants.PROPERTY_SHEET_CHANGE, null, null);
269 public DescriptionElementBase
getDescriptionElement() {
270 return descriptionElement
;
274 * @param parentid the parentid to set
276 public void setParentid(String parentid
) {
277 this.parentid
= parentid
;
281 * @return the parentid
283 public String
getParentid() {