001/* 002 * (C) Copyright 2010 Nuxeo SAS (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * Nuxeo - initial API and implementation 016 */ 017 018package org.nuxeo.ecm.user.center; 019 020import static org.jboss.seam.ScopeType.CONVERSATION; 021 022import java.io.Serializable; 023import java.util.List; 024 025import org.jboss.seam.ScopeType; 026import org.jboss.seam.annotations.Factory; 027import org.jboss.seam.annotations.In; 028import org.jboss.seam.annotations.Name; 029import org.jboss.seam.annotations.Scope; 030import org.nuxeo.ecm.platform.actions.Action; 031import org.nuxeo.ecm.platform.ui.web.api.TabActionsSelection; 032import org.nuxeo.ecm.platform.ui.web.api.WebActions; 033 034/** 035 * Seam Bean used to manage navigation inside the User Center. 036 * 037 * @author tiry 038 */ 039@Name("userCenterViews") 040@Scope(CONVERSATION) 041public class UserCenterViewManager implements Serializable { 042 043 private static final long serialVersionUID = 1L; 044 045 public static final String USER_CENTER_ACTION_CATEGORY = "USER_CENTER"; 046 047 public static final String VIEW_HOME = "view_home"; 048 049 @In(create = true, required = false) 050 protected WebActions webActions; 051 052 @Factory(value = "currentUserCenterView", scope = ScopeType.EVENT) 053 public Action getCurrentView() { 054 return webActions.getCurrentTabAction(USER_CENTER_ACTION_CATEGORY); 055 } 056 057 public void setCurrentView(Action currentView) { 058 webActions.setCurrentTabAction(USER_CENTER_ACTION_CATEGORY, currentView); 059 } 060 061 public String getCurrentViewId() { 062 return getCurrentView().getId(); 063 } 064 065 public String setCurrentViewId(String currentViewId) { 066 webActions.setCurrentTabId(USER_CENTER_ACTION_CATEGORY, currentViewId); 067 return VIEW_HOME; 068 } 069 070 @Factory(value = "currentUserCenterSubView", scope = ScopeType.EVENT) 071 public Action getCurrentSubView() { 072 return webActions.getCurrentSubTabAction(getCurrentViewId()); 073 } 074 075 public void setCurrentSubView(Action currentSubView) { 076 webActions.setCurrentTabAction(TabActionsSelection.getSubTabCategory(getCurrentViewId()), currentSubView); 077 } 078 079 @Factory(value = "currentUserCenterSubViewId", scope = ScopeType.EVENT) 080 public String getCurrentSubViewId() { 081 return getCurrentSubView().getId(); 082 } 083 084 public void setCurrentSubViewId(String currentSubViewId) { 085 webActions.setCurrentTabId(TabActionsSelection.getSubTabCategory(getCurrentViewId()), currentSubViewId); 086 } 087 088 public List<Action> getAvailableActions() { 089 return webActions.getActionsList(USER_CENTER_ACTION_CATEGORY); 090 } 091 092 public List<Action> getAvailableSubActions() { 093 return webActions.getActionsList(TabActionsSelection.getSubTabCategory(getCurrentViewId())); 094 } 095 096 public String navigateTo(Action action) { 097 setCurrentView(action); 098 return VIEW_HOME; 099 } 100 101}