p2izing the editor
[taxeditor.git] / eclipseprojects / eu.etaxonomy.taxeditor / src / 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_UUID = "uuid";
39 public static final String P_ID_LABEL = "label";
40
41 // Property display keys
42 // Note: for an explanation of the sorting prefixes ("04:"),
43 // @see eu.etaxonomy.taxeditor.propertysheet.CustomSortPropertySheetEntry
44 public static final String P_UUID = "00:UUID";
45 public static final String P_LABEL = "01:Description Label";
46
47 // protected static final String[] TOP_LEVEL_PROPERTIES = new String[] {
48 // P_ID_LABEL, P_ID_UUID};
49 protected static final String[] TOP_LEVEL_PROPERTIES = new String[] {
50 P_ID_LABEL};
51
52 /**
53 * Constructor for top level property fields. All fields that are not subfields
54 * should be listed here.
55 * @param name
56 */
57 public TaxonDescriptionPropertySource(TaxonDescription taxonDescription) {
58 this(taxonDescription, null, TOP_LEVEL_PROPERTIES);
59 }
60
61 public TaxonDescriptionPropertySource(TaxonDescription taxonDescription, String parentid,
62 String[] keys) {
63 this.taxonDescription = taxonDescription;
64 this.parentid = parentid;
65 for (String key : keys) {
66 addDescriptor(key);
67 }
68 }
69
70 protected Vector<PropertyDescriptor> descriptors = new Vector<PropertyDescriptor>();
71 /**
72 * Add descriptor for a given property.
73 *
74 * Notes on Descriptor:
75 *
76 * PropertyDescriptor - uneditable cell value
77 * ComboBoxPropertyDescriptor - dropdown list, property supplied must be integer-based
78 * TextPropertyDescriptor - editable cell value
79 *
80 * If any descriptor calls setCategory, all descriptors w/out a category are put in
81 * category "Misc".
82 *
83 * descriptor.setFilterFlags (new String[] { IPropertySheetEntry.FILTER_ID_EXPERT }) -
84 * this descriptor shown under advanced properties
85 *
86 * @param id
87 */
88 protected void addDescriptor(String id) {
89 if (id.equals(P_ID_LABEL)) {
90 descriptors.addElement(
91 new TextPropertyDescriptor(P_ID_LABEL, P_LABEL));
92 }
93 if (id.equals(P_ID_UUID)) {
94 descriptors.addElement(
95 new PropertyDescriptor(P_ID_UUID, P_UUID));
96 }
97 }
98
99 /* (non-Javadoc)
100 * @see org.eclipse.ui.views.properties.IPropertySource#getEditableValue()
101 */
102 public Object getEditableValue() {
103 return this;
104 }
105
106 /* (non-Javadoc)
107 * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyDescriptors()
108 */
109 public IPropertyDescriptor[] getPropertyDescriptors() {
110 return (IPropertyDescriptor[]) descriptors.toArray(
111 new IPropertyDescriptor[descriptors.size()]);
112 }
113
114 /* (non-Javadoc)
115 * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyValue(java.lang.Object)
116 */
117 public Object getPropertyValue(Object id) {
118 if (id.equals(P_ID_LABEL)) {
119 return taxonDescription.getTitleCache();
120 }
121 if (id.equals(P_ID_UUID)) {
122 return taxonDescription.getUuid().toString();
123 }
124 return null;
125 }
126
127 /* (non-Javadoc)
128 * @see org.eclipse.ui.views.properties.IPropertySource#isPropertySet(java.lang.Object)
129 */
130 public boolean isPropertySet(Object id) {
131 return false;
132 }
133
134 /* (non-Javadoc)
135 * @see org.eclipse.ui.views.properties.IPropertySource#resetPropertyValue(java.lang.Object)
136 */
137 public void resetPropertyValue(Object id) {}
138
139 /* (non-Javadoc)
140 * @see org.eclipse.ui.views.properties.IPropertySource#setPropertyValue(java.lang.Object, java.lang.Object)
141 */
142 public void setPropertyValue(Object id, Object value) {
143 if (id.equals(P_ID_LABEL)) {
144 taxonDescription.setTitleCache((String) value);
145 }
146 }
147 }