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