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, 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.ade.containerpage.shared; 029 030import java.util.Arrays; 031import java.util.HashMap; 032import java.util.List; 033import java.util.Map; 034import java.util.Set; 035 036import com.google.common.collect.Sets; 037import com.google.gwt.user.client.rpc.IsSerializable; 038 039/** 040 * Container bean.<p> 041 * 042 * @since 8.0.0 043 */ 044public class CmsContainer implements IsSerializable { 045 046 /** Flag indicating the container is displayed in detail view only. */ 047 private boolean m_detailOnly; 048 049 /** Flag indicating this container is used for detail views. */ 050 private boolean m_detailView; 051 052 /** Flag indicating the container is editable by the current user. */ 053 private boolean m_editable; 054 055 /** List of the contained elements. */ 056 private List<CmsContainerElement> m_elements; 057 058 /** The content to display in case the container is empty. */ 059 private String m_emptyContainerContent; 060 061 /** 062 * Indicates whether this container not nested, 063 * or in case of a detail only container page the starting point of a detail only container hierarchy. 064 **/ 065 private boolean m_isRootContainer; 066 067 /** The maximum number of elements. */ 068 private int m_maxElements; 069 070 /** The container name. */ 071 private String m_name; 072 073 /** The parent container name. */ 074 private String m_parentContainerName; 075 076 /** The parent instance id. */ 077 private String m_parentInstanceId; 078 079 private Map<String, String> m_settingPresets = new HashMap<String, String>(); 080 081 /** The container type. */ 082 private String m_type; 083 084 /** The width of the container. */ 085 private int m_width; 086 087 /** 088 * Constructor.<p> 089 * 090 * @param name the container name, also used as id within a container-page 091 * @param type the container type 092 * @param emptyContainerContent content to display in case the container is empty 093 * @param width the width of the container 094 * @param maxElements the maximum number of elements displayed by this container 095 * @param detailView flag indicating this container is used for detail views 096 * @param editable flag indicating the container is editable by the current user 097 * @param elements the container elements id's 098 * @param parentContainerName the parent container name 099 * @param parentInstanceId the parent instance id 100 * @param settingPresets the presets for container element settings 101 */ 102 public CmsContainer( 103 String name, 104 String type, 105 String emptyContainerContent, 106 int width, 107 int maxElements, 108 boolean detailView, 109 boolean editable, 110 List<CmsContainerElement> elements, 111 String parentContainerName, 112 String parentInstanceId, 113 Map<String, String> settingPresets) { 114 115 m_elements = elements; 116 m_name = name; 117 m_type = type; 118 m_emptyContainerContent = emptyContainerContent; 119 m_maxElements = maxElements; 120 m_width = width; 121 m_detailView = detailView; 122 m_editable = editable; 123 m_parentContainerName = parentContainerName; 124 m_parentInstanceId = parentInstanceId; 125 m_settingPresets = settingPresets != null ? settingPresets : new HashMap<String, String>(); 126 } 127 128 /** 129 * Hidden default constructor (for GWT serialization).<p> 130 */ 131 protected CmsContainer() { 132 133 // do nothing 134 } 135 136 /** 137 * Splits the type attribute of a container into individual types.<p> 138 * 139 * @param containerTypeSpec the container type attribute 140 * 141 * @return the entries of the type attribute 142 */ 143 public static Set<String> splitType(String containerTypeSpec) { 144 145 return Sets.newHashSet(Arrays.asList(containerTypeSpec.trim().split(" *, *"))); 146 147 } 148 149 /** 150 * Returns the list of the contained elements id's.<p> 151 * 152 * @return the list of the contained elements id's 153 */ 154 public List<CmsContainerElement> getElements() { 155 156 return m_elements; 157 } 158 159 /** 160 * Returns the content to display in case the container is empty.<p> 161 * 162 * @return the content to display in case the container is empty 163 */ 164 public String getEmptyContainerContent() { 165 166 return m_emptyContainerContent; 167 } 168 169 /** 170 * Returns the maximum number of elements allowed in this container.<p> 171 * 172 * @return the maximum number of elements allowed in this container 173 */ 174 public int getMaxElements() { 175 176 return m_maxElements; 177 } 178 179 /** 180 * Returns the container name, also used as HTML-id for the container DOM-element. Has to be unique within the template.<p> 181 * 182 * @return the container name 183 */ 184 public String getName() { 185 186 return m_name; 187 } 188 189 /** 190 * Returns the parent container name.<p> 191 * 192 * @return the parent container name 193 */ 194 public String getParentContainerName() { 195 196 return m_parentContainerName; 197 } 198 199 /** 200 * Returns the parent instance id.<p> 201 * 202 * @return the parent instance id 203 */ 204 public String getParentInstanceId() { 205 206 return m_parentInstanceId; 207 } 208 209 public Map<String, String> getSettingPresets() { 210 211 return m_settingPresets; 212 } 213 214 /** 215 * Returns the container type. Used to determine the formatter used to render the contained elements.<p> 216 * 217 * @return the container type 218 */ 219 public String getType() { 220 221 return m_type; 222 } 223 224 /** 225 * Returns the container width.<p> 226 * 227 * @return the container width 228 */ 229 public int getWidth() { 230 231 return m_width; 232 } 233 234 /** 235 * Returns <code>true</code> if the container is displayed in detail view only.<p> 236 * 237 * @return <code>true</code> if the container is displayed in detail view only 238 */ 239 public boolean isDetailOnly() { 240 241 return m_detailOnly; 242 } 243 244 /** 245 * Returns if this container is used for detail views.<p> 246 * 247 * @return <code>true</code> if this container is used for detail views 248 */ 249 public boolean isDetailView() { 250 251 return m_detailView; 252 } 253 254 /** 255 * Returns if the container is editable by the current user.<p> 256 * 257 * @return <code>true</code> if the container is editable by the current user 258 */ 259 public boolean isEditable() { 260 261 return m_editable; 262 } 263 264 /** 265 * Returns if this container not nested, 266 * or in case of a detail only container page the starting point of a detail only container hierarchy.<p> 267 * 268 * @return <code>true</code> if this container not nested 269 */ 270 public boolean isRootContainer() { 271 272 return m_isRootContainer; 273 } 274 275 /** 276 * Returns if this is a sub container.<p> 277 * 278 * @return <code>true</code> this is a sub container 279 */ 280 public boolean isSubContainer() { 281 282 return m_parentContainerName != null; 283 } 284 285 /** 286 * Sets the detail only flag.<p> 287 * 288 * @param detailOnly <code>true</code> if the container is displayed in detail view only 289 */ 290 public void setDeatilOnly(boolean detailOnly) { 291 292 m_detailOnly = detailOnly; 293 } 294 295 /** 296 * Sets the elements contained in this container.<p> 297 * 298 * @param elements the elements 299 */ 300 public void setElements(List<CmsContainerElement> elements) { 301 302 m_elements = elements; 303 304 } 305 306 /** 307 * Sets the maxElements.<p> 308 * 309 * @param maxElements the maxElements to set 310 */ 311 public void setMaxElements(int maxElements) { 312 313 m_maxElements = maxElements; 314 } 315 316 /** 317 * Sets the name.<p> 318 * 319 * @param name the name to set 320 */ 321 public void setName(String name) { 322 323 m_name = name; 324 } 325 326 /** 327 * Sets the if this container not nested, 328 * or in case of a detail only container page the starting point of a detail only container hierarchy.<p> 329 * 330 * @param isRootContainer <code>true</code> if this container not nested 331 */ 332 public void setRootContainer(boolean isRootContainer) { 333 334 m_isRootContainer = isRootContainer; 335 } 336 337 /** 338 * Sets the type.<p> 339 * 340 * @param type the type to set 341 */ 342 public void setType(String type) { 343 344 m_type = type; 345 } 346 347 /** 348 * @see java.lang.Object#toString() 349 */ 350 @Override 351 public String toString() { 352 353 return "[Container name='" 354 + m_name 355 + "' type='" 356 + m_type 357 + "' numElements='" 358 + (m_elements == null ? 0 : m_elements.size()) 359 + "']"; 360 } 361 362}