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