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.Arrays ; 23 import java.util.Collection ; 24 import java.util.Iterator ; 25 import java.util.Vector ; 26 import org.apache.log4j.Logger; 27 import org.objectweb.jac.aspects.gui.*; 28 import org.objectweb.jac.util.ExtArrays; 29 30 33 public class AbstractCompositeView extends AbstractView 34 implements CompositeView,HTMLViewer 35 { 36 static Logger logger = Logger.getLogger("gui.close"); 37 38 Vector components = new Vector (); 39 40 public AbstractCompositeView() { 41 } 42 43 public void setContext(DisplayContext context) { 44 super.setContext(context); 45 Iterator i = getViews().iterator(); 47 while (i.hasNext()) { 48 View component = (View)i.next(); 49 component.setContext(context); 50 } 51 } 52 53 public void addHorizontalStrut(int width) {} 54 public void addVerticalStrut(int height) {} 55 56 public void addView(View view, Object extraInfo) { 57 view.setContext(context); 58 components.add(view); 59 view.setParentView(this); 60 } 61 62 public void addView(View view) { 63 addView(view,null); 64 } 65 66 public Collection getViews() { 67 return components; 68 } 69 70 public View getView(Object id) { 71 if (id instanceof String ) 72 return (View)components.get(Integer.parseInt((String )id)); 73 else if (id instanceof Integer ) 74 return (View)components.get(((Integer )id).intValue()); 75 else 76 throw new RuntimeException ("getView(): bad id "+id); 77 } 78 79 public boolean containsView(String viewType, Object [] parameters) { 80 Iterator it = components.iterator(); 81 while (it.hasNext()) { 82 View view = (View)it.next(); 83 if (view.equalsView(viewType,parameters)) 84 return true; 85 } 86 return false; 87 } 88 89 public void removeView(View component, boolean validate) { 90 component.close(validate); 91 components.remove(component); 92 } 93 94 public void removeAllViews(boolean validate) { 95 closeAllViews(validate); 96 components.clear(); 97 } 98 99 public void close(boolean validate) { 100 super.close(validate); 101 closeAllViews(validate); 102 } 103 104 protected void closeAllViews(boolean validate) { 105 logger.debug("closing "+components.size()+" components of "+this+": "+components); 106 Iterator i = ((Vector )components.clone()).iterator(); 107 while (i.hasNext()) { 108 ((View)i.next()).close(validate); 109 } 110 } 111 112 protected void add(View component) { 113 component.setParentView(this); 114 components.add(component); 115 } 116 117 public void genDescription(PrintWriter out) { 118 if (description!=null) { 119 if(!(this instanceof ObjectView && 120 (parentView!=null && parentView.getClass()==Dialog.class))) { 121 out.println("<div class=\"description\">"+description+"</div>"); 122 } 123 } 124 } 125 126 public void genMessage(PrintWriter out) { 127 if(message!=null) { 128 String msg=(String )message.invoke(null,ExtArrays.emptyObjectArray); 129 out.println("<div class=\"message\">"+msg+"</div>"); 130 } 131 } 132 133 public void genHTML(PrintWriter out) throws IOException { 134 Iterator i = components.iterator(); 135 while (i.hasNext()) { 136 HTMLViewer component = (HTMLViewer)i.next(); 137 out.println("<div class=\""+type+ 138 "\" id=\""+((View)component).getLabel()+"\">"); 139 component.genHTML(out); 140 out.println("</div>"); 141 } 142 } 143 } 144 145 | Popular Tags |