KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2   Copyright (C) 2001-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 java.util.List JavaDoc;
24 import java.util.Vector JavaDoc;
25 import javax.servlet.http.HttpServletResponse JavaDoc;
26 import org.objectweb.jac.aspects.gui.Constants;
27 import org.objectweb.jac.aspects.gui.FieldEditor;
28 import org.objectweb.jac.aspects.gui.GuiAC;
29
30 public class EditorContainer extends Container
31     implements org.objectweb.jac.aspects.gui.EditorContainer, DialogListener
32 {
33     Vector JavaDoc editors = new Vector JavaDoc();
34     boolean showButtons;
35
36     /**
37      * @param showButtons wether to show an OK and a Cancel button
38      */

39     public EditorContainer(boolean showButtons) {
40         super(Constants.VERTICAL);
41         this.showButtons = showButtons;
42     }
43
44     public void addEditor(Object JavaDoc editor) {
45         editors.add(editor);
46     }
47    
48     public void removeEditor(Object JavaDoc editor) {
49         editors.remove(editor);
50     }
51    
52     public List getEditors() {
53         return (List)editors.clone();
54     }
55
56     public boolean hasEnabledEditor() {
57         Iterator JavaDoc it = editors.iterator();
58         while (it.hasNext()) {
59             Object JavaDoc view = it.next();
60             if (view instanceof FieldEditor &&
61                 ((FieldEditor)view).isEnabled()) {
62                 return true;
63             }
64         }
65         return false;
66     }
67
68     public void setShowButtons(boolean value) {
69         this.showButtons = value;
70     }
71     public boolean showButtons() {
72         return showButtons;
73     }
74
75     public void genHTML(PrintWriter JavaDoc out) throws IOException JavaDoc {
76         out.println("<div class=\""+type+"\">");
77         if (!editors.isEmpty() && showButtons) {
78             out.println("<form action=\""+
79                         ((WebDisplay)context.getDisplay()).getServletName()+"\""+
80                         " accept-charset=\"utf-8\">");
81         }
82         genItemsHTML(out);
83         if (!editors.isEmpty() && showButtons) {
84             out.println(" <div class=\"actions\">");
85             out.println(" <input type=\"hidden\" name=\"source\" value=\""+getId()+"\">");
86             out.println(" <button class=button type=submit name=event "+
87                         "value=\"onOK\">OK</button>");
88             out.println(" <button class=\"button\" type=\"submit\" name=\"event\" "+
89                         "value=\"onCancel\">"+GuiAC.getLabelCancel()+"</button>");
90             out.println(" </div>");
91             out.println("</form>");
92         }
93         out.println("</div>");
94     }
95
96     // DialogListener interface
97

98     public void onOK(JacRequest request) {
99         onValidate(request);
100         ((WebDisplay)context.getDisplay()).refresh();
101     }
102
103     public void onRefresh(JacRequest request) {
104         onValidate(request);
105         ((WebDisplay)context.getDisplay()).refresh();
106     }
107
108     public void onValidate(JacRequest request){
109         Iterator JavaDoc i = editors.iterator();
110         while (i.hasNext()) {
111             FieldEditor editor = (FieldEditor)i.next();
112             ((HTMLEditor)editor).readValue(request.getParameter(editor.getLabel()));
113             ((HTMLEditor)editor).commit();
114         }
115     }
116
117     public void onCancel() {
118         ((WebDisplay)context.getDisplay()).refresh();
119     }
120
121     public void restoreContext() {}
122
123     public HttpServletResponse JavaDoc getResponse() {
124         return null;
125     }
126
127     public JacRequest getRequest() {
128         return null;
129     }
130
131 }
132
Popular Tags