001/* 002 * (C) Copyright 2006-2008 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 * 016 * $Id$ 017 */ 018 019package org.nuxeo.ecm.webapp.tree.nav; 020 021import static org.jboss.seam.ScopeType.CONVERSATION; 022import static org.jboss.seam.annotations.Install.FRAMEWORK; 023 024import java.io.Serializable; 025import java.util.Map; 026 027import org.apache.commons.lang.StringUtils; 028import org.jboss.seam.annotations.In; 029import org.jboss.seam.annotations.Install; 030import org.jboss.seam.annotations.Name; 031import org.jboss.seam.annotations.Observer; 032import org.jboss.seam.annotations.Scope; 033import org.jboss.seam.annotations.intercept.BypassInterceptors; 034import org.jboss.seam.core.Events; 035import org.nuxeo.ecm.core.api.impl.DocumentModelImpl; 036import org.nuxeo.ecm.platform.ui.web.api.WebActions; 037import org.nuxeo.ecm.webapp.action.WebActionsBean; 038import org.nuxeo.ecm.webapp.directory.DirectoryTreeDescriptor; 039import org.nuxeo.ecm.webapp.directory.DirectoryTreeManager; 040import org.nuxeo.ecm.webapp.helpers.EventNames; 041 042/** 043 * Seam component to handle MultiTree navigation 044 * <p> 045 * Moved from module nuxeo-platform-virtual-navigation-web, added in 5.6. 046 * 047 * @since 6.0 048 */ 049@Name("multiNavTreeManager") 050@Scope(CONVERSATION) 051@Install(precedence = FRAMEWORK) 052public class MultiNavTreeManager implements Serializable { 053 054 private static final long serialVersionUID = 1L; 055 056 public static final String STD_NAV_TREE = "CONTENT_TREE"; 057 058 protected String thePath = ""; 059 060 @In(required = false, create = true) 061 protected WebActionsBean webActions; 062 063 @In(required = false, create = true) 064 protected DirectoryTreeManager directoryTreeManager; 065 066 @In(create = true) 067 protected Map<String, String> messages; 068 069 public void setSelectedNavigationTree(String selectedNavigationTree) { 070 webActions.setCurrentTabId(DirectoryTreeDescriptor.NAV_ACTION_CATEGORY, selectedNavigationTree); 071 } 072 073 public String getSelectedNavigationTree() { 074 String id = webActions.getCurrentTabId(DirectoryTreeDescriptor.NAV_ACTION_CATEGORY); 075 if (id != null) { 076 if (id.startsWith(DirectoryTreeDescriptor.ACTION_ID_PREFIX)) { 077 return id.substring(DirectoryTreeDescriptor.ACTION_ID_PREFIX.length()); 078 } 079 if (id.startsWith(DirectoryTreeDescriptor.ACTION_ID_PREFIX)) { 080 return id.substring(DirectoryTreeDescriptor.ACTION_ID_PREFIX.length()); 081 } 082 return id; 083 } 084 return null; 085 } 086 087 @Observer(value = { WebActions.CURRENT_TAB_CHANGED_EVENT + "_" + DirectoryTreeDescriptor.NAV_ACTION_CATEGORY, 088 WebActions.CURRENT_TAB_CHANGED_EVENT + "_" + DirectoryTreeDescriptor.DIR_ACTION_CATEGORY }, create = true) 089 public void onCurrentTreeChange(String category, String tabId) { 090 // raise this event in order to reset the documents lists from 091 // 'conversationDocumentsListsManager' 092 Events.instance().raiseEvent(EventNames.FOLDERISHDOCUMENT_SELECTION_CHANGED, new DocumentModelImpl("Folder")); 093 if (tabId != null) { 094 if (tabId.startsWith(DirectoryTreeDescriptor.ACTION_ID_PREFIX)) { 095 directoryTreeManager.setSelectedTreeName(tabId.substring(DirectoryTreeDescriptor.ACTION_ID_PREFIX.length())); 096 } 097 if (tabId.startsWith(DirectoryTreeDescriptor.DIR_ACTION_CATEGORY)) { 098 directoryTreeManager.setSelectedTreeName(tabId.substring(DirectoryTreeDescriptor.DIR_ACTION_CATEGORY.length())); 099 } 100 } 101 } 102 103 @Observer(value = { "PATH_PROCESSED" }, create = false) 104 @BypassInterceptors 105 public void setThePath(String myPath) { 106 thePath = myPath; 107 } 108 109 public String getVirtualNavPath() { 110 String[] partOfPath = thePath.split("/"); 111 String finalPath = ""; 112 for (String aPart : partOfPath) { 113 if (!StringUtils.isBlank(aPart)) { 114 finalPath = finalPath + " > " + messages.get(aPart); 115 } 116 } 117 return finalPath; 118 } 119 120}