Rough version of images module that doesn't actually save image URLs i.e. Taxon has...
[taxeditor.git] / eclipseprojects / eu.etaxonomy.taxeditor / src / eu / etaxonomy / taxeditor / propertysheet / CollectionPropertySource.java
1 package eu.etaxonomy.taxeditor.propertysheet;
2
3 import java.util.Collection;
4 import java.util.Vector;
5
6 import org.apache.log4j.Logger;
7 import org.eclipse.ui.views.properties.IPropertyDescriptor;
8 import org.eclipse.ui.views.properties.IPropertySource;
9 import org.eclipse.ui.views.properties.PropertyDescriptor;
10
11 /**
12 * @author p.ciardelli
13 * @created 08.05.2008
14 * @version 1.0
15 */
16 abstract public class CollectionPropertySource implements IPropertySource {
17 private static final Logger logger = Logger
18 .getLogger(CollectionPropertySource.class);
19
20 protected Vector<PropertyDescriptor> descriptors = new Vector<PropertyDescriptor>();
21 protected Collection collection;
22 private Object collectionOwner;
23
24 public CollectionPropertySource(Collection collection) {
25 this.collection = collection;
26 for (Object item : collection) {
27 addDescriptor(item);
28 }
29 }
30
31 public CollectionPropertySource(Collection collection, Object collectionOwner) {
32 this.collection = collection;
33 this.collectionOwner = collectionOwner;
34 for (Object item : collection) {
35 addDescriptor(item);
36 }
37 }
38
39 protected Object getCollectionOwner() {
40 return collectionOwner;
41 }
42
43 protected void addDescriptor(Object item) {
44 String itemDisplayName = getItemDisplayName(item);
45 descriptors.addElement(
46 new PropertyDescriptor(item, itemDisplayName));
47 }
48
49 /**
50 * Returns the label for the name of the property sheet entry.
51 * Return "" if the entry should have no label.
52 *
53 * @param item
54 * @return
55 */
56 abstract protected String getItemDisplayName(Object item);
57
58 public Object getEditableValue() {
59 return this;
60 }
61
62 public IPropertyDescriptor[] getPropertyDescriptors() {
63 return (IPropertyDescriptor[]) descriptors.toArray(
64 new IPropertyDescriptor[descriptors.size()]);
65 }
66
67 abstract public Object getPropertyValue(Object id);
68
69 public boolean isPropertySet(Object id) {
70 return false;
71 }
72
73 public void resetPropertyValue(Object id) {}
74
75 /* (non-Javadoc)
76 * @see org.eclipse.ui.views.properties.IPropertySource#setPropertyValue(java.lang.Object, java.lang.Object)
77 */
78 abstract public void setPropertyValue(Object id, Object value);
79
80 /**
81 * Returns the string that should appear in the parent
82 * entry's value field, which is usually "".
83 *
84 * @return String
85 * @see java.lang.Object#toString()
86 */
87 @Override
88 abstract public String toString();
89 }