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 javax.servlet.http.HttpServletResponse;
023    import org.apache.log4j.Logger;
024    import org.objectweb.jac.aspects.gui.*;
025    
026    /**
027     * An HTML page containing a View and a close button.
028     */
029    public class Page extends AbstractPage implements WindowListener
030    {
031        static Logger loggerWeb = Logger.getLogger("gui.events");
032    
033        public Page(View view, boolean newWindow) {
034            super(view,newWindow);
035        }
036    
037        // HTMLViewer interface
038    
039        public void genBody(PrintWriter out) throws IOException {
040            out.println("<div class=\""+type+"\">");
041            if (description!=null)
042                out.println("<div class=\"description\">"+description+"</div>");
043            openForm(out);
044            ((HTMLViewer)view).genHTML(out);
045            showFormButtons(out,false);
046            closeForm(out);
047            out.println("</div>");
048        }
049    
050        // WindowListener interface
051    
052        HttpServletResponse response;
053        JacRequest jacRequest;
054    
055        public void onOK(JacRequest request) {
056            logger.debug(this+".onOK");
057            WebDisplay display = (WebDisplay)context.getDisplay();
058            try {
059                response = WebDisplay.getResponse();
060                jacRequest = WebDisplay.getRequest();
061                display.closeWindow(this,true);
062            } finally {
063                display.refresh();
064            }
065        }
066    
067        public void onRefresh(JacRequest request) {
068            logger.debug(this+".onRefresh");
069            WebDisplay display = (WebDisplay)context.getDisplay();
070            response = WebDisplay.getResponse();
071            jacRequest = WebDisplay.getRequest();
072            WebDisplay.readValuesAndRefresh(context,request,true);
073        }
074    
075        public void onCancel() {
076            // Each view inside the page is supposed to be validated with
077            // its own OK/Cancel buttons. Since the close link is not a
078            // button in a form, editors must not try to readValue()
079            // because there will never be any data to be read.
080            CustomizedDisplay display = (WebDisplay)context.getDisplay();
081            display.closeWindow(this,false);
082            display.refresh();
083        }
084    
085        public void onValidate(JacRequest request) {
086            WebDisplay.readValues(context,request,true);
087        }
088    }