1 18 19 package org.objectweb.jac.aspects.gui.web; 20 21 import org.objectweb.jac.core.rtti.CollectionItem; 22 import org.objectweb.jac.core.rtti.FieldItem; 23 import org.objectweb.jac.core.rtti.MethodItem; 24 import org.objectweb.jac.core.rtti.RttiAC; 25 import org.objectweb.jac.util.Strings; 26 import java.io.PrintWriter ; 27 28 32 public class IndexSelector extends AbstractFieldEditor 33 implements HTMLEditor 34 { 35 CollectionItem index; 36 FieldItem indexedField; 37 Object repository; 38 String key; 39 MethodItem indexNotFoundHandler; 40 41 public IndexSelector(Object substance, FieldItem field, 42 CollectionItem index, Object repository, 43 boolean allowCreation, 44 MethodItem indexNotFoundHandler) { 45 super(substance,field); 46 this.index = index; 47 this.repository = repository; 48 indexedField = (FieldItem)index.getAttribute(RttiAC.INDEXED_FIELD); 49 this.indexNotFoundHandler = indexNotFoundHandler; 50 updateKey(); 51 } 52 53 public void setValue(Object value) { 54 super.setValue(value); 55 updateKey(); 56 } 57 58 protected void updateKey() { 59 if (indexedField!=null && value!=null) { 60 key = indexedField.getThroughAccessor(value).toString(); 61 } 62 } 63 64 66 public void genHTML(PrintWriter out) { 67 out.print("<input type=\"text\" name=\""+label+ 68 "\" size=\"12\" style=\"width:12ex\""+ 69 " value=\""+(key!=null?key:"")+"\""); 70 printAttributes(out); 71 out.println(">"); 72 } 73 74 protected boolean doReadValue(Object parameter) { 75 key = (String )parameter; 76 if (Strings.isEmpty(key)) { 77 setValue(null); 78 } else { 79 Object value = index.getMap(repository,key); 80 if (value!=null) { 81 setValue(value); 82 } else { 83 if (indexNotFoundHandler!=null && field!=null) { 84 value = indexNotFoundHandler.invokeStatic( 85 new Object [] {field.getTypeItem(),key}); 86 } 87 setValue(value); 88 } 89 90 } 91 return true; 92 } 93 94 95 } 96 97 | Popular Tags |