KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > eclipse > console > views > properties > EntityPropertySource


1 /*
2  * Created on 22-Mar-2005
3  *
4  */

5 package org.hibernate.eclipse.console.views.properties;
6
7 import java.util.Hashtable JavaDoc;
8
9 import org.eclipse.ui.views.properties.IPropertyDescriptor;
10 import org.eclipse.ui.views.properties.IPropertySource2;
11 import org.hibernate.Session;
12 import org.hibernate.console.ConsoleConfiguration;
13 import org.hibernate.console.PropertyUtil;
14
15 import com.l2fprod.common.propertysheet.Property;
16
17 public class EntityPropertySource implements IPropertySource2
18 {
19     private Object JavaDoc reflectedObject;
20     private Hashtable JavaDoc descriptors, properties;
21     private final ConsoleConfiguration currentConfiguration;
22     private final Session currentSession;
23     
24     public EntityPropertySource (final Object JavaDoc object, final Session currentSession, ConsoleConfiguration currentConfiguration)
25     {
26         this.currentSession = currentSession;
27         this.currentConfiguration = currentConfiguration;
28         descriptors = new Hashtable JavaDoc();
29         properties = new Hashtable JavaDoc();
30         reflectedObject = object;
31         
32         currentConfiguration.execute(new ConsoleConfiguration.Command() {
33
34             public Object JavaDoc execute() {
35                 try {
36                     Property objectProperties[] = PropertyUtil.extractProperties(object, currentSession);
37                     for (int i = 0; i < objectProperties.length; i++)
38                     {
39                         String JavaDoc propertyId = HibernatePropertyHelper.getPropertyId(objectProperties[i]);
40                         IPropertyDescriptor descriptor = HibernatePropertyHelper.getPropertyDescriptor(objectProperties[i]);
41                         descriptors.put(propertyId, descriptor);
42                         properties.put(propertyId, objectProperties[i]);
43                         
44                     }
45                     
46                 } catch (Exception JavaDoc e) {
47                     e.printStackTrace();
48                 }
49                 return null;
50             }
51         });
52                 
53     }
54     
55     
56     public Object JavaDoc getEditableValue() {
57         return "";
58     }
59     
60     public IPropertyDescriptor[] getPropertyDescriptors() {
61         return (IPropertyDescriptor[]) descriptors.values().toArray(new IPropertyDescriptor[descriptors.values().size()]);
62     }
63     
64     private Property getProperty (Object JavaDoc id)
65     {
66         return (Property) properties.get(id);
67     }
68     
69     public Object JavaDoc getPropertyValue(Object JavaDoc id) {
70         Property property = getProperty(id);
71         if (property != null)
72         {
73             try {
74                 property.readFromObject(reflectedObject);
75                 return property;
76             } catch (Exception JavaDoc e) {
77                 e.printStackTrace();
78             }
79         }
80         
81         return "";
82     }
83     
84     public boolean isPropertySet(Object JavaDoc id) {
85         return false; // we can not decide this at the given point.
86
}
87     
88     public void resetPropertyValue(Object JavaDoc id) {
89         
90     }
91     
92     public void setPropertyValue(Object JavaDoc id, Object JavaDoc value) {
93         Property property = getProperty(id);
94         if (property != null)
95         {
96             try {
97                 property.setValue(value);
98             } catch (Exception JavaDoc e) {
99                 e.printStackTrace();
100             }
101         }
102     }
103     
104     public boolean isPropertyResettable(Object JavaDoc id) {
105         return false;
106     }
107     
108 }
Popular Tags