1 18 19 package org.objectweb.jac.aspects.gui.web; 20 21 import org.objectweb.jac.aspects.gui.*; 22 import org.objectweb.jac.core.rtti.CollectionItem; 23 import org.objectweb.jac.util.ExtArrays; 24 import java.io.IOException ; 25 import java.io.PrintWriter ; 26 import java.util.Collection ; 27 import java.util.Iterator ; 28 29 35 36 public class CollectionItemView extends AbstractView 37 implements HTMLViewer, CollectionItemViewListener, AbstractCollectionItemView 38 { 39 Object substance; 40 CollectionItem collection; 41 CollectionView collectionView; 42 CollectionModel model; 43 44 int current; 45 ObjectView objectView; 46 String viewType; 47 String [] viewParams; 48 View hiddenView; 49 50 56 public CollectionItemView(View view, 57 CollectionPosition coll, 58 String viewType, String [] viewParams, 59 View hiddenView) { 60 this.objectView = (ObjectView) view; 61 this.collection = coll.getCollection(); 62 this.collectionView = coll.getCollectionView(); 63 this.model = this.collectionView.getCollectionModel(); 64 this.current = coll.getIndex(); 65 this.substance = coll.getSubstance(); 66 this.viewType = viewType; 67 this.viewParams = viewParams; 68 this.hiddenView = hiddenView; 69 } 70 71 public View getView() 72 { 73 return objectView; 74 } 75 76 public void close(boolean validate) { 77 super.close(validate); 78 objectView.close(validate); 79 } 80 81 public void setCollection(CollectionItem coll) { 82 collection = coll; 83 } 84 85 public CollectionItem getCollection() { 86 return collection; 87 } 88 89 public void setCurrent(int index) { 90 current = index; 91 } 92 93 public int getCurrent() { 94 return current; 95 } 96 97 private void genPrevNext(String prev, 98 String next, 99 int total, 100 PrintWriter out) { 101 out.println("<div class=\"navTool\">"); 102 103 if (prev != null) 104 { 105 out.println("<div class=\"prev\">"); 106 out.print("<a HREF=\"" 107 + eventURL("onPreviousInCollection") 108 + "\">" 109 + "(" + prev + ")" 110 + iconElement(ResourceManager.getResource("previous_icon"), 111 "previous") 112 + "</a>"); 113 out.println(" "); 114 out.println("</div>"); 115 } 116 117 int cur = current + 1; 118 out.print("[" + cur + " / " + total + "]"); 119 120 if (next != null) 121 { 122 out.println("<div class=\"next\">"); 123 out.print("<a HREF=\"" 124 + eventURL("onNextInCollection") 125 + "\">" 126 + iconElement(ResourceManager.getResource("next_icon"), 127 "next") 128 + "(" + next + ")" 129 + "</a>"); 130 out.println("</div>"); 131 } 132 133 if (((View)collectionView).isClosed()) { 134 out.println("<div class=\"back\">"); 135 out.print("<a HREF=\"" 136 +eventURL("onBackToCollection") 137 +"\">"); 138 out.print(iconElement(ResourceManager.getResource("up_icon"), 139 "back")); 140 out.print("</a>"); 141 out.println("</div>"); 142 } 143 144 if (GuiAC.isRemovable(collection)) { 145 out.println("<div class=\"remove\">"); 146 out.print("<a HREF=\"" 147 +eventURL("onRemoveInCollection") 148 +"\">" 149 +iconElement(ResourceManager.getResource("remove_icon"), 150 "remove")); 151 out.println("</a>"); 152 out.println("</div>"); 153 } 154 155 out.println("</div>"); 156 } 157 158 public void genHTML(PrintWriter out) throws IOException { 159 if (!GuiAC.hasSetNavBar(context.getCustomizedView().getCustomizedGUI(), 160 collection)) { 161 objectView.genHTML(out); 162 return; 163 } 164 165 int size = model.getRowCount(); 166 167 String prevStr = 168 (current>0) ? GuiAC.toString(model.getObject(current-1)) : null; 169 String nextStr = 170 (current<(size-1)) ? 171 GuiAC.toString(model.getObject(current+1)) : 172 null; 173 174 genPrevNext(prevStr, nextStr, size, out); 175 objectView.genHTML(out); 176 genPrevNext(prevStr, nextStr, size, out); 177 } 178 179 180 public void onNextInCollection() { 181 if (current < model.getRowCount()-1) 182 { 183 current++; 184 if (collectionView!=null) 185 collectionView.setSelected(current); 186 Object curr = model.getObject(current); 187 objectView.close(true); 188 objectView = (ObjectView) factory.createView("target[?]", viewType, 189 ExtArrays.add(curr,viewParams), 190 context); 191 } 192 context.getDisplay().refresh(); 193 } 194 195 public void onPreviousInCollection() { 196 Collection col = collection.getActualCollection(substance); 197 if (current > 0) { 198 current--; 199 if (collectionView!=null) 200 collectionView.setSelected(current); 201 Object curr = model.getObject(current); 202 objectView.close(true); 203 objectView = (ObjectView) 204 factory.createView("target[?]", viewType, 205 ExtArrays.add(curr,viewParams), 206 context); 207 } 208 context.getDisplay().refresh(); 209 } 210 211 protected CompositeView findPanel() { 212 View current = getParentView(); 213 View last = null; 214 while (current!=null && !(current instanceof PanelView)) { 215 last = current; 216 current = current.getParentView(); 217 } 218 return (CompositeView)last; 219 } 220 221 public void onBackToCollection() { 222 CompositeView panel = findPanel(); 223 if (panel!=null) { 224 int numRows = GuiAC.getNumRowsPerPage(collection); 225 GuiAC.setStartIndex( 226 collection, 227 numRows>0 ? (current - current%numRows) : 0); 228 try { 229 panel.addView( 230 factory.createView(substance.getClass().getName(), 231 "Object",new Object [] {"default",substance},context)); 232 } finally { 233 GuiAC.removeStartIndex(collection); 234 } 235 } 236 context.getDisplay().refresh(); 237 } 238 239 public void onRemoveInCollection() { 240 Collection col = collection.getActualCollection(substance); 241 int old = current; 242 243 if (current > 0) { 244 current--; 245 } else if (col.size() <= 1) { 246 col.clear(); 247 objectView.close(true); 248 onBackToCollection(); 249 return; 250 } 251 252 Object curr = null; 253 Iterator it = col.iterator(); 254 for (int i=0; it.hasNext() && i<=old; i++) 255 curr = it.next(); 256 257 try { 258 collection.removeThroughRemover(substance,curr); 259 } catch (Exception e) { 260 e.printStackTrace(); 261 current = old; 262 context.getDisplay().refresh(); 263 return; 264 } 265 266 Iterator it2 = col.iterator(); 267 for (int i=0; it2.hasNext() && i<=current; i++) { 268 curr = it2.next(); 269 } 270 objectView.close(true); 271 objectView = (ObjectView) factory.createView("target[?]", viewType, 272 ExtArrays.add(curr,viewParams), 273 context); 274 275 if (current > 0) 276 collectionView.setSelected(current); 277 278 context.getDisplay().refresh(); 279 } 280 281 } 282 | Popular Tags |