1 19 20 package org.netbeans.modules.java.ui.editors; 21 22 import java.beans.*; 23 import java.util.Collection ; 24 import java.util.Enumeration ; 25 import java.util.LinkedList ; 26 27 28 import org.openide.explorer.propertysheet.ExPropertyEditor; 29 import org.openide.explorer.propertysheet.PropertyEnv; 30 import org.openide.filesystems.FileObject; 31 import org.openide.filesystems.FileSystem; 32 import org.openide.loaders.DataObject; 33 import org.openide.loaders.DataObjectNotFoundException; 34 35 36 import org.openide.src.*; 37 38 46 public class TypeIdentPE extends PropertyEditorSupport implements ExPropertyEditor { 47 48 private static final String ATTR_CUSTOM_TITLE = "title"; private static final String ATTR_CUSTOM_INPUT = "userInput"; private static final String ATTR_CLASSPATH_ROOTS = "classPathRoots"; private static final String ATTR_ACCEPT_CLASSES = "acceptClasses"; private static final String ATTR_ACCEPT_INTERFACES = "acceptInterfaces"; private static final String ATTR_DATA_FILTER = "dataFilter"; 55 58 PropertyEnv environment; 59 60 63 boolean acceptClasses = true; 64 65 68 boolean acceptInterfaces = true; 69 70 74 boolean validNamesOnly = false; 75 76 PropertyChangeSupport supp; 77 78 ClassChooserPanel customEditor; 79 80 84 85 88 Identifier identifier; 89 90 public java.lang.String getAsText() { 91 if (identifier == null) 92 return ""; 94 return identifier.getSourceName(); 96 } 97 98 110 public void setAsText(java.lang.String str) throws IllegalArgumentException { 111 Identifier i; 112 113 if (str == null || "".equals(str)) { 114 i = null; 115 } else { 116 Type t; 117 118 t = Type.parse(str); 121 122 if (t.isPrimitive()) { 124 denyPrimitiveType(t); 125 } else if (t.isArray()) { 126 denyArrayType(t); 127 } 128 129 ClassElement c = loadRepresentation(str); 130 131 checkInputConstraints(str, c); 134 135 i = t.getClassName(); 136 } 137 138 super.setValue(i); 140 } 141 142 public void setValue(java.lang.Object obj) throws IllegalArgumentException { 143 if (!(obj instanceof Identifier)) 144 throw new IllegalArgumentException ("Invalid value type: " + obj.getClass()); super.setValue(obj); 146 } 147 148 151 public boolean supportsCustomEditor() { 152 return true; 153 } 154 155 163 public void attachEnv(PropertyEnv env) { 164 FeatureDescriptor fd = env.getFeatureDescriptor(); 165 166 Boolean b; 167 168 b = (Boolean )fd.getValue(ATTR_ACCEPT_CLASSES); 169 if (b != null) 170 setAcceptClasses(b.booleanValue()); 171 172 b = (Boolean )fd.getValue(ATTR_ACCEPT_INTERFACES); 173 if (b != null) 174 setAcceptInterfaces(b.booleanValue()); 175 176 182 } 183 184 public void addPropertyChangeListener(PropertyChangeListener l) { 185 super.addPropertyChangeListener(l); 186 if (supp == null) { 187 synchronized (this) { 188 if (supp == null) 189 supp = new PropertyChangeSupport(this); 190 } 191 } 192 synchronized (supp) { 193 supp.addPropertyChangeListener(l); 194 } 195 } 196 197 public void removePropertyChangeListener(PropertyChangeListener l) { 198 if (supp != null) { 199 synchronized (supp) { 200 supp.removePropertyChangeListener(l); 201 } 202 } 203 super.removePropertyChangeListener(l); 204 } 205 206 void enableOK(boolean enable) { 207 if (supp == null) { 208 return; 209 } 210 supp.firePropertyChange(ExPropertyEditor.PROP_VALUE_VALID, null, 211 enable ? Boolean.TRUE : Boolean.FALSE); 212 } 213 214 219 public void setAcceptClasses(boolean accept) { 220 this.acceptClasses = accept; 221 } 222 223 228 public void setAcceptInterfaces(boolean accept) { 229 this.acceptInterfaces = accept; 230 } 231 232 public void setValidNamesOnly(boolean accept) { 233 this.validNamesOnly = accept; 234 } 235 236 public boolean getAcceptClasses() { 237 return this.acceptClasses; 238 } 239 240 public boolean getAcceptInterfaces() { 241 return this.acceptInterfaces; 242 } 243 244 public boolean getValidNamesOnly() { 245 return this.validNamesOnly; 246 } 247 248 251 252 257 private ClassElement loadRepresentation(String className) { 258 return ClassElement.forName(className); 260 } 261 262 263 private void denyPrimitiveType(Type t) { 264 throw new IllegalArgumentException ( 265 t.toString() + " is a primitive type. Simple class or interface is required" ); 267 } 268 269 private void denyArrayType(Type t) { 270 throw new IllegalArgumentException ( 271 t.toString() + " is an array. Simple class or interface is required" ); 273 } 274 275 279 void checkInputConstraints(String input, ClassElement result) 280 throws IllegalArgumentException { 281 283 if (result == null) { 284 if (!getValidNamesOnly()) { 285 return; 288 } 289 throw new IllegalArgumentException ("Cannot find class or interface " + input); } 291 292 boolean properClass = result.isClassOrInterface(); 293 294 if (properClass && !getAcceptClasses()) { 295 throw new IllegalArgumentException ("Class name is not permitted here"); } 297 298 if (!properClass && !getAcceptInterfaces()) { 299 throw new IllegalArgumentException ("Interface name is not permitted here"); } 301 } 302 303 public java.awt.Component getCustomEditor() { 304 Thread.dumpStack(); 305 return new javax.swing.JPanel (); 307 324 } 325 326 333 } 334 | Popular Tags |