001/* 002 * (C) Copyright 2006-2008 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 * 018 * $Id$ 019 */ 020 021package org.nuxeo.ecm.webapp.tree.nav; 022 023import java.io.Serializable; 024import java.util.ArrayList; 025import java.util.HashMap; 026import java.util.Map; 027 028import org.nuxeo.common.xmap.annotation.XNode; 029import org.nuxeo.common.xmap.annotation.XObject; 030import org.nuxeo.ecm.platform.actions.Action; 031import org.nuxeo.ecm.platform.actions.ActionPropertiesDescriptor; 032import org.nuxeo.ecm.webapp.directory.DirectoryTreeDescriptor; 033 034/** 035 * Descriptor for navigation tree contributions. 036 * <p> 037 * Moved from module nuxeo-platform-virtual-navigation-web, originally added in 5.6. 038 * 039 * @since 6.0 040 */ 041@XObject("navTree") 042public class NavTreeDescriptor implements Serializable, Comparable<NavTreeDescriptor> { 043 044 /** 045 * @since 6.0 046 */ 047 public static final String ACTION_ID_PREFIX = "navtree_"; 048 049 private static final long serialVersionUID = 1L; 050 051 @XNode("@treeId") 052 private String treeId; 053 054 @XNode("@treeLabel") 055 private String treeLabel; 056 057 @XNode("@xhtmlview") 058 private String xhtmlview; 059 060 @XNode("@directoryTreeBased") 061 private boolean directoryTreeBased = false; 062 063 @XNode("@order") 064 private Integer order = Integer.valueOf(100); 065 066 @XNode("@enabled") 067 private boolean enabled = true; 068 069 public boolean isDirectoryTreeBased() { 070 return directoryTreeBased; 071 } 072 073 public void setDirectoryTreeBased(boolean directoryTreeBased) { 074 this.directoryTreeBased = directoryTreeBased; 075 } 076 077 public String getXhtmlview() { 078 return xhtmlview; 079 } 080 081 public void setXhtmlview(String xhtmlview) { 082 this.xhtmlview = xhtmlview; 083 } 084 085 public NavTreeDescriptor() { 086 } 087 088 public NavTreeDescriptor(String treeId, String treeLabel) { 089 this(treeId, treeLabel, false); 090 } 091 092 public NavTreeDescriptor(String treeId, String treeLabel, boolean directoryTreeBased) { 093 this.treeId = treeId; 094 this.treeLabel = treeLabel; 095 this.directoryTreeBased = directoryTreeBased; 096 } 097 098 public String getTreeId() { 099 return treeId; 100 } 101 102 public void setTreeId(String treeId) { 103 this.treeId = treeId; 104 } 105 106 public String getTreeLabel() { 107 return treeLabel; 108 } 109 110 public void setTreeLabel(String treeLabel) { 111 this.treeLabel = treeLabel; 112 } 113 114 public Integer getOrder() { 115 return order; 116 } 117 118 public void setEnabled(boolean enabled) { 119 this.enabled = enabled; 120 } 121 122 public boolean isEnabled() { 123 return enabled; 124 } 125 126 /** 127 * @since 5.6 128 */ 129 @Override 130 public int compareTo(NavTreeDescriptor o) { 131 return getOrder().compareTo(o.getOrder()); 132 } 133 134 /** 135 * Helper to register a simple action based on the given descriptor 136 * 137 * @since 6.0 138 */ 139 protected Action getAction() { 140 Action a = new Action(ACTION_ID_PREFIX + getTreeId(), 141 new String[] { DirectoryTreeDescriptor.NAV_ACTION_CATEGORY }); 142 a.setType("rest_document_link"); 143 a.setLabel(getTreeLabel()); 144 Map<String, String> props = new HashMap<String, String>(); 145 props.put("ajaxSupport", "true"); 146 if (isDirectoryTreeBased()) { 147 props.put("link", "/incl/single_directory_tree_explorer.xhtml"); 148 } else { 149 props.put("link", getXhtmlview()); 150 } 151 ActionPropertiesDescriptor pdesc = new ActionPropertiesDescriptor(); 152 pdesc.setProperties(props); 153 a.setPropertiesDescriptor(pdesc); 154 Integer order = getOrder(); 155 if (order != null) { 156 a.setOrder(order.intValue()); 157 } 158 a.setEnabled(isEnabled()); 159 a.setIcon(String.format("/img/%s.png", getTreeId())); 160 // need to set a non-empty list 161 a.setFilterIds(new ArrayList<String>()); 162 return a; 163 } 164 165}