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.file.CmsObject;
031import org.opencms.main.OpenCms;
032import org.opencms.ui.A_CmsUI;
033import org.opencms.ui.I_CmsUpdateListener;
034
035import java.util.List;
036import java.util.Locale;
037
038import com.google.common.collect.Lists;
039
040/**
041 * Displays all available app.<p>
042 */
043public class CmsAppHierachy implements I_CmsWorkplaceApp, I_CmsCachableApp {
044
045    /** The serial version id. */
046    private static final long serialVersionUID = -2767203655877536034L;
047
048    /**
049     * @see org.opencms.ui.apps.I_CmsWorkplaceApp#initUI(org.opencms.ui.apps.I_CmsAppUIContext)
050     */
051    public void initUI(I_CmsAppUIContext context) {
052
053        CmsObject cms = A_CmsUI.getCmsObject();
054        Locale locale = OpenCms.getWorkplaceManager().getWorkplaceLocale(cms);
055        List<I_CmsWorkplaceAppConfiguration> visibleApps = Lists.newArrayList();
056        for (I_CmsWorkplaceAppConfiguration appConfig : OpenCms.getWorkplaceAppManager().getWorkplaceApps()) {
057            CmsAppVisibilityStatus status = appConfig.getVisibility(cms);
058            if (status.isVisible()) {
059                visibleApps.add(appConfig);
060            }
061        }
062        CmsAppHierarchyBuilder hierarchyBuilder = new CmsAppHierarchyBuilder();
063        for (I_CmsWorkplaceAppConfiguration app : visibleApps) {
064            hierarchyBuilder.addAppConfiguration(app);
065        }
066        for (I_CmsAppCategory category : OpenCms.getWorkplaceAppManager().getCategories()) {
067            hierarchyBuilder.addCategory(category);
068        }
069
070        CmsAppHierarchyPanel hierarchyPanel = new CmsAppHierarchyPanel(new CmsDefaultAppButtonProvider());
071        hierarchyPanel.fill(hierarchyBuilder.buildHierarchy(), locale);
072
073        context.setAppContent(hierarchyPanel);
074        context.showInfoArea(false);
075        context.addPublishButton(new I_CmsUpdateListener<String>() {
076
077            public void onUpdate(List<String> updatedItems) {
078                // ignore
079            }
080        });
081    }
082
083    /**
084     * @see org.opencms.ui.apps.I_CmsCachableApp#isCachable()
085     */
086    public boolean isCachable() {
087
088        return true;
089    }
090
091    /**
092     * @see org.opencms.ui.apps.I_CmsCachableApp#onRestoreFromCache()
093     */
094    public void onRestoreFromCache() {
095        // do nothing
096    }
097
098    /**
099     * @see org.opencms.ui.apps.I_CmsWorkplaceApp#onStateChange(java.lang.String)
100     */
101    public void onStateChange(String state) {
102
103        // nothing to do
104    }
105}