KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > aspects > gui > web > CompactList


1 /*
2   Copyright (C) 2001-2003 Laurent Martelli <laurent@aopsys.com>
3   
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU Lesser General Public License as
6   published by the Free Software Foundation; either version 2 of the
7   License, or (at your option) any later version.
8
9   This program is distributed in the hope that it will be useful,
10   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12   GNU Lesser General Public License for more details.
13
14   You should have received a copy of the GNU Lesser General Public License
15   along with this program; if not, write to the Free Software
16   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */

17
18 package org.objectweb.jac.aspects.gui.web;
19
20 import java.io.PrintWriter JavaDoc;
21 import java.io.UnsupportedEncodingException JavaDoc;
22 import java.net.URLEncoder JavaDoc;
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 JavaDoc 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     // LinkGenerator interface
41
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 JavaDoc substance) {
53         if (model!=null)
54             model.close();
55         model = new ListModel(collection,substance);
56     }
57
58     // HTMLViewer interface
59

60     public void genHTML(PrintWriter JavaDoc 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 JavaDoc row = (String JavaDoc)((ListModel)model).getElementAt(index);
69             if (!ulOpened) {
70                 out.println("<ul class=\"list\">");
71                 ulOpened = true;
72             }
73             String JavaDoc 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")+"&amp;object="+
78                               URLEncoder.encode(name,GuiAC.getEncoding())+"\">"+row+"</a>");
79                 } catch(UnsupportedEncodingException JavaDoc 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 (/*GuiAC.isAddable(substance,collection) &&*/ isEditor) {
93             if (GuiAC.isAutoCreate(collection) && isEditor) {
94                 genCollectionEvent(out,"onAddToCollection","new_icon",GuiAC.getLabelAdd());
95                 /*
96                   genCollectionEvent(out,"onAddToCollection","new_icon","add new");
97                   genCollectionEvent(out,"onAddExistingToCollection","new_icon","add existing");
98                 */

99             } else {
100                 genCollectionEvent(out,"onAddToCollection","new_icon",GuiAC.getLabelAdd());
101             }
102         }
103
104     }
105 }
106
Popular Tags