001// Copyright 2013 The Apache Software Foundation
002//
003// Licensed under the Apache License, Version 2.0 (the "License");
004// you may not use this file except in compliance with the License.
005// You may obtain a copy of the License at
006//
007//     http://www.apache.org/licenses/LICENSE-2.0
008//
009// Unless required by applicable law or agreed to in writing, software
010// distributed under the License is distributed on an "AS IS" BASIS,
011// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012// See the License for the specific language governing permissions and
013// limitations under the License.
014
015package org.apache.tapestry5.internal.services.dashboard;
016
017import org.apache.tapestry5.Block;
018import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
019import org.apache.tapestry5.runtime.Component;
020import org.apache.tapestry5.services.ComponentSource;
021import org.apache.tapestry5.services.dashboard.DashboardManager;
022import org.apache.tapestry5.services.dashboard.DashboardTab;
023
024import java.util.Collections;
025import java.util.List;
026import java.util.Map;
027
028public class DashboardManagerImpl implements DashboardManager
029{
030    private final ComponentSource componentSource;
031
032    private final List<String> tabNames;
033
034    private final Map<String, String> tab2PageName = CollectionFactory.newCaseInsensitiveMap();
035
036    public DashboardManagerImpl(ComponentSource componentSource, List<DashboardTab> tabs)
037    {
038        this.componentSource = componentSource;
039
040        List<String> tabNames = CollectionFactory.newList();
041
042        for (DashboardTab tab : tabs)
043        {
044            tabNames.add(tab.tabName);
045
046            tab2PageName.put(tab.tabName, tab.pageName);
047        }
048
049        this.tabNames = Collections.unmodifiableList(tabNames);
050    }
051
052    public List<String> getTabNames()
053    {
054        return tabNames;
055    }
056
057    public Block getTabContent(String tabName)
058    {
059        Component page = componentSource.getPage(tab2PageName.get(tabName));
060
061        return page.getComponentResources().getBlock("content");
062    }
063}