001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (C) Alkacon Software (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.acacia.client; 029 030import java.util.ArrayList; 031import java.util.Collections; 032import java.util.List; 033 034/** 035 * A bean which contains the data for a choice menu entry.<p> 036 */ 037public class CmsChoiceMenuEntryBean { 038 039 /** The child entries of this choice. */ 040 protected List<CmsChoiceMenuEntryBean> m_children = new ArrayList<CmsChoiceMenuEntryBean>(); 041 042 /** The parent of this entry. */ 043 protected CmsChoiceMenuEntryBean m_parent; 044 045 /** The path component (attribute id) of this menu entry. */ 046 protected String m_pathComponent; 047 048 /** 049 * Creates a new choice menu entry bean. 050 * 051 * @param pathComponent the path component of the choice (attribute id) 052 */ 053 public CmsChoiceMenuEntryBean(String pathComponent) { 054 055 // path component may be null for dummy root entries 056 m_pathComponent = pathComponent; 057 } 058 059 /** 060 * Adds a new child entry to this bean and returns it.<p> 061 * 062 * @param pathComponent the path component of the child 063 * 064 * @return the new child 065 */ 066 public CmsChoiceMenuEntryBean addChild(String pathComponent) { 067 068 assert pathComponent != null; 069 CmsChoiceMenuEntryBean child = new CmsChoiceMenuEntryBean(pathComponent); 070 m_children.add(child); 071 child.m_parent = this; 072 return child; 073 } 074 075 /** 076 * Gets the list of children of this entry.<p> 077 * 078 * @return the list of children 079 */ 080 public List<CmsChoiceMenuEntryBean> getChildren() { 081 082 return m_children; 083 } 084 085 /** 086 * Gets the help text for the menu entry.<p> 087 * 088 * @param widgetService the widget service to ask for labels 089 * 090 * @return the help text 091 */ 092 public String getHelp(I_CmsWidgetService widgetService) { 093 094 return widgetService.getAttributeHelp(m_pathComponent); 095 } 096 097 /** 098 * Gets the label for the menu entry.<p> 099 * 100 * @param widgetService the widget service to ask for label texts 101 * 102 * @return the entry label 103 */ 104 public String getLabel(I_CmsWidgetService widgetService) { 105 106 return widgetService.getAttributeLabel(m_pathComponent); 107 } 108 109 /** 110 * Gets the parent entry of this entry.<p> 111 * 112 * @return the parent entry 113 */ 114 public CmsChoiceMenuEntryBean getParent() { 115 116 return m_parent; 117 } 118 119 /** 120 * Gets the complete path of this entry, which is a list of attribute ids.<p> 121 * 122 * @return the path of this entry 123 */ 124 public List<String> getPath() { 125 126 List<String> result = new ArrayList<String>(); 127 CmsChoiceMenuEntryBean entry = this; 128 while (entry != null) { 129 String pathComponent = entry.getPathComponent(); 130 if (pathComponent != null) { 131 // pathComponent may be null for a dummy root entry 132 result.add(entry.getPathComponent()); 133 } 134 entry = entry.m_parent; 135 } 136 Collections.reverse(result); 137 return result; 138 } 139 140 /** 141 * Gets the path component of this entry.<p> 142 * 143 * @return the path component 144 */ 145 public String getPathComponent() { 146 147 return m_pathComponent; 148 } 149 150 /** 151 * Returns true if this entry has no children.<p> 152 * 153 * @return true if this entry has no children 154 */ 155 public boolean isLeaf() { 156 157 return m_children.isEmpty(); 158 } 159}