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.objectweb.jac.aspects.gui.*; 024 import org.objectweb.jac.core.Collaboration; 025 import org.objectweb.jac.util.Semaphore; 026 027 /** 028 * An HTML page containing a View and a close button. 029 */ 030 public class RefreshPage extends Page implements DialogView 031 { 032 033 public RefreshPage(View view) { 034 super(view,false); 035 } 036 037 // Konqueror bug workaround 038 int count = 0; 039 040 // HTMLViewer interface 041 public void genBody(PrintWriter out) throws IOException { 042 ((HTMLViewer)view).genHTML(out); 043 044 out.println( 045 "<script type=\"text/javascript\">"+ 046 "setTimeout(\"window.location.href = '"+ 047 getBaseURL()+"?event=onRefresh&source="+getId()+ 048 "&refresh="+(count++)+"';\", '3000');"+ 049 "</script>"); 050 } 051 052 HttpServletResponse response; 053 JacRequest jacRequest; 054 Semaphore semaphore = new Semaphore(); 055 boolean waiting = false; 056 057 public boolean waitForClose() throws TimeoutException { 058 waiting = true; 059 semaphore.acquire(); 060 // Sets the response and request so that the caller can use them 061 WebDisplay.setResponse(response); 062 WebDisplay.setRequest(jacRequest); 063 return true; 064 } 065 066 public void restoreContext() {} 067 068 // WindowListener interface 069 070 public void onRefresh(JacRequest request) { 071 if (waiting) { 072 response = WebDisplay.getResponse(); 073 jacRequest = WebDisplay.getRequest(); 074 ((WebDisplay)context.getDisplay()).closeWindow(this,false); 075 semaphore.release(); 076 } else { 077 super.onRefresh(request); 078 } 079 } 080 081 public void onClose() { 082 throw new RuntimeException("onClose is not implemented for RefreshPage"); 083 } 084 }