001/* 002 * (C) Copyright 2012 Nuxeo SA (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 * Anahide Tchertchian 016 */ 017package org.nuxeo.ecm.styleguide; 018 019import static org.jboss.seam.ScopeType.CONVERSATION; 020 021import java.util.List; 022 023import org.jboss.seam.annotations.In; 024import org.jboss.seam.annotations.Name; 025import org.jboss.seam.annotations.Scope; 026import org.nuxeo.ecm.platform.actions.Action; 027import org.nuxeo.ecm.platform.actions.ejb.ActionManager; 028 029/** 030 * @since 5.7 031 */ 032@Name("styleGuideActions") 033@Scope(CONVERSATION) 034public class StyleGuideActions { 035 036 public static final String PAGE_ACTION_CAT = "STYLE_GUIDE_PAGE"; 037 038 @In(create = true, required = false) 039 protected transient ActionManager actionManager; 040 041 protected Action currentPage; 042 043 protected List<Action> pages; 044 045 public Action getCurrentPage() { 046 if (currentPage == null) { 047 // initialize 048 getPages(); 049 if (pages != null && !pages.isEmpty()) { 050 currentPage = pages.get(0); 051 } 052 } 053 return currentPage; 054 } 055 056 public void setCurrentPage(Action currentPage) { 057 this.currentPage = currentPage; 058 } 059 060 public String getCurrentPageId() { 061 Action currentPage = getCurrentPage(); 062 if (currentPage != null) { 063 return currentPage.getId(); 064 } 065 return null; 066 } 067 068 public void setCurrentPageId(String currentPageId) { 069 this.currentPage = actionManager.getAction(currentPageId, null, true); 070 } 071 072 public List<Action> getPages() { 073 if (pages == null) { 074 pages = getActions(PAGE_ACTION_CAT); 075 } 076 return pages; 077 } 078 079 public List<Action> getActions(String cat) { 080 return actionManager.getActions(cat, null); 081 } 082 083}