1 19 20 package org.netbeans.modules.form; 21 22 import java.awt.*; 23 import java.beans.*; 24 import java.util.*; 25 import java.lang.ref.WeakReference ; 26 import java.security.*; 27 28 import org.openide.explorer.propertysheet.editors.EnhancedPropertyEditor; 29 import org.openide.explorer.propertysheet.PropertyEnv; 30 import org.openide.explorer.propertysheet.ExPropertyEditor; 31 import org.openide.nodes.*; 32 33 38 39 public class FormPropertyEditor implements PropertyEditor, 40 PropertyChangeListener, 41 EnhancedPropertyEditor, 42 ExPropertyEditor 43 { 44 private static String NO_VALUE_TEXT; 45 46 private Object value = BeanSupport.NO_VALUE; 47 48 private FormProperty property; 49 private WeakReference propertyEnv; 50 51 private PropertyEditor[] allEditors; 52 private PropertyChangeSupport changeSupport; 53 54 55 FormPropertyEditor(FormProperty property) { 56 this.property = property; 57 PropertyEditor prEd = property.getCurrentEditor(); 58 if (prEd != null) { 59 prEd.addPropertyChangeListener(this); 60 value = prEd.getValue(); 61 } 62 } 63 64 Class getPropertyType() { 65 return property.getValueType(); 66 } 67 68 FormProperty getProperty() { 69 return property; 70 } 71 72 FormPropertyContext getPropertyContext() { 73 return property.getPropertyContext(); 74 } 75 76 PropertyEnv getPropertyEnv() { 77 return propertyEnv != null ? (PropertyEnv) propertyEnv.get() : null; 78 } 79 80 PropertyEditor getCurrentEditor() { 81 return property.getCurrentEditor(); 82 } 83 84 87 public void propertyChange(PropertyChangeEvent evt) { 88 PropertyEditor prEd = property.getCurrentEditor(); 89 if (prEd != null) 90 value = prEd.getValue(); 91 92 AccessController.doPrivileged(new PrivilegedAction() { 95 public Object run() { 96 FormPropertyEditor.this.firePropertyChange(); 97 return null; 98 } 99 }); 100 } 101 102 105 112 public void setValue(Object newValue) { 113 value = newValue; 114 115 PropertyEditor prEd = property.getCurrentEditor(); 116 if (value != BeanSupport.NO_VALUE && prEd != null) 117 prEd.setValue(value); 118 } 119 120 125 public Object getValue() { 126 PropertyEditor prEd = property.getCurrentEditor(); 127 return prEd != null ? prEd.getValue() : value; 128 } 129 130 132 137 public boolean isPaintable() { 138 PropertyEditor prEd = property.getCurrentEditor(); 139 return prEd != null ? prEd.isPaintable() : false; 140 } 141 142 153 public void paintValue(Graphics gfx, Rectangle box) { 154 PropertyEditor prEd = property.getCurrentEditor(); 155 if (prEd != null) 156 prEd.paintValue(gfx, box); 157 } 158 159 161 172 public String getJavaInitializationString() { 173 PropertyEditor prEd = property.getCurrentEditor(); 174 return prEd != null ? prEd.getJavaInitializationString() : null; 175 } 176 177 179 189 public String getAsText() { 190 if (value == BeanSupport.NO_VALUE) { 191 if (NO_VALUE_TEXT == null) 192 NO_VALUE_TEXT = FormUtils.getBundleString("CTL_ValueNotSet"); return NO_VALUE_TEXT; 194 } 195 196 PropertyEditor prEd = property.getCurrentEditor(); 197 return prEd != null ? prEd.getAsText() : null; 198 } 199 200 208 public void setAsText(String text) throws java.lang.IllegalArgumentException { 209 PropertyEditor prEd = property.getCurrentEditor(); 210 if (prEd != null) 211 prEd.setAsText(text); 212 } 213 214 216 227 public String [] getTags() { 228 PropertyEditor prEd = property.getCurrentEditor(); 229 return prEd != null ? prEd.getTags() : null; 230 } 231 232 234 248 249 public Component getCustomEditor() { 250 Component customEditor; 251 252 PropertyEditor prEd = property.getCurrentEditor(); 253 if (prEd != null && prEd.supportsCustomEditor()) { 254 customEditor = prEd.getCustomEditor(); 255 if (customEditor instanceof Window) 256 return customEditor; 257 } 258 else customEditor = null; 259 260 return new FormCustomEditor(this, customEditor); 261 } 262 263 268 public boolean supportsCustomEditor() { 269 PropertyEditor[] editors = getAllEditors(); 270 271 if (!property.canWrite()) { for (int i=0; i < editors.length; i++) 273 if (!editors[i].getClass().equals(RADConnectionPropertyEditor.class) 274 && editors[i].supportsCustomEditor()) 275 return true; 276 return false; 277 } 278 279 if (editors.length > 1) 281 return true; if (editors.length == 1) 283 return editors[0].supportsCustomEditor(); 284 285 return false; 286 } 287 288 synchronized PropertyEditor[] getAllEditors() { 289 if (allEditors == null) { 290 PropertyEditor expliciteEditor = property.getExpliciteEditor(); 291 PropertyEditor[] typeEditors = 292 FormPropertyEditorManager.getAllEditors(property); 293 if (expliciteEditor != null) { 294 for (int i=0; i < typeEditors.length; i++) 296 if (expliciteEditor.getClass().equals(typeEditors[i].getClass())) { 297 typeEditors[i] = expliciteEditor; 298 expliciteEditor = null; 299 break; 300 } 301 } 302 if (expliciteEditor != null) { 303 allEditors = new PropertyEditor[typeEditors.length+1]; 304 allEditors[0] = expliciteEditor; 305 System.arraycopy(typeEditors, 0, allEditors, 1, typeEditors.length); 306 } 307 else allEditors = typeEditors; 308 } 309 return allEditors; 310 } 311 312 315 319 public Component getInPlaceCustomEditor() { 320 PropertyEditor prEd = property.getCurrentEditor(); 321 return prEd instanceof EnhancedPropertyEditor ? 322 ((EnhancedPropertyEditor)prEd).getInPlaceCustomEditor() : null; 323 } 324 325 328 public boolean hasInPlaceCustomEditor() { 329 PropertyEditor prEd = property.getCurrentEditor(); 330 return prEd instanceof EnhancedPropertyEditor ? 331 ((EnhancedPropertyEditor)prEd).hasInPlaceCustomEditor() : false; 332 } 333 334 338 public boolean supportsEditingTaggedValues() { 339 PropertyEditor prEd = property.getCurrentEditor(); 340 return prEd instanceof EnhancedPropertyEditor ? 341 ((EnhancedPropertyEditor)prEd).supportsEditingTaggedValues() : false; 342 } 343 344 347 354 356 363 public void addPropertyChangeListener(PropertyChangeListener l) { 364 synchronized (this) { 365 if (changeSupport == null) 366 changeSupport = new PropertyChangeSupport(this); 367 } 368 changeSupport.addPropertyChangeListener(l); 369 } 370 371 376 public void removePropertyChangeListener(PropertyChangeListener l) { 377 if (changeSupport != null) 378 changeSupport.removePropertyChangeListener(l); 379 } 380 381 384 void firePropertyChange() { 385 if (changeSupport != null) 386 changeSupport.firePropertyChange(null, null, null); 387 } 388 389 392 396 public void attachEnv(PropertyEnv env) { 397 propertyEnv = new WeakReference (env); 398 PropertyEditor prEd = property.getCurrentEditor(); 399 if (prEd instanceof ExPropertyEditor) 400 ((ExPropertyEditor)prEd).attachEnv(env); 401 } 402 403 407 public int hashCode() { 408 PropertyEditor prEd = property.getCurrentEditor(); 409 return prEd != null ? prEd.hashCode() : super.hashCode(); 410 } 411 412 public boolean equals(Object obj) { 413 return obj != null ? hashCode() == obj.hashCode() : false; 414 } 415 } 416 | Popular Tags |