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.ui.apps; 029 030import org.opencms.ui.apps.CmsWorkplaceAppManager.ConfigurationComparator; 031 032import java.util.ArrayList; 033import java.util.Collections; 034import java.util.List; 035import java.util.Locale; 036 037import com.vaadin.v7.ui.HorizontalLayout; 038import com.vaadin.ui.Panel; 039import com.vaadin.v7.ui.VerticalLayout; 040import com.vaadin.ui.themes.ValoTheme; 041 042/** 043 * Widget used to displays a nested hierarchy of app categories and apps.<p> 044 */ 045public class CmsAppHierarchyPanel extends VerticalLayout { 046 047 /** Serial version id.*/ 048 private static final long serialVersionUID = 1L; 049 050 /** The panel to display the apps at this tree level. */ 051 private HorizontalLayout m_appPanel; 052 053 /** The object used to generate the buttons for the apps. */ 054 private I_CmsAppButtonProvider m_appButtonProvider; 055 056 /** 057 * Creates a new instance.<p> 058 * 059 * @param buttonProvider the object to which we delegate the creation of app buttons 060 */ 061 public CmsAppHierarchyPanel(I_CmsAppButtonProvider buttonProvider) { 062 063 m_appPanel = new HorizontalLayout(); 064 m_appPanel.addStyleName(ValoTheme.LAYOUT_HORIZONTAL_WRAPPING); 065 addComponent(m_appPanel); 066 setMargin(true); 067 setSpacing(true); 068 m_appButtonProvider = buttonProvider; 069 } 070 071 /** 072 * Adds a child category panel.<p> 073 * 074 * @param label the label 075 * @param child the child widget 076 */ 077 public void addChild(String label, CmsAppHierarchyPanel child) { 078 079 Panel panel = new Panel(); 080 panel.setCaption(label); 081 panel.setContent(child); 082 addComponent(panel); 083 } 084 085 /** 086 * Displays the given tree of categories and apps in the tree.<p> 087 * 088 * @param rootNode the rootNode to render in this panel 089 * @param locale the locale to use 090 */ 091 public void fill(CmsAppCategoryNode rootNode, Locale locale) { 092 093 List<I_CmsHasOrder> configurations = new ArrayList<I_CmsHasOrder>(); 094 configurations.addAll(rootNode.getAppConfigurations()); 095 configurations.addAll(rootNode.getChildren()); 096 Collections.sort(configurations, new ConfigurationComparator<I_CmsHasOrder>()); 097 for (I_CmsHasOrder config : configurations) { 098 if (config instanceof I_CmsWorkplaceAppConfiguration) { 099 m_appPanel.addComponent(m_appButtonProvider.createAppButton((I_CmsWorkplaceAppConfiguration)config)); 100 } else { 101 CmsAppCategoryNode childNode = (CmsAppCategoryNode)config; 102 if (childNode.getCategory() instanceof I_CmsFolderAppCategory) { 103 m_appPanel.addComponent(m_appButtonProvider.createAppFolderButton(childNode)); 104 } else { 105 CmsAppHierarchyPanel childPanel = new CmsAppHierarchyPanel(m_appButtonProvider); 106 addChild(childNode.getCategory().getName(locale), childPanel); 107 childPanel.fill(childNode, locale); 108 } 109 } 110 } 111 } 112}