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