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: DirectoryTreeDescriptor.java 29556 2008-01-23 00:59:39Z jcarsique $ 018 */ 019package org.nuxeo.ecm.webapp.directory; 020 021import java.util.ArrayList; 022import java.util.HashMap; 023import java.util.Map; 024 025import org.nuxeo.common.xmap.annotation.XNode; 026import org.nuxeo.common.xmap.annotation.XNodeList; 027import org.nuxeo.common.xmap.annotation.XObject; 028import org.nuxeo.ecm.directory.DirectoryException; 029import org.nuxeo.ecm.platform.actions.Action; 030import org.nuxeo.ecm.platform.actions.ActionPropertiesDescriptor; 031 032@XObject(value = "directoryTree") 033public class DirectoryTreeDescriptor { 034 035 /** 036 * @since 6.0 037 */ 038 public static final String ACTION_ID_PREFIX = "dirtree_"; 039 040 /** 041 * @since 6.0 042 */ 043 public static final String NAV_ACTION_CATEGORY = "TREE_EXPLORER"; 044 045 /** 046 * @since 6.0 047 */ 048 public static final String DIR_ACTION_CATEGORY = "DIRECTORY_TREE_EXPLORER"; 049 050 /** 051 * @deprecated since 5.6, supports other schemas than 'vocabulary' and 'xvocabulary'. 052 */ 053 @Deprecated 054 public static final String VOCABULARY_SCHEMA = "vocabulary"; 055 056 /** 057 * @deprecated since 5.6, supports other schemas than 'vocabulary' and 'xvocabulary'. 058 */ 059 @Deprecated 060 public static final String XVOCABULARY_SCHEMA = "xvocabulary"; 061 062 @XNode("@name") 063 protected String name; 064 065 @XNode("@enabled") 066 protected Boolean enabled = true; 067 068 @XNode("@isNavigationTree") 069 protected boolean isNavigationTree = true; 070 071 /** 072 * Label to be displayed as the root of the tree (description field). 073 */ 074 @XNode("@label") 075 protected String label; 076 077 /** 078 * Content view to be updated on node selection 079 */ 080 @XNode("@contentView") 081 protected String contentView; 082 083 /** 084 * Name of the QueryModel field that will be used updated on node selection. 085 */ 086 @XNode("@field") 087 protected String fieldName; 088 089 /** 090 * Name of the QueryModel schema for the field that will be used updated on node selection. 091 */ 092 @XNode("@schema") 093 protected String schemaName; 094 095 /** 096 * Id of the faces navigation case to return on node selection. 097 */ 098 @XNode("@outcome") 099 protected String outcome; 100 101 /** 102 * Allows the selection of several nodes of the tree. 103 */ 104 @XNode("@multiselect") 105 protected Boolean multiselect; 106 107 /** 108 * List of directories ids used to build the classification tree. 109 */ 110 protected String[] directories; 111 112 @XNodeList(value = "directory", componentType = String.class, type = String[].class) 113 public void setDirectories(String[] directories) throws DirectoryException { 114 this.directories = directories; 115 } 116 117 /** 118 * @since 6.0 119 */ 120 @XNode("@order") 121 protected Integer order; 122 123 public String getFieldName() { 124 return fieldName; 125 } 126 127 public String getName() { 128 return name; 129 } 130 131 public String[] getDirectories() { 132 return directories; 133 } 134 135 public String getLabel() { 136 return label; 137 } 138 139 public boolean isMultiselect() { 140 if (multiselect == null) { 141 return false; 142 } 143 return multiselect; 144 } 145 146 public String getOutcome() { 147 return outcome; 148 } 149 150 public String getContentView() { 151 return contentView; 152 } 153 154 public String getSchemaName() { 155 return schemaName; 156 } 157 158 public Boolean getEnabled() { 159 return enabled; 160 } 161 162 public boolean isNavigationTree() { 163 return isNavigationTree; 164 } 165 166 public boolean hasContentViewSupport() { 167 return contentView != null; 168 } 169 170 /** 171 * @since 6.0 172 */ 173 public Integer getOrder() { 174 return order; 175 } 176 177 public void merge(DirectoryTreeDescriptor other) { 178 if (other.schemaName != null) { 179 this.schemaName = other.schemaName; 180 } 181 if (other.contentView != null) { 182 this.contentView = other.contentView; 183 } 184 if (other.outcome != null) { 185 this.outcome = other.outcome; 186 } 187 if (other.multiselect != null) { 188 this.multiselect = other.multiselect; 189 } 190 if (other.label != null) { 191 this.label = other.label; 192 } 193 if (other.directories != null) { 194 this.directories = other.directories; 195 } 196 if (other.fieldName != null) { 197 this.fieldName = other.fieldName; 198 } 199 this.enabled = other.enabled; 200 this.isNavigationTree = other.isNavigationTree; 201 if (other.order != null) { 202 this.order = other.order; 203 } 204 } 205 206 public DirectoryTreeDescriptor clone() { 207 DirectoryTreeDescriptor clone = new DirectoryTreeDescriptor(); 208 clone.name = name; 209 clone.enabled = enabled; 210 clone.isNavigationTree = isNavigationTree; 211 clone.label = label; 212 clone.contentView = contentView; 213 clone.fieldName = fieldName; 214 clone.schemaName = schemaName; 215 clone.outcome = outcome; 216 clone.multiselect = multiselect; 217 if (directories != null) { 218 clone.directories = directories.clone(); 219 } 220 clone.order = order; 221 return clone; 222 } 223 224 /** 225 * Helper to register a simple action based on the given descriptor 226 * 227 * @since 6.0 228 */ 229 protected Action getAction() { 230 String[] cats; 231 if (isNavigationTree()) { 232 cats = new String[] { NAV_ACTION_CATEGORY, DIR_ACTION_CATEGORY }; 233 } else { 234 cats = new String[] { DIR_ACTION_CATEGORY }; 235 } 236 Action a = new Action(ACTION_ID_PREFIX + getName(), cats); 237 a.setType("rest_document_link"); 238 a.setLabel(getLabel()); 239 Map<String, String> props = new HashMap<String, String>(); 240 props.put("ajaxSupport", "true"); 241 props.put("link", "/incl/single_directory_tree_explorer.xhtml"); 242 ActionPropertiesDescriptor pdesc = new ActionPropertiesDescriptor(); 243 pdesc.setProperties(props); 244 a.setPropertiesDescriptor(pdesc); 245 Integer order = getOrder(); 246 if (order != null) { 247 a.setOrder(order.intValue()); 248 } else { 249 // use a default high default order for directory trees so that 250 // they're displayed after standard navigation trees 251 a.setOrder(1000); 252 } 253 a.setIcon(String.format("/img/%s.png", getName())); 254 // need to set a non-empty list 255 a.setEnabled(Boolean.TRUE.equals(getEnabled())); 256 a.setFilterIds(new ArrayList<String>()); 257 return a; 258 } 259 260}