1 18 19 package org.objectweb.jac.aspects.gui.web; 20 21 import java.io.PrintWriter ; 22 import org.apache.log4j.Logger; 23 import org.objectweb.jac.aspects.gui.CollectionModel; 24 import org.objectweb.jac.aspects.gui.DisplayContext; 25 import org.objectweb.jac.aspects.gui.FieldEditor; 26 import org.objectweb.jac.aspects.gui.GuiAC; 27 import org.objectweb.jac.aspects.gui.ListModel; 28 import org.objectweb.jac.aspects.gui.ViewFactory; 29 import org.objectweb.jac.core.Collaboration; 30 import org.objectweb.jac.core.rtti.ClassItem; 31 import org.objectweb.jac.core.rtti.CollectionItem; 32 import org.objectweb.jac.core.rtti.FieldItem; 33 import org.objectweb.jac.core.rtti.MethodItem; 34 import org.objectweb.jac.core.rtti.RttiAC; 35 import org.objectweb.jac.util.Strings; 36 37 41 public class IndicesSelector extends AbstractCollection 42 implements FieldEditor, HTMLEditor 43 { 44 static Logger logger = Logger.getLogger("gui.editor"); 45 46 CollectionItem index; 47 Object repository; 48 FieldItem indexedField; 49 MethodItem indexNotFoundHandler; 50 String indices; 51 ClassItem componentType; 52 ClassItem type; 53 54 public IndicesSelector(ViewFactory factory, DisplayContext context, 55 CollectionItem collection, Object substance, 56 CollectionModel model, 57 org.objectweb.jac.aspects.gui.CollectionItemView itemView) { 58 super(factory,context,collection,substance,model,itemView); 59 componentType = collection.getComponentType(); 60 this.index = (CollectionItem) 61 componentType.getAttribute(GuiAC.INDEXED_FIELD_SELECTOR); 62 this.repository = GuiAC.getRepository(componentType); 63 indexedField = (FieldItem)index.getAttribute(RttiAC.INDEXED_FIELD); 64 this.indexNotFoundHandler = (MethodItem) 65 componentType.getAttribute(GuiAC.INDEX_NOT_FOUND_HANDLER); 66 indices = objectsToString(); 67 } 68 69 public void setEditedType(ClassItem type) { 70 this.type = type; 71 } 72 73 public void sort() { 74 } 75 76 public void updateModel(Object substance) { 77 if (model!=null) 78 model.close(); 79 model = new ListModel(collection,substance); 80 indices = objectsToString(); 81 } 82 83 public void commit() { 84 logger.debug(this+": "+collection.getName()+ 85 "'s value changed: "); 86 collection.clear(substance); 87 String [] keys = Strings.split(indices," "); 88 for (int i=0; i<keys.length; i++) { 89 if (Strings.isEmpty(keys[i].trim())) 90 continue; 91 Object value = index.getMap(repository,keys[i]); 92 if (value==null) { 93 if (indexNotFoundHandler!=null) { 94 value = indexNotFoundHandler.invokeStatic( 95 new Object [] {componentType,keys[i]}); 96 } 97 } 98 if (value!=null) { 99 collection.addThroughAdder(substance,value); 100 } else { 101 logger.warn("No such "+collection.getComponentType()+ 102 " with "+indexedField.getName()+"="+keys[i]); 103 } 104 } 105 } 106 107 109 public Object getValue() { 110 return null; 111 } 112 113 public void setEmbedded(boolean embedded) { 114 } 115 116 public void onSetFocus(Object param) { 117 } 118 119 121 public String objectsToString() { 122 StringBuffer res = new StringBuffer (); 123 for (int i=0; i<model.getRowCount(); i++) { 124 if (i!=0) 125 res.append(" "); 126 res.append(indexedField.getThroughAccessor(model.getObject(i)).toString()); 127 } 128 return res.toString(); 129 } 130 131 public void genHTML(PrintWriter out) { 132 out.print("<input type=\"text\" name=\""+label+ 133 "\" size=\"20\" style=\"width:20ex\""+ 134 " value=\""+indices+"\""); 135 printAttributes(out); 136 out.println(">"); 137 } 138 139 public boolean readValue(Object parameter) { 140 indices = (String )parameter; 141 148 return true; 149 } 150 151 152 } 153 154 | Popular Tags |