001 /* 002 Copyright (C) 2002-2003 Laurent Martelli <laurent@aopsys.com> 003 004 This program is free software; you can redistribute it and/or modify 005 it under the terms of the GNU Lesser General Public License as 006 published by the Free Software Foundation; either version 2 of the 007 License, or (at your option) any later version. 008 009 This program is distributed in the hope that it will be useful, 010 but WITHOUT ANY WARRANTY; without even the implied warranty of 011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 012 GNU Lesser General Public License for more details. 013 014 You should have received a copy of the GNU Lesser General Public License 015 along with this program; if not, write to the Free Software 016 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 017 018 package org.objectweb.jac.aspects.gui.web; 019 020 import java.io.IOException; 021 import java.io.PrintWriter; 022 import java.util.Iterator; 023 import javax.servlet.http.HttpServletResponse; 024 import org.objectweb.jac.aspects.gui.Constants; 025 import org.objectweb.jac.aspects.gui.DialogView; 026 import org.objectweb.jac.aspects.gui.FieldEditor; 027 import org.objectweb.jac.aspects.gui.GuiAC; 028 import org.objectweb.jac.aspects.gui.View; 029 030 public class ObjectView extends Container implements DialogListener 031 { 032 public ObjectView() { 033 super(Constants.VERTICAL); 034 } 035 036 public void removeAllViews(boolean validate) { 037 Iterator it = components.iterator(); 038 while (it.hasNext()) { 039 Object component = it.next(); 040 if (component instanceof FieldEditor) { 041 context.removeEditor((FieldEditor)component); 042 } 043 } 044 super.removeAllViews(validate); 045 } 046 047 public void removeView(View component, boolean validate) 048 { 049 super.removeView(component,validate); 050 if (component instanceof FieldEditor) { 051 context.removeEditor((FieldEditor)component); 052 } 053 } 054 055 public void genHTML(PrintWriter out) throws IOException { 056 // This test is bit hackish, we should probably always have a 057 // form in the page 058 boolean showButtons = context.showButtons() && !(parentView instanceof DialogView); 059 if (showButtons) 060 out.println("<form action=\""+ 061 ((WebDisplay)context.getDisplay()).getServletName()+"\" "+ 062 "method=\"post\" accept-charset=\""+GuiAC.getEncoding()+"\" "+ 063 "enctype=\"multipart/form-data\">"); 064 065 super.genHTML(out); 066 if (showButtons) 067 out.println(" <input type=\"hidden\" name=\"source\" value=\""+getId()+"\">"); 068 if (context.hasEnabledEditor() && showButtons) { 069 out.println(" <div class=\"actions\">"); 070 out.println(" <input type=\"hidden\" name=\"event\" value=\"onValidate\">"); 071 out.println(" <input class=\"button\" type=\"submit\" name=\"onOK\" value=\""+GuiAC.getLabelOK()+"\">"); 072 out.println(" <input class=\"button\" type=\"submit\" name=\"onCancel\" value=\""+GuiAC.getLabelCancel()+"\">"); 073 /* // does not work with IE ... 074 out.println(" <button class=\"button\" type=\"submit\" name=\"event\" "+ 075 "value=onOK>"+GuiAC.getLabelOK()+"</button>"); 076 out.println(" <button class=\"button\" type=\"submit\" name=\"event\" "+ 077 "value=onCancel>"+GuiAC.getLabelCancel()+"</button>"); 078 */ 079 out.println(" </div>"); 080 } 081 if (showButtons) 082 out.println("</form>"); 083 } 084 085 // DialogListener interface 086 087 public void onOK(JacRequest request) { 088 onValidate(request); 089 ((WebDisplay)context.getDisplay()).refresh(); 090 } 091 092 public void onRefresh(JacRequest request) { 093 onValidate(request); 094 ((WebDisplay)context.getDisplay()).refresh(); 095 } 096 097 public void onValidate(JacRequest request) { 098 try { 099 WebDisplay.readValues(context,request,true); 100 setDescription(null); 101 } catch (Exception 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 getResponse() { 115 return null; 116 } 117 118 public JacRequest getRequest() { 119 return null; 120 } 121 }