KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > aspects > gui > web > EmbeddedMethod


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 org.objectweb.jac.aspects.gui.web;
19
20 import java.io.IOException JavaDoc;
21 import java.io.PrintWriter JavaDoc;
22 import java.util.List JavaDoc;
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 JavaDoc substance;
34     AbstractMethodItem method;
35     String JavaDoc icon;
36     EditorContainer parameters;
37
38     public EmbeddedMethod(Object JavaDoc substance, AbstractMethodItem method,
39                           EditorContainer parameters) {
40         this.substance = substance;
41         this.method = method;
42         this.parameters = parameters;
43     }
44
45     // MethodView interface
46

47     public void setMethod(AbstractMethodItem method) {
48         this.method = method;
49     }
50
51     public void setIcon(String JavaDoc icon) {
52         this.icon = icon;
53     }
54
55     boolean onlyIcon = false;
56     public void setOnlyIcon(boolean onlyIcon) {
57         this.onlyIcon = onlyIcon;
58     }
59
60     /**
61      * Returns the text of the button
62      */

63     protected String JavaDoc getText() {
64         if (method instanceof MethodItem &&
65             ((MethodItem)method).isSetter() && icon!=null)
66             return "";
67         else
68             return label;
69     }
70
71     // HTMLViewer interface
72

73     public void genHTML(PrintWriter JavaDoc out) throws IOException JavaDoc {
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     // MethodListener interface
90

91     public void onInvoke() {
92         List editors = parameters.getEditors();
93         Object JavaDoc[] params = new Object JavaDoc[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