KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2   Copyright (C) 2001-2003 Renaud Pawlak <renaud@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 org.objectweb.jac.aspects.gui.*;
21 import org.objectweb.jac.core.rtti.CollectionItem;
22 import java.io.IOException JavaDoc;
23 import java.io.PrintWriter JavaDoc;
24
25 /**
26  * A nice collection view.
27  *
28  * <p>It provides a choice on the elements (for the upper part) and an embedded view of the selected object
29  */

30 public class ChoiceCollection
31     extends AbstractCollection
32     implements HTMLViewer
33 {
34
35     int oldSelected = -1;
36     ObjectView objectView = null;
37
38     public ChoiceCollection(
39         ViewFactory factory,
40         DisplayContext context,
41         CollectionItem collection,
42         Object JavaDoc substance,
43         ComboBoxModel model,
44         org.objectweb.jac.aspects.gui.CollectionItemView itemView)
45     {
46         super(factory, context, collection, substance, model, itemView);
47     }
48     /* (non-Javadoc)
49      * @see org.objectweb.jac.aspects.gui.web.AbstractCollection#sort()
50      */

51     public void sort() {
52         // TODO Auto-generated method stub
53

54     }
55
56     public void genHTML(PrintWriter JavaDoc out) throws IOException JavaDoc {
57         out.println("<div class=BORDER_LINE>");
58         out.print(GuiAC.getLabel(collection) + " : ");
59         out.print("<select name=\"index_" + getId() + "\"");
60         printAttributes(out);
61         out.println(">");
62
63         for (int i = 0; i < model.getRowCount(); i++) {
64
65             String JavaDoc label = GuiAC.toString(model.getObject(i));
66             out.println(
67                 "<option"
68                     + (i == selected ? " selected" : "")
69                     + " value=\"" + i + "\">"
70                     + label
71                     + "</OPTION>");
72         }
73         out.println("</SELECT>");
74
75         JacRequest request = WebDisplay.getRequest();
76
77         if (request.isIEUserAgent()) {
78             out.println(
79                 "<table class=\"method\"><tr><td>"
80                     + iconElement(
81                         ResourceManager.getResource("view_icon"),
82                         "view")
83                     + eventURL("view", "onView", "")
84                     + "</td></tr></table>");
85         } else {
86             out.println(
87                 "<span class=\"method\">"
88                     + iconElement(
89                         ResourceManager.getResource("view_icon"),
90                         "view")
91                     + eventURL("View", "onView", "")
92                     + "</span>");
93         }
94
95         genHeader(out, false);
96
97         // out.println(iconElement(null,"view",false)+
98
// eventURL("onView")+
99
// "\">"+"View"+"</a></td>");
100

101         out.println("</div>");
102
103         if (!GuiAC.isExternalChoiceView(collection)) {
104             if (selected != -1) {
105                 if (objectView == null || oldSelected != selected) {
106                     Object JavaDoc selectedObject = model.getObject(selected);
107                     objectView =
108                         (ObjectView) getFactory().createObjectView(
109                             GuiAC.toString(selectedObject),
110                             selectedObject,
111                             getContext());
112                 }
113                 objectView.genHTML(out);
114             }
115             oldSelected = selected;
116         }
117     }
118
119 }
120
Popular Tags