1 17 18 package org.objectweb.jac.aspects.gui.web; 19 20 import java.io.PrintWriter ; 21 import java.io.UnsupportedEncodingException ; 22 import java.net.URLEncoder ; 23 import org.objectweb.jac.aspects.gui.*; 24 import org.objectweb.jac.core.NameRepository; 25 import org.objectweb.jac.core.rtti.CollectionItem; 26 27 public class CompactList extends AbstractCollection 28 implements HTMLViewer, CollectionListener, LinkGenerator 29 { 30 public CompactList(ViewFactory factory, DisplayContext context, 31 CollectionItem collection, Object substance, 32 CollectionModel model, 33 org.objectweb.jac.aspects.gui.CollectionItemView itemView) { 34 super(factory,context,collection,substance,model,itemView); 35 } 36 37 public CompactList() { 38 } 39 40 boolean enableLinks = true; 42 public void setEnableLinks(boolean enable) { 43 this.enableLinks = enable; 44 } 45 public boolean areLinksEnabled() { 46 return enableLinks; 47 } 48 49 public void sort() { 50 } 51 52 public void updateModel(Object substance) { 53 if (model!=null) 54 model.close(); 55 model = new ListModel(collection,substance); 56 } 57 58 60 public void genHTML(PrintWriter out) { 61 sort(); 62 63 boolean ulOpened = false; 64 for (int index=startIndex; 65 (!split || index<startIndex+rowsPerPage) && index<model.getRowCount(); 66 index++) 67 { 68 String row = (String )((ListModel)model).getElementAt(index); 69 if (!ulOpened) { 70 out.println("<ul class=\"list\">"); 71 ulOpened = true; 72 } 73 String name = NameRepository.get().getName(model.getObject(index)); 74 out.print(" <li>"); 75 if (name!=null && enableLinks) { 76 try { 77 out.print("<a HREF=\""+eventURL("onViewObject")+"&object="+ 78 URLEncoder.encode(name,GuiAC.getEncoding())+"\">"+row+"</a>"); 79 } catch(UnsupportedEncodingException e) { 80 logger.error(e); 81 } 82 } else { 83 out.print(row); 84 } 85 if (GuiAC.isRemovable(collection) && isEditor) 86 out.println(removeLink(index)); 87 out.print("</li>"); 88 } 89 if (ulOpened) 90 out.println("</ul>"); 91 92 if ( isEditor) { 93 if (GuiAC.isAutoCreate(collection) && isEditor) { 94 genCollectionEvent(out,"onAddToCollection","new_icon",GuiAC.getLabelAdd()); 95 99 } else { 100 genCollectionEvent(out,"onAddToCollection","new_icon",GuiAC.getLabelAdd()); 101 } 102 } 103 104 } 105 } 106 | Popular Tags |