Project

General

Profile

Download (2.25 KB) Statistics
| Branch: | Tag: | Revision:
1
package eu.etaxonomy.taxeditor.propertysheet;
2

    
3
import java.util.Collection;
4
import java.util.Vector;
5

    
6
import org.eclipse.ui.views.properties.IPropertyDescriptor;
7
import org.eclipse.ui.views.properties.PropertyDescriptor;
8

    
9
/**
10
 * @author p.ciardelli
11
 * @created 08.05.2008
12
 * @version 1.0
13
 */
14
abstract public class CollectionPropertySource implements ICdmBasePropertySource {
15

    
16
	protected Vector<PropertyDescriptor> descriptors = new Vector<PropertyDescriptor>();
17
	protected Collection<?> collection;
18
	private Object collectionOwner;
19
	
20
	public CollectionPropertySource(Collection<?> collection) {
21
		this.collection = collection;
22
		for (Object item : collection) {
23
			addDescriptor(item);
24
		}
25
	}
26

    
27
	public CollectionPropertySource(Collection<?> collection, Object collectionOwner) {
28
		this.collection = collection;
29
		this.collectionOwner = collectionOwner;
30
		for (Object item : collection) {
31
			addDescriptor(item);
32
		}
33
	}
34
	
35
	protected Object getCollectionOwner() {
36
		return collectionOwner;
37
	}
38
	
39
	protected void addDescriptor(Object item) {
40
		String itemDisplayName = getItemDisplayName(item);
41
		descriptors.addElement(
42
				new PropertyDescriptor(item, itemDisplayName));
43
	}
44
	
45
	/**
46
	 * Returns the label for the name of the property sheet entry.
47
	 *  Return "" if the entry should have no label.
48
	 * 
49
	 * @param item
50
	 * @return
51
	 */
52
	abstract protected String getItemDisplayName(Object item);
53

    
54
	public Object getEditableValue() {
55
		return this;
56
	}
57
	
58
	public IPropertyDescriptor[] getPropertyDescriptors() {
59
		return (IPropertyDescriptor[]) descriptors.toArray(
60
                new IPropertyDescriptor[descriptors.size()]);
61
	}
62

    
63
	abstract public Object getPropertyValue(Object id);
64

    
65
	public boolean isPropertySet(Object id) {
66
		return false;
67
	}	
68
	
69
	public void resetPropertyValue(Object id) {}
70

    
71
	/* (non-Javadoc)
72
	 * @see org.eclipse.ui.views.properties.IPropertySource#setPropertyValue(java.lang.Object, java.lang.Object)
73
	 */
74
	abstract public void setPropertyValue(Object id, Object value);
75
	
76
	/**
77
	 * Returns the string that should appear in the parent
78
	 *  entry's value field, which is usually "".
79
	 * 
80
	 * @return String
81
	 * @see java.lang.Object#toString()
82
	 */
83
	@Override
84
	abstract public String toString();
85
}
(7-7/24)