001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com) 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * For further information about Alkacon Software GmbH & Co. KG, please see the 018 * company website: http://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: http://www.opencms.org 022 * 023 * You should have received a copy of the GNU Lesser General Public 024 * License along with this library; if not, write to the Free Software 025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 026 */ 027 028package org.opencms.workplace.administration; 029 030import org.opencms.workplace.CmsWorkplace; 031import org.opencms.workplace.tools.CmsIdentifiableObjectContainer; 032import org.opencms.workplace.tools.CmsToolMacroResolver; 033 034import java.util.Iterator; 035import java.util.List; 036 037/** 038 * Container for menu items that generates the necesary html code for a group of items.<p> 039 * 040 * @since 6.0.0 041 */ 042public class CmsAdminMenuGroup { 043 044 /** Item container. */ 045 private final CmsIdentifiableObjectContainer<CmsAdminMenuItem> m_container = new CmsIdentifiableObjectContainer<CmsAdminMenuItem>( 046 true, 047 true); 048 049 /** Dhtml id, from name. */ 050 private final String m_id; 051 052 /** Name of the group. */ 053 private final String m_name; 054 055 /** 056 * Default Constructor.<p> 057 * 058 * @param id a unique id 059 * @param name the name of the group 060 */ 061 public CmsAdminMenuGroup(String id, String name) { 062 063 m_id = id; 064 m_name = name; 065 } 066 067 /** 068 * Adds a menu item.<p> 069 * 070 * @param item the item 071 * 072 * @see org.opencms.workplace.tools.CmsIdentifiableObjectContainer#addIdentifiableObject(String, Object) 073 */ 074 public void addMenuItem(CmsAdminMenuItem item) { 075 076 m_container.addIdentifiableObject(item.getId(), item); 077 } 078 079 /** 080 * Adds a menu item at the given position.<p> 081 * 082 * @param item the item 083 * @param position the position 084 * 085 * @see org.opencms.workplace.tools.CmsIdentifiableObjectContainer#addIdentifiableObject(String, Object, float) 086 */ 087 public void addMenuItem(CmsAdminMenuItem item, float position) { 088 089 m_container.addIdentifiableObject(item.getId(), item, position); 090 } 091 092 /** 093 * Returns the dhtml unique id.<p> 094 * 095 * @return the dhtml unique id 096 */ 097 public String getId() { 098 099 return m_id; 100 } 101 102 /** 103 * Returns a list of menu items.<p> 104 * 105 * @return a list of <code>{@link CmsAdminMenuItem}</code>s 106 */ 107 public List<CmsAdminMenuItem> getMenuItems() { 108 109 return m_container.elementList(); 110 } 111 112 /** 113 * Returns the group name.<p> 114 * 115 * @return the group name 116 */ 117 public String getName() { 118 119 return m_name; 120 } 121 122 /** 123 * Returns the necessary html code.<p> 124 * 125 * @param wp the jsp page to write the code to 126 * 127 * @return html code 128 */ 129 public String groupHtml(CmsWorkplace wp) { 130 131 StringBuffer html = new StringBuffer(512); 132 html.append(htmlStart(wp)); 133 Iterator<CmsAdminMenuItem> itItem = m_container.elementList().iterator(); 134 while (itItem.hasNext()) { 135 CmsAdminMenuItem item = itItem.next(); 136 html.append(item.itemHtml(wp)); 137 html.append("\n"); 138 } 139 html.append(htmlEnd()); 140 return html.toString(); 141 } 142 143 /** 144 * Generates the last part of the html code.<p> 145 * 146 * @return html code 147 */ 148 private String htmlEnd() { 149 150 StringBuffer html = new StringBuffer(512); 151 html.append("\t\t\t\t\t\t</td>\n"); 152 html.append("\t\t\t\t\t</tr>\n"); 153 html.append("\t\t\t\t</table>\n"); 154 html.append("\t\t\t</div>\n"); 155 html.append("\t\t</td>\n"); 156 html.append("\t</tr>\n"); 157 html.append("</table>\n"); 158 return html.toString(); 159 } 160 161 /** 162 * Generates the first part of the html code.<p> 163 * 164 * @param wp the workplace 165 * 166 * @return html code 167 */ 168 private String htmlStart(CmsWorkplace wp) { 169 170 StringBuffer html = new StringBuffer(1024); 171 html.append("<table border='0' cellspacing='0' cellpadding='0' width='100%' class='navOpened' id='"); 172 html.append(getId()); 173 html.append("'>\n"); 174 html.append("\t<tr>\n"); 175 html.append("\t\t<td class='titleBorder'>\n"); 176 html.append( 177 "\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('"); 178 html.append(getId()); 179 html.append("');\" >\n"); 180 html.append("\t\t\t\t<tr>\n"); 181 html.append("\t\t\t\t\t<td class='titleText' width='100%'>"); 182 html.append(CmsToolMacroResolver.resolveMacros(getName(), wp)); 183 html.append("</td>\n"); 184 html.append("\t\t\t\t</tr>\n"); 185 html.append("\t\t\t</table>\n"); 186 html.append("\t\t</td>\n"); 187 html.append("\t</tr><tr>\n"); 188 html.append("\t\t<td class='treeBorder'>\n"); 189 html.append("\t\t\t<div class='tree'>\n"); 190 html.append("\t\t\t\t<table border='0' cellspacing='0' cellpadding='0' width='100%'>\n"); 191 html.append("\t\t\t\t\t<tr>\n"); 192 html.append("\t\t\t\t\t\t<td>\n"); 193 return html.toString(); 194 } 195 196}