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