001/* 002 * (C) Copyright 2014 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-2.1.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 * <a href="mailto:grenard@nuxeo.com">Guillaume</a> 016 */ 017package org.nuxeo.ecm.collections.jsf.actions; 018 019import java.io.Serializable; 020import java.util.List; 021 022import org.jboss.seam.Component; 023import org.jboss.seam.ScopeType; 024import org.jboss.seam.annotations.Name; 025import org.jboss.seam.annotations.Scope; 026import org.jboss.seam.annotations.intercept.BypassInterceptors; 027import org.nuxeo.ecm.collections.api.CollectionConstants; 028import org.nuxeo.ecm.collections.api.CollectionManager; 029import org.nuxeo.ecm.core.api.CoreSession; 030import org.nuxeo.ecm.core.api.DocumentModel; 031import org.nuxeo.ecm.platform.ui.web.api.NavigationContext; 032import org.nuxeo.runtime.api.Framework; 033 034/** 035 * @since 5.9.3 036 */ 037@Name("currentDocumentCollection") 038@Scope(ScopeType.PAGE) 039@BypassInterceptors 040public class CurrentDocumentCollectionBean implements Serializable { 041 042 private static final long serialVersionUID = 1L; 043 044 protected boolean hasCurrentDocumentMoreCollectionToDisplay = false; 045 046 private boolean isDisplayAll; 047 048 public List<DocumentModel> getCurrentDocumentCollections() { 049 final NavigationContext navigationContext = (NavigationContext) Component.getInstance("navigationContext", true); 050 final DocumentModel currentDocument = navigationContext.getCurrentDocument(); 051 final CollectionManager collectionManager = Framework.getLocalService(CollectionManager.class); 052 if (!collectionManager.isCollectable(currentDocument)) { 053 return null; 054 } 055 final CoreSession session = (CoreSession) Component.getInstance("documentManager", true); 056 List<DocumentModel> result = collectionManager.getVisibleCollection(currentDocument, 057 isDisplayAll ? CollectionConstants.MAX_COLLECTION_RETURNED 058 : CollectionConstants.DEFAULT_COLLECTION_RETURNED, session); 059 if (!isDisplayAll && result.size() == CollectionConstants.DEFAULT_COLLECTION_RETURNED) { 060 hasCurrentDocumentMoreCollectionToDisplay = true; 061 } else { 062 isDisplayAll = true; 063 hasCurrentDocumentMoreCollectionToDisplay = false; 064 } 065 return result; 066 } 067 068 public Boolean getHasCurrentDocumentMoreCollectionToDisplay() { 069 return hasCurrentDocumentMoreCollectionToDisplay; 070 } 071 072 public boolean isDisplayAll() { 073 return isDisplayAll; 074 } 075 076 public void setDisplayAll(final boolean isDisplayAll) { 077 this.isDisplayAll = isDisplayAll; 078 } 079 080}