1 17 18 package org.objectweb.jac.aspects.gui.web; 19 20 import java.io.IOException ; 21 import java.io.PrintWriter ; 22 import java.util.Iterator ; 23 import java.util.Map ; 24 import javax.servlet.http.HttpServletResponse ; 25 import org.apache.log4j.Logger; 26 import org.objectweb.jac.aspects.gui.*; 27 import org.objectweb.jac.core.Collaboration; 28 import org.objectweb.jac.util.Semaphore; 29 30 33 public class Dialog extends AbstractPage 34 implements DialogView, DialogListener 35 { 36 static Logger loggerTimeout = Logger.getLogger("gui.timeout"); 37 static Logger loggerEvents = Logger.getLogger("gui.events"); 38 39 boolean ok = false; 40 Semaphore semaphore = new Semaphore(); 41 String description; 42 HttpServletResponse response; 43 JacRequest jacRequest; 44 45 Map attributes; 46 47 53 public Dialog(ViewFactory factory, DisplayContext context, 54 View view, Object parent, 55 String title, String description) 56 { 57 super(factory,context,view,false); 58 this.description = description; 59 attributes = Collaboration.get().getAttributes(); 60 attributes.remove(WebDisplay.REQUEST); 61 attributes.remove(WebDisplay.RESPONSE); 62 68 Iterator i = context.getEditors().iterator(); 69 while (i.hasNext()) { 70 Object editor = i.next(); 71 if (editor instanceof HTMLEditor) { 72 ((HTMLEditor)editor).setAttribute( 73 "onkeypress", 74 "return commitFormOnEnter(event,this,'event=onRefresh&source="+getId()+"')\""); 75 } 76 } 77 } 79 80 public HttpServletResponse getResponse() { 81 return response; 82 } 83 84 public JacRequest getRequest() { 85 return jacRequest; 86 } 87 88 90 public boolean waitForClose() throws TimeoutException { 91 loggerTimeout.debug("waiting for "+this+" to be closed "+ 92 GuiAC.dialogTimeout+"ms"); 93 if (!semaphore.acquire(GuiAC.dialogTimeout)) { 94 loggerTimeout.debug("Dialog timedout: "+this); 95 throw new TimeoutException(this); 96 } 97 loggerEvents.debug("closed "+this+" -> "+ok); 98 return ok; 99 } 100 101 public View getContentView() { 102 return view; 103 } 104 105 107 public void genHTML(PrintWriter out) throws IOException { 108 Collaboration c = Collaboration.get(); 109 c.addAttribute(WebDisplay.ON_ENTER_ACTION, "event=onRefresh"); 111 try { 112 super.genHTML(out); 113 } finally { 114 c.removeAttribute(WebDisplay.ON_ENTER_ACTION); 115 } 116 } 117 118 public void genBody(PrintWriter out) throws IOException { 119 out.println("<div class=\""+type+"\">"); 120 if (description!=null) 121 out.println("<div class=\"description\">"+description+"</div>"); 122 openForm(out); 123 ((HTMLViewer)view).genHTML(out); 124 showFormButtons(out); 125 closeForm(out); 126 out.println("</div>"); 127 } 128 129 131 public void restoreContext() { 132 loggerEvents.debug("Restoring attributes: "+attributes.keySet()); 133 Collaboration.get().setAttributes(attributes); 134 } 135 136 public void onOK(JacRequest request) { 137 loggerEvents.debug(this+".onOK"); 138 restoreContext(); 139 WebDisplay display = (WebDisplay)context.getDisplay(); 140 response = WebDisplay.getResponse(); 141 jacRequest = WebDisplay.getRequest(); 142 display.closeWindow(this,true); 143 ok = true; 144 semaphore.release(); 145 } 146 147 public void onRefresh(JacRequest request) { 148 loggerEvents.debug(this+".onRefresh"); 149 WebDisplay display = (WebDisplay)context.getDisplay(); 150 restoreContext(); 151 response = WebDisplay.getResponse(); 152 jacRequest = WebDisplay.getRequest(); 153 WebDisplay.readValuesAndRefresh(context,request,true); 154 } 155 156 public void onValidate(JacRequest request) { 157 restoreContext(); 158 WebDisplay.readValues(context,request,true); 159 } 160 161 public void onCancel() { 162 loggerEvents.debug(this+".onCancel"); 163 ok = false; 164 Collaboration collab = Collaboration.get(); 165 try { 166 WebDisplay display = (WebDisplay)context.getDisplay(); 167 response = WebDisplay.getResponse(); 168 jacRequest = WebDisplay.getRequest(); 169 display.closeWindow(this,false); 171 } finally { 172 semaphore.release(); 174 } 175 } 176 } 177 | Popular Tags |