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.tools; 029 030import org.opencms.util.CmsStringUtil; 031import org.opencms.workplace.CmsWorkplace; 032 033import java.util.Iterator; 034import java.util.List; 035 036/** 037 * This is an admin tool group, it just generates the html code for 038 * the group structure.<p> 039 * 040 * @since 6.0.0 041 */ 042public class CmsToolGroup { 043 044 /** Container for the items. */ 045 private final CmsIdentifiableObjectContainer<CmsTool> m_container = new CmsIdentifiableObjectContainer<CmsTool>( 046 true, 047 true); 048 049 /** Dhtml id. */ 050 private final String m_id; 051 052 /** Display name. */ 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 CmsToolGroup(String id, String name) { 062 063 m_id = id; 064 m_name = name; 065 } 066 067 /** 068 * Adds an admin tool.<p> 069 * 070 * @param adminTool the admin tool 071 * 072 * @see org.opencms.workplace.tools.CmsIdentifiableObjectContainer#addIdentifiableObject(String, Object) 073 */ 074 public void addAdminTool(CmsTool adminTool) { 075 076 m_container.addIdentifiableObject(adminTool.getId(), adminTool); 077 } 078 079 /** 080 * Adds an admin tool at the given position.<p> 081 * 082 * @param adminTool the admin tool 083 * @param position the position 084 * 085 * @see org.opencms.workplace.tools.CmsIdentifiableObjectContainer#addIdentifiableObject(String, Object, float) 086 */ 087 public void addAdminTool(CmsTool adminTool, float position) { 088 089 m_container.addIdentifiableObject(adminTool.getId(), adminTool, position); 090 } 091 092 /** 093 * Returns a list of admin tools.<p> 094 * 095 * @return a list of <code>{@link CmsTool}</code>s 096 */ 097 public List<CmsTool> getAdminTools() { 098 099 return m_container.elementList(); 100 } 101 102 /** 103 * Returns the id.<p> 104 * 105 * @return the id 106 */ 107 public String getId() { 108 109 return m_id; 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(2048); 132 Iterator<CmsTool> itItem = m_container.elementList().iterator(); 133 while (itItem.hasNext()) { 134 CmsTool item = itItem.next(); 135 html.append(item.buttonHtml(wp)); 136 } 137 if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(html.toString())) { 138 html.insert(0, ((CmsToolDialog)wp).iconsBlockAreaStart(getName())); 139 html.append(((CmsToolDialog)wp).iconsBlockAreaEnd()); 140 } 141 return html.toString(); 142 } 143 144}