128c1464c5ea3abc9c412b34b2ba27ca5e9ad8e2
[taxeditor.git] / taxeditor-editor / src / main / java / eu / etaxonomy / taxeditor / propertysheet / description / TaxonDescriptionPropertySource.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.description;
11
12 import java.util.Vector;
13
14 import org.apache.log4j.Logger;
15 import org.eclipse.ui.views.properties.IPropertyDescriptor;
16 import org.eclipse.ui.views.properties.IPropertySource;
17 import org.eclipse.ui.views.properties.PropertyDescriptor;
18 import org.eclipse.ui.views.properties.TextPropertyDescriptor;
19
20 import eu.etaxonomy.cdm.model.description.TaxonDescription;
21
22 /**
23 * @author p.ciardelli
24 * @created 29.08.2008
25 * @version 1.0
26 */
27 public class TaxonDescriptionPropertySource implements IPropertySource {
28 private static final Logger logger = Logger
29 .getLogger(TaxonDescriptionPropertySource.class);
30
31 // The TaxonDescription whose properties are being displayed
32 private TaxonDescription taxonDescription;
33
34 // If this is a property with a parent, the parent's property ID
35 private String parentid;
36
37 // Property unique keys
38 public static final String P_ID_LABEL = "label";
39 public static final String P_ID_UUID = "uuid";
40
41 // Property display keys
42 public String P_LABEL = "Description Label";
43 public static final String P_UUID = "UUID";
44
45 protected static final String[] TOP_LEVEL_PROPERTIES = new String[] {
46 P_ID_LABEL};
47
48 /**
49 * Constructor for top level property fields. All fields that are not subfields
50 * should be listed here.
51 * @param name
52 */
53 public TaxonDescriptionPropertySource(TaxonDescription taxonDescription) {
54 this(taxonDescription, null, TOP_LEVEL_PROPERTIES);
55 }
56
57 public TaxonDescriptionPropertySource(TaxonDescription taxonDescription, String parentid,
58 String[] keys) {
59
60 if (taxonDescription.isImageGallery()) {
61 P_LABEL = "Image Gallery Label";
62 }
63
64 this.taxonDescription = taxonDescription;
65 this.parentid = parentid;
66 for (String key : keys) {
67 addDescriptor(key);
68 }
69 }
70
71 protected Vector<PropertyDescriptor> descriptors = new Vector<PropertyDescriptor>();
72 /**
73 * Add descriptor for a given property.
74 *
75 * Notes on Descriptor:
76 *
77 * PropertyDescriptor - uneditable cell value
78 * ComboBoxPropertyDescriptor - dropdown list, property supplied must be integer-based
79 * TextPropertyDescriptor - editable cell value
80 *
81 * If any descriptor calls setCategory, all descriptors w/out a category are put in
82 * category "Misc".
83 *
84 * descriptor.setFilterFlags (new String[] { IPropertySheetEntry.FILTER_ID_EXPERT }) -
85 * this descriptor shown under advanced properties
86 *
87 * @param id
88 */
89 protected void addDescriptor(String id) {
90 if (id.equals(P_ID_LABEL)) {
91 descriptors.addElement(
92 new PropertyDescriptor(P_ID_LABEL, P_LABEL));
93 }
94 if (id.equals(P_ID_UUID)) {
95 descriptors.addElement(
96 new PropertyDescriptor(P_ID_UUID, P_UUID));
97 }
98 }
99
100 /* (non-Javadoc)
101 * @see org.eclipse.ui.views.properties.IPropertySource#getEditableValue()
102 */
103 public Object getEditableValue() {
104 return this;
105 }
106
107 /* (non-Javadoc)
108 * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyDescriptors()
109 */
110 public IPropertyDescriptor[] getPropertyDescriptors() {
111 return (IPropertyDescriptor[]) descriptors.toArray(
112 new IPropertyDescriptor[descriptors.size()]);
113 }
114
115 /* (non-Javadoc)
116 * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyValue(java.lang.Object)
117 */
118 public Object getPropertyValue(Object id) {
119 if (id.equals(P_ID_LABEL)) {
120 return taxonDescription.getTitleCache();
121 }
122 if (id.equals(P_ID_UUID)) {
123 return taxonDescription.getUuid().toString();
124 }
125 return null;
126 }
127
128 /* (non-Javadoc)
129 * @see org.eclipse.ui.views.properties.IPropertySource#isPropertySet(java.lang.Object)
130 */
131 public boolean isPropertySet(Object id) {
132 return false;
133 }
134
135 /* (non-Javadoc)
136 * @see org.eclipse.ui.views.properties.IPropertySource#resetPropertyValue(java.lang.Object)
137 */
138 public void resetPropertyValue(Object id) {}
139
140 /* (non-Javadoc)
141 * @see org.eclipse.ui.views.properties.IPropertySource#setPropertyValue(java.lang.Object, java.lang.Object)
142 */
143 public void setPropertyValue(Object id, Object value) {
144 if (id.equals(P_ID_LABEL)) {
145 taxonDescription.setTitleCache((String) value);
146 }
147 }
148 }