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