KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2   Copyright (C) 2002-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.Iterator JavaDoc;
23 import javax.servlet.http.HttpServletResponse JavaDoc;
24 import org.objectweb.jac.aspects.gui.Constants;
25 import org.objectweb.jac.aspects.gui.DialogView;
26 import org.objectweb.jac.aspects.gui.FieldEditor;
27 import org.objectweb.jac.aspects.gui.GuiAC;
28 import org.objectweb.jac.aspects.gui.View;
29
30 public class ObjectView extends Container implements DialogListener
31 {
32     public ObjectView() {
33         super(Constants.VERTICAL);
34     }
35
36     public void removeAllViews(boolean validate) {
37         Iterator JavaDoc it = components.iterator();
38         while (it.hasNext()) {
39             Object JavaDoc component = it.next();
40             if (component instanceof FieldEditor) {
41                 context.removeEditor((FieldEditor)component);
42             }
43         }
44         super.removeAllViews(validate);
45     }
46
47     public void removeView(View component, boolean validate)
48     {
49         super.removeView(component,validate);
50         if (component instanceof FieldEditor) {
51             context.removeEditor((FieldEditor)component);
52         }
53     }
54
55     public void genHTML(PrintWriter JavaDoc out) throws IOException JavaDoc {
56         // This test is bit hackish, we should probably always have a
57
// form in the page
58
boolean showButtons = context.showButtons() && !(parentView instanceof DialogView);
59         if (showButtons)
60             out.println("<form action=\""+
61                         ((WebDisplay)context.getDisplay()).getServletName()+"\" "+
62                         "method=\"post\" accept-charset=\""+GuiAC.getEncoding()+"\" "+
63                         "enctype=\"multipart/form-data\">");
64
65         super.genHTML(out);
66         if (showButtons)
67             out.println(" <input type=\"hidden\" name=\"source\" value=\""+getId()+"\">");
68         if (context.hasEnabledEditor() && showButtons) {
69             out.println(" <div class=\"actions\">");
70             out.println(" <input type=\"hidden\" name=\"event\" value=\"onValidate\">");
71             out.println(" <input class=\"button\" type=\"submit\" name=\"onOK\" value=\""+GuiAC.getLabelOK()+"\">");
72             out.println(" <input class=\"button\" type=\"submit\" name=\"onCancel\" value=\""+GuiAC.getLabelCancel()+"\">");
73             /* // does not work with IE ...
74               out.println(" <button class=\"button\" type=\"submit\" name=\"event\" "+
75               "value=onOK>"+GuiAC.getLabelOK()+"</button>");
76               out.println(" <button class=\"button\" type=\"submit\" name=\"event\" "+
77               "value=onCancel>"+GuiAC.getLabelCancel()+"</button>");
78             */

79             out.println(" </div>");
80         }
81         if (showButtons)
82             out.println("</form>");
83     }
84
85     // DialogListener interface
86

87     public void onOK(JacRequest request) {
88         onValidate(request);
89         ((WebDisplay)context.getDisplay()).refresh();
90     }
91
92     public void onRefresh(JacRequest request) {
93         onValidate(request);
94         ((WebDisplay)context.getDisplay()).refresh();
95     }
96
97     public void onValidate(JacRequest request) {
98         try {
99             WebDisplay.readValues(context,request,true);
100             setDescription(null);
101         } catch (Exception JavaDoc e) {
102             setDescription(e.getMessage());
103             logger.error(this+".onValidate",e);
104         }
105     }
106
107     public void onCancel() {
108         ((WebDisplay)context.getDisplay()).refresh();
109     }
110
111     public void restoreContext() {
112     }
113
114     public HttpServletResponse JavaDoc getResponse() {
115         return null;
116     }
117
118     public JacRequest getRequest() {
119         return null;
120     }
121 }
122
Popular Tags