1 19 20 25 26 package org.netbeans.modules.j2ee.sun.share.config.ui; 27 28 import java.beans.*; 29 import java.util.*; 30 31 import javax.enterprise.deploy.spi.DConfigBean ; 32 33 import org.openide.nodes.*; 34 35 import org.netbeans.modules.j2ee.sun.share.config.ConfigBeanStorage; 36 37 38 public class ConfigProperty { 39 40 public static Node.Property getBraindead(BeanDescriptor descrip) { 41 return new Braindead(descrip); 42 } 43 44 public static Node.Property getProperty(Object bean,PropertyDescriptor property) { 45 if(property instanceof IndexedPropertyDescriptor) 46 return new Complex(bean,(IndexedPropertyDescriptor) property); 47 return new Simple(bean,property); 48 } 49 50 public static Node.Property getFixedProperty(ConfigBeanStorage cbs, String xpath) { 51 return new Fixed(cbs,xpath); 52 } 53 54 public static PropertyEditor getEditor(Object bean,PropertyDescriptor property,Class type) { 55 PropertyEditor ed = null; 56 try { 57 ed = (PropertyEditor) property.getPropertyEditorClass().newInstance(); 58 } catch (Exception e) {} 59 if(ed == null) 60 ed = PropertyEditorManager.findEditor(type); 61 if(ed == null) 62 ed = new ConfigPropertyEditor(bean,type); 63 ed.setValue(bean); 65 return ed; 67 } 68 69 70 private static class Braindead extends PropertySupport.WriteOnly { 71 72 Object obj = null; 73 Class customizer; 74 75 public Braindead(BeanDescriptor descrip) { 76 super(descrip.getName(),descrip.getBeanClass(),descrip.getDisplayName(),descrip.getShortDescription()); 77 customizer = descrip.getCustomizerClass(); 78 System.err.println("bean customizer class " + customizer); 79 } 80 81 public void setValue(Object obj) throws java.lang.IllegalAccessException , java.lang.IllegalArgumentException , java.lang.reflect.InvocationTargetException { 82 this.obj = obj; 83 } 84 85 public PropertyEditor getPropertyEditor() { 86 return new PropertyEditorSupport() { 87 public String getAsText() {return "No text";} 88 public boolean supportsCustomEditor() { return true; } 89 public synchronized java.awt.Component getCustomEditor() { 90 try { 91 Customizer foo = (Customizer) customizer.newInstance(); 92 foo.setObject(obj); 93 return (java.awt.Component ) foo; 94 } catch (Exception e) { 95 return null; 96 } 97 } 98 }; 99 } 100 101 } 102 103 private static class Simple extends PropertySupport.Reflection { 104 105 PropertyDescriptor property; 106 107 Simple(Object bean,PropertyDescriptor property) { 108 super(bean,property.getPropertyType(), 109 property.getReadMethod(),property.getWriteMethod()); 110 this.property = property; 111 } 113 114 public PropertyEditor getPropertyEditor() { 115 return ConfigProperty.getEditor(instance,property,property.getPropertyType()); 117 } 118 119 public String getName() { 120 return property.getName(); 121 } 122 123 public String getDisplayName() { 124 return property.getDisplayName(); 125 } 126 127 public String getShortDescription() { 128 return property.getShortDescription(); 129 } 130 131 public Object getValue() throws IllegalArgumentException , IllegalAccessException , java.lang.reflect.InvocationTargetException { 132 Object obj = super.getValue(); 133 if(obj == null) 134 try { 135 obj = property.getPropertyType().newInstance(); 136 setValue(obj); 137 } catch (InstantiationException ie) { 138 } 141 return obj; 142 } 143 144 } 145 146 private static class Complex extends IndexedPropertySupport { 147 148 IndexedPropertyDescriptor property; 149 150 Complex(Object bean,IndexedPropertyDescriptor descriptor) { 151 super(bean,descriptor.getPropertyType(),descriptor.getIndexedPropertyType(), 152 descriptor.getReadMethod(),descriptor.getWriteMethod(), 153 descriptor.getIndexedReadMethod(),descriptor.getIndexedWriteMethod()); 154 property = descriptor; 155 } 157 158 public PropertyEditor getIndexedPropertyEditor() { 159 return ConfigProperty.getEditor(instance,property,property.getIndexedPropertyType()); 161 } 162 163 public String getName() { 164 return property.getName(); 165 } 166 167 public String getDisplayName() { 168 return property.getDisplayName(); 169 } 170 171 public void setValue(Object obj) throws IllegalArgumentException , IllegalAccessException , java.lang.reflect.InvocationTargetException { 172 if(obj.getClass().isArray()) { 173 Object [] arr = (Object []) obj; 174 for(int i = 0 ; i < arr.length; i++) 175 if(arr[i] == null) 176 try { 177 arr[i] = property.getIndexedPropertyType().newInstance(); 178 } catch (InstantiationException ie) { 179 } 182 } 183 super.setValue(obj); 184 } 185 } 186 187 private static class Fixed extends IndexedPropertySupport { 190 ConfigBeanStorage cbs; 191 String xpath; 192 Collection objs = new HashSet(); 193 Class cl = DConfigBean .class; 194 Fixed(ConfigBeanStorage cbs, String xpath) { 196 super(cbs.getConfigBean(),(new DConfigBean [0]).getClass(),DConfigBean .class, 197 null,null,null,null); 198 this.cbs = cbs; this.xpath = xpath; 199 String name = xpath.substring(xpath.lastIndexOf("/")+1); 200 setName(name); 201 setDisplayName(name); 202 } 204 205 public PropertyEditor getIndexedPropertyEditor() { 206 return ConfigProperty.getEditor(instance,null,cl); 209 } 210 211 public boolean canIndexedRead() { return true; } 212 public boolean canIndexedWrite() { return false; } 213 public boolean canRead() { return true; } 214 public boolean canWrite() { return false; } 215 216 public Object getIndexedValue(int index) { 217 return ((ConfigBeanStorage)objs.toArray()[index]).getConfigBean(); 219 } 220 221 public Object getValue() { 222 Object [] arr = objs.toArray(); 224 DConfigBean [] cb = new DConfigBean [arr.length]; 225 for(int i = 0; i < cb.length; i++) 226 cb[i] = ((ConfigBeanStorage)arr[i]).getConfigBean(); 227 return cb; 228 } 229 230 public void addElement(ConfigBeanStorage elem) { 231 cl = elem.getConfigBean().getClass(); 232 objs.add(elem); 233 } 234 235 public void removeElement(ConfigBeanStorage elem) { 236 objs.remove(elem); 237 } 238 } 239 } 240 | Popular Tags |