1 19 20 23 24 package org.netbeans.modules.j2ee.sun.ws7.ide.editors; 25 import java.beans.PropertyEditorSupport ; 26 import java.lang.reflect.Method ; 27 28 32 public class TaggedEditor extends PropertyEditorSupport { 33 private Object curr_Sel; 34 private Class clazz; 35 private Method getValue; 36 private Method getChoices; 37 private String [] tags; 38 39 public TaggedEditor(Class clazz) { 40 this.clazz = clazz; 41 curr_Sel = null; 42 43 try { 44 getValue = clazz.getMethod("getValue", new Class [] { String .class }); 46 getChoices = clazz.getMethod("getChoices", null); } catch (NoSuchMethodException e) { 48 e.printStackTrace(); 50 } } 52 53 public String getAsText() { 54 return curr_Sel.toString(); 55 } 56 57 public void setAsText(String string) 58 throws IllegalArgumentException { 59 if ((string == null) || string.equals("")) { throw new IllegalArgumentException (); 61 } 62 else { 63 try { 64 curr_Sel = getValue. 65 invoke(null, new Object []{ string }); 66 } catch (Exception e) { 67 } } 71 this.firePropertyChange(); 72 } 73 74 public void setValue (Object val) { 75 if (!clazz.isInstance(val)) { 76 throw new IllegalArgumentException (); 77 } 78 79 curr_Sel = val; 80 } 81 82 public Object getValue() { 83 return curr_Sel; 84 } 85 86 public String getJavaInitializationString() { 87 return getAsText(); 88 } 89 90 public String [] getTags() { 91 if (tags == null) { 92 TaggedValue[] tagObjs = new TaggedValue[0]; 93 94 try { 95 tagObjs = 96 (TaggedValue[])getChoices.invoke(null, null); 97 } catch (Exception e) { 98 e.printStackTrace(); 99 } 102 tags = new String [tagObjs.length]; 103 104 for (int i = 0; i < tagObjs.length; i++) { 105 tags[i] = tagObjs[i].toString(); 106 } } 109 return tags; 110 } 111 } 112 | Popular Tags |