1 19 24 package org.openide.explorer.propertysheet; 25 26 import org.openide.nodes.Node; 27 28 import java.beans.FeatureDescriptor ; 29 import java.beans.PropertyChangeListener ; 30 import java.beans.PropertyChangeSupport ; 31 import java.beans.PropertyEditor ; 32 33 import java.lang.reflect.InvocationTargetException ; 34 35 36 39 class NodePropertyModel implements ExPropertyModel { 40 43 44 private Node.Property prop; 45 46 47 private Object [] beans; 48 49 50 private PropertyChangeSupport sup = new PropertyChangeSupport (this); 51 String beanName = null; 52 53 57 public NodePropertyModel(Node.Property property, Object [] beans) { 58 this.prop = property; 59 this.beans = beans; 60 } 61 62 String getBeanName() { 63 if (beans != null) { 64 if ((beans.length == 1) && beans[0] instanceof Node.Property) { 65 return ((Node.Property) beans[0]).getDisplayName(); 66 } 67 } 68 69 return null; 70 } 71 72 73 public Object getValue() throws InvocationTargetException { 74 try { 75 return prop.getValue(); 76 } catch (IllegalAccessException iae) { 77 throw annotateException(iae); 78 } catch (InvocationTargetException ite) { 79 throw annotateException(ite); 80 } catch (ProxyNode.DifferentValuesException dve) { 81 return null; 82 } 83 } 84 85 86 public void setValue(Object v) throws InvocationTargetException { 87 try { 88 prop.setValue(v); 89 sup.firePropertyChange(PropertyModel.PROP_VALUE, null, null); 90 } catch (IllegalAccessException iae) { 91 throw annotateException(iae); 92 } catch (IllegalArgumentException iaae) { 93 throw annotateException(iaae); 94 } catch (InvocationTargetException ite) { 95 throw annotateException(ite); 96 } 97 } 98 99 104 private InvocationTargetException annotateException(Exception exception) { 105 if (exception instanceof InvocationTargetException ) { 106 return (InvocationTargetException ) exception; 107 } else { 108 return new InvocationTargetException (exception); 109 } 110 } 111 112 113 public Class getPropertyType() { 114 return prop.getValueType(); 115 } 116 117 118 public Class getPropertyEditorClass() { 119 Object ed = prop.getPropertyEditor(); 120 121 if (ed != null) { 122 return ed.getClass(); 123 } 124 125 return null; 126 } 127 128 131 public PropertyEditor getPropertyEditor() { 132 return PropUtils.getPropertyEditor(prop); 133 } 134 135 136 public void addPropertyChangeListener(PropertyChangeListener l) { 137 sup.addPropertyChangeListener(l); 138 } 139 140 141 public void removePropertyChangeListener(PropertyChangeListener l) { 142 sup.removePropertyChangeListener(l); 143 } 144 145 146 public Object [] getBeans() { 147 return beans; 148 } 149 150 151 public FeatureDescriptor getFeatureDescriptor() { 152 return prop; 153 } 154 155 void fireValueChanged() { 156 sup.firePropertyChange(PropertyModel.PROP_VALUE, null, null); 157 } 158 159 162 Node.Property getProperty() { 163 return prop; 164 } 165 } 166 | Popular Tags |