001    /*
002      Copyright (C) 2001-2003 Renaud Pawlak <renaud@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 org.objectweb.jac.aspects.gui.*;
021    import org.objectweb.jac.core.rtti.CollectionItem;
022    import java.io.IOException;
023    import java.io.PrintWriter;
024    
025    /**
026     * A nice collection view.
027     * 
028     * <p>It provides a choice on the elements (for the upper part) and an embedded view of the selected object
029     */
030    public class ChoiceCollection
031            extends AbstractCollection
032            implements HTMLViewer 
033    {
034    
035            int oldSelected = -1;
036            ObjectView objectView = null;
037    
038            public ChoiceCollection(
039                    ViewFactory factory,
040                    DisplayContext context,
041                    CollectionItem collection,
042                    Object substance,
043                    ComboBoxModel model,
044                    org.objectweb.jac.aspects.gui.CollectionItemView itemView) 
045        {
046                    super(factory, context, collection, substance, model, itemView);
047            }
048            /* (non-Javadoc)
049             * @see org.objectweb.jac.aspects.gui.web.AbstractCollection#sort()
050             */
051            public void sort() {
052                    // TODO Auto-generated method stub
053    
054            }
055    
056            public void genHTML(PrintWriter out) throws IOException {
057                    out.println("<div class=BORDER_LINE>");
058                    out.print(GuiAC.getLabel(collection) + " : ");
059                    out.print("<select name=\"index_" + getId() + "\"");
060                    printAttributes(out);
061                    out.println(">");
062    
063                    for (int i = 0; i < model.getRowCount(); i++) {
064    
065                            String label = GuiAC.toString(model.getObject(i));
066                            out.println(
067                                    "<option"
068                                            + (i == selected ? " selected" : "")
069                                            + " value=\"" + i + "\">"
070                                            + label
071                                            + "</OPTION>");
072                    }
073                    out.println("</SELECT>");
074    
075                    JacRequest request = WebDisplay.getRequest();
076    
077                    if (request.isIEUserAgent()) {
078                            out.println(
079                                    "<table class=\"method\"><tr><td>"
080                                            + iconElement(
081                                                    ResourceManager.getResource("view_icon"),
082                                                    "view")
083                                            + eventURL("view", "onView", "")
084                                            + "</td></tr></table>");
085                    } else {
086                            out.println(
087                                    "<span class=\"method\">"
088                                            + iconElement(
089                                                    ResourceManager.getResource("view_icon"),
090                                                    "view")
091                                            + eventURL("View", "onView", "")
092                                            + "</span>");
093                    }
094    
095                    genHeader(out, false);
096    
097                    //              out.println(iconElement(null,"view",false)+
098                    //                                      eventURL("onView")+
099                    //                                      "\">"+"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 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    }