KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > workplace > administration > CmsAdminMenuGroup


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/administration/CmsAdminMenuGroup.java,v $
3  * Date : $Date: 2005/06/24 11:24:57 $
4  * Version: $Revision: 1.6 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.workplace.administration;
33
34 import org.opencms.util.CmsIdentifiableObjectContainer;
35 import org.opencms.workplace.CmsWorkplace;
36 import org.opencms.workplace.tools.CmsToolMacroResolver;
37
38 import java.util.Iterator JavaDoc;
39 import java.util.List JavaDoc;
40
41 /**
42  * Container for menu items that generates the necesary html code for a group of items.<p>
43  *
44  * @author Michael Moossen
45  *
46  * @version $Revision: 1.6 $
47  *
48  * @since 6.0.0
49  */

50 public class CmsAdminMenuGroup {
51
52     /** Item container. */
53     private final CmsIdentifiableObjectContainer m_container = new CmsIdentifiableObjectContainer(true, true);
54
55     /** Dhtml id, from name. */
56     private final String JavaDoc m_id;
57
58     /** Name of the group. */
59     private final String JavaDoc m_name;
60
61     /**
62      * Default Constructor.<p>
63      *
64      * @param id a unique id
65      * @param name the name of the group
66      */

67     public CmsAdminMenuGroup(String JavaDoc id, String JavaDoc name) {
68
69         m_id = id;
70         m_name = name;
71     }
72
73     /**
74      * Adds a menu item.<p>
75      *
76      * @param item the item
77      *
78      * @see org.opencms.util.I_CmsIdentifiableObjectContainer#addIdentifiableObject(String, Object)
79      */

80     public void addMenuItem(CmsAdminMenuItem item) {
81
82         m_container.addIdentifiableObject(item.getId(), item);
83     }
84
85     /**
86      * Adds a menu item at the given position.<p>
87      *
88      * @param item the item
89      * @param position the position
90      *
91      * @see org.opencms.util.I_CmsIdentifiableObjectContainer#addIdentifiableObject(String, Object, float)
92      */

93     public void addMenuItem(CmsAdminMenuItem item, float position) {
94
95         m_container.addIdentifiableObject(item.getId(), item, position);
96     }
97
98     /**
99      * Returns the dhtml unique id.<p>
100      *
101      * @return the dhtml unique id
102      */

103     public String JavaDoc getId() {
104
105         return m_id;
106     }
107
108     /**
109      * Retuns a list of menu items.<p>
110      *
111      * @return a list of <code>{@link CmsAdminMenuItem}</code>s
112      */

113     public List JavaDoc getMenuItems() {
114
115         return m_container.elementList();
116     }
117
118     /**
119      * Returns the group name.<p>
120      *
121      * @return the group name
122      */

123     public String JavaDoc getName() {
124
125         return m_name;
126     }
127
128     /**
129      * Returns the necessary html code.<p>
130      *
131      * @param wp the jsp page to write the code to
132      *
133      * @return html code
134      */

135     public String JavaDoc groupHtml(CmsWorkplace wp) {
136
137         StringBuffer JavaDoc html = new StringBuffer JavaDoc(512);
138         html.append(htmlStart(wp));
139         Iterator JavaDoc itItem = m_container.elementList().iterator();
140         while (itItem.hasNext()) {
141             CmsAdminMenuItem item = (CmsAdminMenuItem)itItem.next();
142             html.append(item.itemHtml(wp));
143             html.append("\n");
144         }
145         html.append(htmlEnd());
146         return html.toString();
147     }
148
149     /**
150      * Generates the last part of the html code.<p>
151      *
152      * @return html code
153      */

154     private String JavaDoc htmlEnd() {
155
156         StringBuffer JavaDoc html = new StringBuffer JavaDoc(512);
157         html.append("\t\t\t\t\t\t</td>\n");
158         html.append("\t\t\t\t\t</tr>\n");
159         html.append("\t\t\t\t</table>\n");
160         html.append("\t\t\t</div>\n");
161         html.append("\t\t</td>\n");
162         html.append("\t</tr>\n");
163         html.append("</table>\n");
164         return html.toString();
165     }
166
167     /**
168      * Generates the first part of the html code.<p>
169      *
170      * @param wp the workplace
171      *
172      * @return html code
173      */

174     private String JavaDoc htmlStart(CmsWorkplace wp) {
175
176         StringBuffer JavaDoc html = new StringBuffer JavaDoc(1024);
177         html.append("<table border='0' cellspacing='0' cellpadding='0' width='100%' class='navOpened' id='");
178         html.append(getId());
179         html.append("'>\n");
180         html.append("\t<tr>\n");
181         html.append("\t\t<td class='titleBorder'>\n");
182         html.append("\t\t\t<table border='0' cellspacing='0' cellpadding='0' width='100%' class='navTitle' onMouseOver='mouseGroupEvent(this, true);' onMouseOut='mouseGroupEvent(this, false);' onClick=\"return openGroup('");
183         html.append(getId());
184         html.append("');\" >\n");
185         html.append("\t\t\t\t<tr>\n");
186         html.append("\t\t\t\t\t<td class='titleText' width='100%'>");
187         html.append(CmsToolMacroResolver.resolveMacros(getName(), wp));
188         html.append("</td>\n");
189         html.append("\t\t\t\t</tr>\n");
190         html.append("\t\t\t</table>\n");
191         html.append("\t\t</td>\n");
192         html.append("\t</tr><tr>\n");
193         html.append("\t\t<td class='treeBorder'>\n");
194         html.append("\t\t\t<div class='tree'>\n");
195         html.append("\t\t\t\t<table border='0' cellspacing='0' cellpadding='0' width='100%'>\n");
196         html.append("\t\t\t\t\t<tr>\n");
197         html.append("\t\t\t\t\t\t<td>\n");
198         return html.toString();
199     }
200
201 }
Popular Tags