001 /* 002 Copyright (C) 2001-2003 Laurent Martelli <laurent@aopsys.com> 003 004 This program is free software; you can redistribute it and/or modify 005 it under the terms of the GNU Lesser General Public License as 006 published by the Free Software Foundation; either version 2 of the 007 License, or (at your option) any later version. 008 009 This program is distributed in the hope that it will be useful, 010 but WITHOUT ANY WARRANTY; without even the implied warranty of 011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 012 GNU Lesser General Public License for more details. 013 014 You should have received a copy of the GNU Lesser General Public License 015 along with this program; if not, write to the Free Software 016 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 017 018 package org.objectweb.jac.aspects.gui.web; 019 020 import java.io.PrintWriter; 021 import java.io.UnsupportedEncodingException; 022 import java.net.URLEncoder; 023 import org.objectweb.jac.aspects.gui.*; 024 import org.objectweb.jac.core.NameRepository; 025 import org.objectweb.jac.core.rtti.CollectionItem; 026 027 public class CompactList extends AbstractCollection 028 implements HTMLViewer, CollectionListener, LinkGenerator 029 { 030 public CompactList(ViewFactory factory, DisplayContext context, 031 CollectionItem collection, Object substance, 032 CollectionModel model, 033 org.objectweb.jac.aspects.gui.CollectionItemView itemView) { 034 super(factory,context,collection,substance,model,itemView); 035 } 036 037 public CompactList() { 038 } 039 040 // LinkGenerator interface 041 boolean enableLinks = true; 042 public void setEnableLinks(boolean enable) { 043 this.enableLinks = enable; 044 } 045 public boolean areLinksEnabled() { 046 return enableLinks; 047 } 048 049 public void sort() { 050 } 051 052 public void updateModel(Object substance) { 053 if (model!=null) 054 model.close(); 055 model = new ListModel(collection,substance); 056 } 057 058 // HTMLViewer interface 059 060 public void genHTML(PrintWriter out) { 061 sort(); 062 063 boolean ulOpened = false; 064 for (int index=startIndex; 065 (!split || index<startIndex+rowsPerPage) && index<model.getRowCount(); 066 index++) 067 { 068 String row = (String)((ListModel)model).getElementAt(index); 069 if (!ulOpened) { 070 out.println("<ul class=\"list\">"); 071 ulOpened = true; 072 } 073 String name = NameRepository.get().getName(model.getObject(index)); 074 out.print(" <li>"); 075 if (name!=null && enableLinks) { 076 try { 077 out.print("<a href=\""+eventURL("onViewObject")+"&object="+ 078 URLEncoder.encode(name,GuiAC.getEncoding())+"\">"+row+"</a>"); 079 } catch(UnsupportedEncodingException e) { 080 logger.error(e); 081 } 082 } else { 083 out.print(row); 084 } 085 if (GuiAC.isRemovable(collection) && isEditor) 086 out.println(removeLink(index)); 087 out.print("</li>"); 088 } 089 if (ulOpened) 090 out.println("</ul>"); 091 092 if (/*GuiAC.isAddable(substance,collection) &&*/ isEditor) { 093 if (GuiAC.isAutoCreate(collection) && isEditor) { 094 genCollectionEvent(out,"onAddToCollection","new_icon",GuiAC.getLabelAdd()); 095 /* 096 genCollectionEvent(out,"onAddToCollection","new_icon","add new"); 097 genCollectionEvent(out,"onAddExistingToCollection","new_icon","add existing"); 098 */ 099 } else { 100 genCollectionEvent(out,"onAddToCollection","new_icon",GuiAC.getLabelAdd()); 101 } 102 } 103 104 } 105 }