Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: jac/aspects/gui/web/ObjectView.java


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 jac.aspects.gui.web;
19  
20  import jac.aspects.gui.Constants;
21  import jac.aspects.gui.DialogView;
22  import jac.aspects.gui.FieldEditor;
23  import jac.aspects.gui.GuiAC;
24  import jac.aspects.gui.View;
25  import jac.util.Log;
26  import java.io.IOException;
27  import java.io.PrintWriter;
28  import java.util.Iterator;
29  import java.util.List;
30  import java.util.Vector;
31  import javax.servlet.ServletRequest;
32  
33  public class ObjectView extends Container implements DialogListener
34  {
35     /**
36      * @param showButtons wether to show an OK and a Cancel button
37      */
38     public ObjectView() {
39        super(Constants.VERTICAL);
40     }
41  
42     public void removeAllViews() {
43        Iterator it = components.iterator();
44        while (it.hasNext()) {
45           Object component = it.next();
46           if (component instanceof FieldEditor) {
47              context.removeEditor((FieldEditor)component);
48           }
49        }
50        super.removeAllViews();
51     }
52  
53     public void removeView(View component)
54     {
55        super.removeView(component);
56        if (component instanceof FieldEditor) {
57           context.removeEditor((FieldEditor)component);
58        }
59     }
60  
61     public void genHTML(PrintWriter out) throws IOException {
62        // This test is bit hackish, we should probably always have a
63        // form in the page
64        boolean showButtons = context.showButtons() && !(parentView instanceof DialogView);
65        if (showButtons)
66           out.println("<form action=\""+
67                       ((WebDisplay)context.getDisplay()).getServletName()+"\" "+
68                       "method=\"post\" "+
69                       "enctype=\"multipart/form-data\">");
70  
71        out.println("    <input type=\"hidden\" name=\"source\" value=\""+getId()+"\">");
72        super.genHTML(out);
73        if (!context.getEditors().isEmpty() && showButtons) {
74           out.println("  <div class=\"actions\">");
75           out.println("    <input type=\"hidden\" name=\"event\" value=\"onValidate\">");
76           out.println("    <input class=\"button\" type=\"submit\" name=\"onOK\" value=\""+GuiAC.getLabelOK()+"\">");
77           out.println("    <input class=\"button\" type=\"submit\" name=\"onCancel\" value=\""+GuiAC.getLabelCancel()+"\">");
78           /*
79           out.println("    <button class=\"button\" type=\"submit\" name=\"event\" "+
80                       "value=onOK>"+GuiAC.getLabelOK()+"</button>");
81           out.println("    <button class=\"button\" type=\"submit\" name=\"event\" "+
82                       "value=onCancel>"+GuiAC.getLabelCancel()+"</button>");
83           */
84           out.println("  </div>");
85        }
86        if (showButtons)
87           out.println("</form>");
88     }
89  
90     // DialogListener interface
91  
92     public void onOK(JacRequest request) {
93        onValidate(request);
94        ((WebDisplay)context.getDisplay()).refresh();
95     }
96  
97     public void onValidate(JacRequest request) {
98        Log.trace("gui.events",this+".onValidate");
99        try {
100          WebDisplay.readValues(context,request,true);
101          setDescription(null);
102       } catch (Exception e) {
103          setDescription(e.getMessage());
104          e.printStackTrace();
105       }
106    }
107 
108    public void onCancel() {
109       ((WebDisplay)context.getDisplay()).refresh();
110    }
111 
112    public void restoreContext() {
113    }
114 }