1 17 18 package org.objectweb.jac.aspects.gui.web; 19 20 import java.io.IOException ; 21 import java.io.PrintWriter ; 22 import java.util.List ; 23 import org.objectweb.jac.aspects.gui.EventHandler; 24 import org.objectweb.jac.aspects.gui.FieldEditor; 25 import org.objectweb.jac.aspects.gui.InvokeEvent; 26 import org.objectweb.jac.aspects.gui.MethodView; 27 import org.objectweb.jac.core.rtti.AbstractMethodItem; 28 import org.objectweb.jac.core.rtti.MethodItem; 29 30 public class EmbeddedMethod extends AbstractCompositeView 31 implements MethodView, MethodListener 32 { 33 Object substance; 34 AbstractMethodItem method; 35 String icon; 36 EditorContainer parameters; 37 38 public EmbeddedMethod(Object substance, AbstractMethodItem method, 39 EditorContainer parameters) { 40 this.substance = substance; 41 this.method = method; 42 this.parameters = parameters; 43 } 44 45 47 public void setMethod(AbstractMethodItem method) { 48 this.method = method; 49 } 50 51 public void setIcon(String icon) { 52 this.icon = icon; 53 } 54 55 boolean onlyIcon = false; 56 public void setOnlyIcon(boolean onlyIcon) { 57 this.onlyIcon = onlyIcon; 58 } 59 60 63 protected String getText() { 64 if (method instanceof MethodItem && 65 ((MethodItem)method).isSetter() && icon!=null) 66 return ""; 67 else 68 return label; 69 } 70 71 73 public void genHTML(PrintWriter out) throws IOException { 74 JacRequest request = WebDisplay.getRequest(); 75 parameters.genHTML(out); 76 if (request.isIEUserAgent()) { 77 out.print("<table class=\"method\"><tr><td>"+ 78 iconElement(icon,label,false)+ 79 eventURL(getText(),"onInvoke","")+ 80 "</td></tr></table>"); 81 } else { 82 out.print("<span class=\"method\">"+ 83 iconElement(icon,label,false)+ 84 eventURL(getText(),"onInvoke","")+ 85 "</span>"); 86 } 87 } 88 89 91 public void onInvoke() { 92 List editors = parameters.getEditors(); 93 Object [] params = new Object [editors.size()]; 94 JacRequest request = WebDisplay.getRequest(); 95 for (int i=0; i<params.length; i++) { 96 FieldEditor editor = (FieldEditor)editors.get(i); 97 ((HTMLEditor)editor).readValue(request.getParameter(editor.getLabel())); 98 params[i] = editor.getValue(); 99 } 100 EventHandler.get().onInvoke( 101 context, 102 new InvokeEvent(this,substance,method,params), 103 false,null,null); 104 } 105 } 106 | Popular Tags |