1 19 20 package org.openide.explorer.propertysheet; 21 22 import java.beans.PropertyEditorSupport ; 23 24 28 final class EnumPropertyEditor extends PropertyEditorSupport { 29 30 private final Class <? extends Enum > c; 31 32 public EnumPropertyEditor(Class <? extends Enum > c) { 33 this.c = c; 34 } 35 36 public String [] getTags() { 37 try { 38 Object [] values = (Object []) c.getMethod("values").invoke(null); String [] tags = new String [values.length]; 40 for (int i = 0; i < values.length; i++) { 41 tags[i] = values[i].toString(); 42 } 43 return tags; 44 } catch (Exception x) { 45 throw new AssertionError (x); 46 } 47 } 48 49 public String getAsText() { 50 Object o = getValue(); 51 return o != null ? o.toString() : ""; 52 } 53 54 @SuppressWarnings ("unchecked") 55 public void setAsText(String text) throws IllegalArgumentException { 56 if (text.length() > 0) { 57 setValue(Enum.valueOf(c, text)); 58 } else { 59 setValue(null); 60 } 61 } 62 63 public String getJavaInitializationString() { 64 Enum e = (Enum ) getValue(); 65 return e != null ? c.getName().replace('$', '.') + '.' + e.name() : "null"; } 67 68 } 69 | Popular Tags |