1 18 19 package org.objectweb.jac.aspects.gui.web; 20 21 import java.io.PrintWriter ; 22 import java.lang.reflect.Constructor ; 23 import org.objectweb.jac.aspects.gui.GuiAC; 24 import org.objectweb.jac.aspects.gui.Length; 25 import org.objectweb.jac.core.rtti.FieldItem; 26 27 28 32 public class PrimitiveFieldEditor extends AbstractFieldEditor 33 implements HTMLEditor 34 { 35 boolean password; 36 37 public PrimitiveFieldEditor(Object substance, FieldItem field, 38 boolean password) { 39 super(substance,field); 40 this.password = password; 41 width = new Length("15ex"); 42 } 43 44 public PrimitiveFieldEditor(Object substance, FieldItem field) { 45 super(substance,field); 46 width = new Length("15ex"); 47 } 48 49 51 public void genHTML(PrintWriter out) { 52 boolean hasDefault = field!=null && GuiAC.hasDefaultValue(field); 53 out.print("<INPUT type=\""+(password?"password":"text")+"\""+ 54 " class=\"editor\""+ 55 " id=\""+label+"\""+ 56 " name=\""+label+"\""+ 57 sizeSpec()+ 58 " value=\""+displayedValue()+"\""); 59 printAttributes(out); 60 out.print(">"); 61 } 62 63 protected String displayedValue() { 64 return value==null ? "" : value.toString(); 65 } 66 67 protected boolean doReadValue(Object parameter) { 68 if (parameter==null) 69 return false; 70 String string = (String )parameter; 71 Class cl = type.getActualClass(); 72 if (cl == int.class || cl == Integer .class) { 73 setValue(new Integer (string)); 74 } else if (cl == boolean.class || cl == Boolean .class) { 75 setValue(Boolean.valueOf(string)); 76 } else if (cl == long.class || cl == Long .class) { 77 setValue(new Long (string)); 78 } else if (cl == float.class || cl == Float .class) { 79 setValue(new Float (string)); 80 } else if (cl == double.class || cl == Double .class) { 81 setValue(new Double (string)); 82 } else if (cl == short.class || cl == Short .class) { 83 setValue(new Short (string)); 84 } else if (cl == byte.class || cl == Byte .class) { 85 setValue(new Byte (string)); 86 } else if (cl == char.class || cl == Character .class) { 87 setValue(new Character (string.charAt(0))); 88 } else if (cl == String .class) { 89 setValue(string); 90 } else { 91 try { 92 Constructor c = cl.getConstructor(new Class [] {String .class}); 97 setValue(c.newInstance(new Object [] {string})); 98 } catch (Exception e) { 99 e.printStackTrace(); 100 throw new RuntimeException ("Unhandled type "+type.getName()); 101 } 102 } 103 return true; 104 } 105 } 106 107 | Popular Tags |