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.admin;
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.jboss.seam.contexts.Contexts;
031import org.nuxeo.ecm.core.api.DocumentModel;
032import org.nuxeo.ecm.platform.actions.Action;
033import org.nuxeo.ecm.platform.ui.web.api.NavigationContext;
034import org.nuxeo.ecm.platform.ui.web.api.TabActionsSelection;
035import org.nuxeo.ecm.platform.ui.web.api.WebActions;
036import org.nuxeo.runtime.api.Framework;
037
038/**
039 * Seam Bean used to manage navigation inside the Admin Center.
040 *
041 * @author tiry
042 */
043@Name("adminViews")
044@Scope(CONVERSATION)
045public class AdminViewManager implements Serializable {
046
047    private static final long serialVersionUID = 1L;
048
049    protected String externalPackageDownloadRequest;
050
051    public static final String ADMIN_ACTION_CATEGORY = "NUXEO_ADMIN";
052
053    public static final String VIEW_ADMIN = "view_admin";
054
055    @In(create = true, required = false)
056    protected WebActions webActions;
057
058    @In(create = true, required = false)
059    protected transient NavigationContext navigationContext;
060
061    protected DocumentModel lastVisitedDocument;
062
063    public String goHome() {
064        webActions.resetCurrentTabs(ADMIN_ACTION_CATEGORY);
065        Contexts.getEventContext().remove("currentView");
066        Contexts.getEventContext().remove("currentAdminSubView");
067        return VIEW_ADMIN;
068    }
069
070    public String enter() {
071        lastVisitedDocument = navigationContext.getCurrentDocument();
072        return VIEW_ADMIN;
073    }
074
075    public String exit() {
076        if (lastVisitedDocument != null) {
077            return navigationContext.navigateToDocument(lastVisitedDocument);
078        } else {
079            return navigationContext.goHome();
080        }
081    }
082
083    @Factory(value = "currentAdminView", scope = ScopeType.EVENT)
084    public Action getCurrentView() {
085        return webActions.getCurrentTabAction(ADMIN_ACTION_CATEGORY);
086    }
087
088    public void setCurrentView(Action currentView) {
089        webActions.setCurrentTabAction(ADMIN_ACTION_CATEGORY, currentView);
090    }
091
092    public String getCurrentViewId() {
093        return getCurrentView().getId();
094    }
095
096    public String setCurrentViewId(String currentViewId) {
097        webActions.setCurrentTabId(ADMIN_ACTION_CATEGORY, currentViewId);
098        return VIEW_ADMIN;
099    }
100
101    @Factory(value = "currentAdminSubView", scope = ScopeType.EVENT)
102    public Action getCurrentSubView() {
103        return webActions.getCurrentSubTabAction(getCurrentViewId());
104    }
105
106    public void setCurrentSubView(Action currentSubView) {
107        webActions.setCurrentTabAction(TabActionsSelection.getSubTabCategory(getCurrentViewId()), currentSubView);
108    }
109
110    @Factory(value = "currentAdminSubViewId", scope = ScopeType.EVENT)
111    public String getCurrentSubViewId() {
112        return getCurrentSubView().getId();
113    }
114
115    public void setCurrentSubViewId(String currentSubViewId) {
116        webActions.setCurrentTabId(TabActionsSelection.getSubTabCategory(getCurrentViewId()), currentSubViewId);
117    }
118
119    public List<Action> getAvailableActions() {
120        return webActions.getActionsList(ADMIN_ACTION_CATEGORY);
121    }
122
123    public List<Action> getAvailableSubActions() {
124        return webActions.getActionsList(TabActionsSelection.getSubTabCategory(getCurrentViewId()));
125    }
126
127    public boolean hasExternalPackageDownloadRequest() {
128        return externalPackageDownloadRequest != null;
129    }
130
131    public void addExternalPackageDownloadRequest(String pkgId) {
132        this.externalPackageDownloadRequest = pkgId;
133    }
134
135    public String getExternalPackageDownloadRequest() {
136        String id = externalPackageDownloadRequest;
137        externalPackageDownloadRequest = null;
138        return id;
139    }
140
141    public boolean isUpdateCenterDisabled() {
142        return Framework.isBooleanPropertyTrue("nuxeo.updatecenter.disabled");
143    }
144
145    public boolean isProductionServer() {
146        return Framework.isBooleanPropertyTrue("org.nuxeo.prod");
147    }
148
149}