Source code: jac/aspects/gui/web/EmbeddedMethod.java
1 /*
2 Copyright (C) 2003 Laurent Martelli <laurent@aopsys.com>
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
17
18 package jac.aspects.gui.web;
19
20 import jac.aspects.gui.EventHandler;
21 import jac.aspects.gui.FieldEditor;
22 import jac.aspects.gui.MethodView;
23 import jac.core.rtti.AbstractMethodItem;
24 import jac.core.rtti.MethodItem;
25 import jac.util.Log;
26 import java.io.IOException;
27 import java.io.PrintWriter;
28 import java.util.List;
29 import jac.aspects.gui.EditorContainer;
30
31
32 public class EmbeddedMethod extends AbstractCompositeView
33 implements MethodView, MethodListener
34 {
35 Object substance;
36 AbstractMethodItem method;
37 String icon;
38 EditorContainer parameters;
39
40 public EmbeddedMethod(Object substance, AbstractMethodItem method,
41 EditorContainer parameters) {
42 this.substance = substance;
43 this.method = method;
44 this.parameters = parameters;
45 }
46
47 // MethodView interface
48
49 public void setMethod(AbstractMethodItem method) {
50 this.method = method;
51 }
52
53 public void setIcon(String icon) {
54 this.icon = icon;
55 }
56
57 /**
58 * Returns the text of the button
59 */
60 protected String getText() {
61 if (method instanceof MethodItem &&
62 ((MethodItem)method).isSetter() && icon!=null)
63 return "";
64 else
65 return label;
66 }
67
68 // HTMLViewer interface
69
70 public void genHTML(PrintWriter out) throws IOException {
71 JacRequest request = ((WebDisplay)context.getDisplay()).getRequest();
72 ((HTMLViewer)parameters).genHTML(out);
73 if (request.isIEUserAgent()) {
74 out.println("<table class=\"method\"><tr><td>"+
75 iconElement(icon,label,false)+
76 eventURL(getText(),"onInvoke","")+
77 "</td></tr></table>");
78 } else {
79 out.println("<span class=\"method\">"+
80 iconElement(icon,label,false)+
81 eventURL(getText(),"onInvoke","")+
82 "</span>");
83 }
84 }
85
86 // MethodListener interface
87
88 public void onInvoke() {
89 Log.trace("gui.events",
90 "action performed on EmbeddedMethod "+method.getName());
91 List editors = parameters.getEditors();
92 Object[] params = new Object[editors.size()];
93 JacRequest request = WebDisplay.getRequest();
94 for (int i=0; i<params.length; i++) {
95 FieldEditor editor = (FieldEditor)editors.get(i);
96 ((HTMLEditor)editor).readValue(request.getParameter(editor.getLabel()));
97 params[i] = editor.getValue();
98 }
99 EventHandler.get().onInvoke(
100 context,substance,method,params,null,null);
101 }
102 }
103