1 5 package org.hibernate.eclipse.console.views.properties; 6 7 import java.util.Hashtable ; 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 reflectedObject; 20 private Hashtable descriptors, properties; 21 private final ConsoleConfiguration currentConfiguration; 22 private final Session currentSession; 23 24 public EntityPropertySource (final Object object, final Session currentSession, ConsoleConfiguration currentConfiguration) 25 { 26 this.currentSession = currentSession; 27 this.currentConfiguration = currentConfiguration; 28 descriptors = new Hashtable (); 29 properties = new Hashtable (); 30 reflectedObject = object; 31 32 currentConfiguration.execute(new ConsoleConfiguration.Command() { 33 34 public Object execute() { 35 try { 36 Property objectProperties[] = PropertyUtil.extractProperties(object, currentSession); 37 for (int i = 0; i < objectProperties.length; i++) 38 { 39 String 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 e) { 47 e.printStackTrace(); 48 } 49 return null; 50 } 51 }); 52 53 } 54 55 56 public Object 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 id) 65 { 66 return (Property) properties.get(id); 67 } 68 69 public Object getPropertyValue(Object id) { 70 Property property = getProperty(id); 71 if (property != null) 72 { 73 try { 74 property.readFromObject(reflectedObject); 75 return property; 76 } catch (Exception e) { 77 e.printStackTrace(); 78 } 79 } 80 81 return ""; 82 } 83 84 public boolean isPropertySet(Object id) { 85 return false; } 87 88 public void resetPropertyValue(Object id) { 89 90 } 91 92 public void setPropertyValue(Object id, Object value) { 93 Property property = getProperty(id); 94 if (property != null) 95 { 96 try { 97 property.setValue(value); 98 } catch (Exception e) { 99 e.printStackTrace(); 100 } 101 } 102 } 103 104 public boolean isPropertyResettable(Object id) { 105 return false; 106 } 107 108 } | Popular Tags |