001/*
002 * (C) Copyright 2010 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     Nuxeo - initial API and implementation
018 */
019
020package org.nuxeo.ecm.user.center;
021
022import static org.jboss.seam.ScopeType.CONVERSATION;
023
024import java.io.Serializable;
025import java.util.List;
026
027import org.jboss.seam.ScopeType;
028import org.jboss.seam.annotations.Factory;
029import org.jboss.seam.annotations.In;
030import org.jboss.seam.annotations.Name;
031import org.jboss.seam.annotations.Scope;
032import org.nuxeo.ecm.platform.actions.Action;
033import org.nuxeo.ecm.platform.ui.web.api.TabActionsSelection;
034import org.nuxeo.ecm.platform.ui.web.api.WebActions;
035
036/**
037 * Seam Bean used to manage navigation inside the User Center.
038 *
039 * @author tiry
040 */
041@Name("userCenterViews")
042@Scope(CONVERSATION)
043public class UserCenterViewManager implements Serializable {
044
045    private static final long serialVersionUID = 1L;
046
047    public static final String USER_CENTER_ACTION_CATEGORY = "USER_CENTER";
048
049    public static final String VIEW_HOME = "view_home";
050
051    @In(create = true, required = false)
052    protected WebActions webActions;
053
054    @Factory(value = "currentUserCenterView", scope = ScopeType.EVENT)
055    public Action getCurrentView() {
056        return webActions.getCurrentTabAction(USER_CENTER_ACTION_CATEGORY);
057    }
058
059    public void setCurrentView(Action currentView) {
060        webActions.setCurrentTabAction(USER_CENTER_ACTION_CATEGORY, currentView);
061    }
062
063    public String getCurrentViewId() {
064        return getCurrentView().getId();
065    }
066
067    public String setCurrentViewId(String currentViewId) {
068        webActions.setCurrentTabId(USER_CENTER_ACTION_CATEGORY, currentViewId);
069        return VIEW_HOME;
070    }
071
072    @Factory(value = "currentUserCenterSubView", scope = ScopeType.EVENT)
073    public Action getCurrentSubView() {
074        return webActions.getCurrentSubTabAction(getCurrentViewId());
075    }
076
077    public void setCurrentSubView(Action currentSubView) {
078        webActions.setCurrentTabAction(TabActionsSelection.getSubTabCategory(getCurrentViewId()), currentSubView);
079    }
080
081    @Factory(value = "currentUserCenterSubViewId", scope = ScopeType.EVENT)
082    public String getCurrentSubViewId() {
083        return getCurrentSubView().getId();
084    }
085
086    public void setCurrentSubViewId(String currentSubViewId) {
087        webActions.setCurrentTabId(TabActionsSelection.getSubTabCategory(getCurrentViewId()), currentSubViewId);
088    }
089
090    public List<Action> getAvailableActions() {
091        return webActions.getActionsList(USER_CENTER_ACTION_CATEGORY);
092    }
093
094    public List<Action> getAvailableSubActions() {
095        return webActions.getActionsList(TabActionsSelection.getSubTabCategory(getCurrentViewId()));
096    }
097
098    public String navigateTo(Action action) {
099        setCurrentView(action);
100        return VIEW_HOME;
101    }
102
103}