001/* 002 * (C) Copyright 2007 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 * $Id: DirectoryTreeService.java 20619 2007-06-16 21:49:26Z sfermigier $ 018 */ 019package org.nuxeo.ecm.webapp.directory; 020 021import java.util.List; 022 023import org.nuxeo.ecm.platform.actions.ActionService; 024import org.nuxeo.runtime.api.Framework; 025import org.nuxeo.runtime.model.ComponentContext; 026import org.nuxeo.runtime.model.ComponentInstance; 027import org.nuxeo.runtime.model.DefaultComponent; 028 029/** 030 * Register directory tree configurations to make them available to the DirectoryTreeManagerBean to build 031 * DirectoryTreeNode instances. 032 * 033 * @author <a href="mailto:ogrisel@nuxeo.com">Olivier Grisel</a> 034 */ 035public class DirectoryTreeService extends DefaultComponent { 036 037 public static final String NAME = DirectoryTreeService.class.getName(); 038 039 protected DirectoryTreeRegistry registry; 040 041 public DirectoryTreeDescriptor getDirectoryTreeDescriptor(String treeName) { 042 return registry.getDirectoryTreeDescriptor(treeName); 043 } 044 045 @Override 046 public void activate(ComponentContext context) { 047 registry = new DirectoryTreeRegistry(); 048 } 049 050 @Override 051 public void deactivate(ComponentContext context) { 052 registry = null; 053 } 054 055 @Override 056 public void registerContribution(Object contribution, String extensionPoint, ComponentInstance contributor) { 057 DirectoryTreeDescriptor descriptor = (DirectoryTreeDescriptor) contribution; 058 registry.addContribution(descriptor); 059 getActionService().getActionRegistry().addAction(descriptor.getAction()); 060 } 061 062 @Override 063 public void unregisterContribution(Object contribution, String extensionPoint, ComponentInstance contributor) { 064 DirectoryTreeDescriptor descriptor = (DirectoryTreeDescriptor) contribution; 065 registry.removeContribution(descriptor); 066 getActionService().getActionRegistry().removeAction(descriptor.getAction().getId()); 067 } 068 069 /** 070 * @since 6.0 071 */ 072 protected ActionService getActionService() { 073 return (ActionService) Framework.getRuntime().getComponent(ActionService.ID); 074 } 075 076 public List<String> getDirectoryTrees() { 077 return registry.getDirectoryTrees(); 078 } 079 080 /** 081 * Returns only the enabled Directory Trees marked as being also Navigation Trees. 082 * 083 * @since 5.4 084 */ 085 public List<String> getNavigationDirectoryTrees() { 086 return registry.getNavigationDirectoryTrees(); 087 } 088 089}