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.List ; 24 import java.util.Vector ; 25 import javax.servlet.http.HttpServletResponse ; 26 import org.objectweb.jac.aspects.gui.Constants; 27 import org.objectweb.jac.aspects.gui.FieldEditor; 28 import org.objectweb.jac.aspects.gui.GuiAC; 29 30 public class EditorContainer extends Container 31 implements org.objectweb.jac.aspects.gui.EditorContainer, DialogListener 32 { 33 Vector editors = new Vector (); 34 boolean showButtons; 35 36 39 public EditorContainer(boolean showButtons) { 40 super(Constants.VERTICAL); 41 this.showButtons = showButtons; 42 } 43 44 public void addEditor(Object editor) { 45 editors.add(editor); 46 } 47 48 public void removeEditor(Object editor) { 49 editors.remove(editor); 50 } 51 52 public List getEditors() { 53 return (List)editors.clone(); 54 } 55 56 public boolean hasEnabledEditor() { 57 Iterator it = editors.iterator(); 58 while (it.hasNext()) { 59 Object view = it.next(); 60 if (view instanceof FieldEditor && 61 ((FieldEditor)view).isEnabled()) { 62 return true; 63 } 64 } 65 return false; 66 } 67 68 public void setShowButtons(boolean value) { 69 this.showButtons = value; 70 } 71 public boolean showButtons() { 72 return showButtons; 73 } 74 75 public void genHTML(PrintWriter out) throws IOException { 76 out.println("<div class=\""+type+"\">"); 77 if (!editors.isEmpty() && showButtons) { 78 out.println("<form action=\""+ 79 ((WebDisplay)context.getDisplay()).getServletName()+"\""+ 80 " accept-charset=\"utf-8\">"); 81 } 82 genItemsHTML(out); 83 if (!editors.isEmpty() && showButtons) { 84 out.println(" <div class=\"actions\">"); 85 out.println(" <input type=\"hidden\" name=\"source\" value=\""+getId()+"\">"); 86 out.println(" <button class=button type=submit name=event "+ 87 "value=\"onOK\">OK</button>"); 88 out.println(" <button class=\"button\" type=\"submit\" name=\"event\" "+ 89 "value=\"onCancel\">"+GuiAC.getLabelCancel()+"</button>"); 90 out.println(" </div>"); 91 out.println("</form>"); 92 } 93 out.println("</div>"); 94 } 95 96 98 public void onOK(JacRequest request) { 99 onValidate(request); 100 ((WebDisplay)context.getDisplay()).refresh(); 101 } 102 103 public void onRefresh(JacRequest request) { 104 onValidate(request); 105 ((WebDisplay)context.getDisplay()).refresh(); 106 } 107 108 public void onValidate(JacRequest request){ 109 Iterator i = editors.iterator(); 110 while (i.hasNext()) { 111 FieldEditor editor = (FieldEditor)i.next(); 112 ((HTMLEditor)editor).readValue(request.getParameter(editor.getLabel())); 113 ((HTMLEditor)editor).commit(); 114 } 115 } 116 117 public void onCancel() { 118 ((WebDisplay)context.getDisplay()).refresh(); 119 } 120 121 public void restoreContext() {} 122 123 public HttpServletResponse getResponse() { 124 return null; 125 } 126 127 public JacRequest getRequest() { 128 return null; 129 } 130 131 } 132 | Popular Tags |