001/* 002 * (C) Copyright 2006-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$ 018 */ 019 020package org.nuxeo.ecm.platform.ui.web.directory; 021 022import java.util.Arrays; 023import java.util.List; 024import java.util.Map; 025 026import javax.faces.component.UIComponent; 027import javax.faces.component.UIInput; 028import javax.faces.context.FacesContext; 029import javax.faces.el.ValueBinding; 030 031import org.apache.commons.logging.Log; 032import org.apache.commons.logging.LogFactory; 033import org.nuxeo.ecm.platform.ui.web.util.BaseURL; 034 035/** 036 * @deprecated : component is useless (not declared correctly in deployment-fragment.xml and bugg) should be refactored 037 * instead 038 */ 039@Deprecated 040public class ChainSelectMultiListboxComponent extends UIInput { 041 042 public static final String COMPONENT_TYPE = "nxdirectory.chainSelectMultiListbox"; 043 044 public static final String COMPONENT_FAMILY = "nxdirectory.chainSelectMultiListbox"; 045 046 @SuppressWarnings("unused") 047 private static final Log log = LogFactory.getLog(ChainSelectMultiListboxComponent.class); 048 049 public boolean ajaxUpdated = false; 050 051 private List<String> directoriesNames; 052 053 private List<VocabularyEntryList> directoriesValues; 054 055 private Boolean displayIdAndLabel; 056 057 private Boolean displayObsoleteEntries = false; 058 059 private String onchange; 060 061 private int index; 062 063 private String ordering; 064 065 private String displayIdAndLabelSeparator = " "; 066 067 private String cssStyle; 068 069 private String cssStyleClass; 070 071 private String size; 072 073 private Boolean localize = false; 074 075 private String displayValueOnlySeparator; 076 077 private String display; 078 079 public ChainSelectMultiListboxComponent() { 080 setRendererType(COMPONENT_TYPE); 081 } 082 083 @Override 084 public String getFamily() { 085 return COMPONENT_FAMILY; 086 } 087 088 public boolean isMultiSelect() { 089 ChainSelect chain = getChain(); 090 if (size != null && Integer.valueOf(size) < 2) { 091 // this allows the last element to be a simple select box event 092 // though the global chain is a multiselect thanks to some ajax add 093 // button 094 return false; 095 } 096 return index == chain.getSize() - 1 && chain.getBooleanProperty("multiSelect", false); 097 } 098 099 public String getDisplayIdAndLabelSeparator() { 100 return displayIdAndLabelSeparator; 101 } 102 103 public void setDisplayIdAndLabelSeparator(String displayIdAndLabelSeparator) { 104 this.displayIdAndLabelSeparator = displayIdAndLabelSeparator; 105 } 106 107 @Override 108 @SuppressWarnings("unchecked") 109 public void restoreState(FacesContext context, Object state) { 110 Object[] values = (Object[]) state; 111 super.restoreState(context, values[0]); 112 index = (Integer) values[1]; 113 displayIdAndLabel = (Boolean) values[2]; 114 displayIdAndLabelSeparator = (String) values[3]; 115 displayObsoleteEntries = (Boolean) values[4]; 116 ajaxUpdated = (Boolean) values[5]; 117 directoriesNames = (List<String>) values[6]; 118 localize = (Boolean) values[7]; 119 displayValueOnlySeparator = (String) values[10]; 120 onchange = (String) values[11]; 121 cssStyle = (String) values[12]; 122 cssStyleClass = (String) values[13]; 123 size = (String) values[14]; 124 directoriesValues = (List<VocabularyEntryList>) values[15]; 125 ordering = (String) values[16]; 126 display = (String) values[17]; 127 } 128 129 @Override 130 public Object saveState(FacesContext context) { 131 Object[] values = new Object[18]; 132 values[0] = super.saveState(context); 133 values[1] = index; 134 values[2] = displayIdAndLabel; 135 values[3] = displayIdAndLabelSeparator; 136 values[4] = displayObsoleteEntries; 137 values[5] = ajaxUpdated; 138 values[6] = directoriesNames; 139 values[7] = localize; 140 values[10] = displayValueOnlySeparator; 141 values[11] = onchange; 142 values[12] = cssStyle; 143 values[13] = cssStyleClass; 144 values[14] = size; 145 values[15] = directoriesValues; 146 values[16] = ordering; 147 values[17] = display; 148 return values; 149 } 150 151 public List<String> getDirectoriesNamesArray() { 152 return directoriesNames; 153 } 154 155 public String getDirectoriesNames() { 156 // concat dir names 157 StringBuilder buf = new StringBuilder(); 158 String comma = ""; 159 for (String directoryName : directoriesNames) { 160 buf.append(comma); 161 comma = ","; 162 buf.append(directoryName); 163 } 164 return buf.toString(); 165 } 166 167 public void setDirectoriesNames(String newDirectiriesNames) { 168 if (newDirectiriesNames == null) { 169 throw new IllegalArgumentException("null newDirectiriesNames"); 170 } 171 directoriesNames = Arrays.asList(newDirectiriesNames.split(",")); 172 } 173 174 /* 175 * public List<VocabularyEntryList> getDirectoriesValues() { List<VocabularyEntryList> list = new 176 * ArrayList<VocabularyEntryList>(); ValueBinding vb = getValueBinding("directoryValues"); if (vb != null) { 177 * list.add( (VocabularyEntryList) vb.getValue(FacesContext.getCurrentInstance()) ); } else { //return null; } 178 * return list; } 179 */ 180 public void setDirectoriesValues(List<VocabularyEntryList> directoriesValues) { 181 this.directoriesValues = directoriesValues; 182 } 183 184 public Map<String, DirectorySelectItem> getOptions() { 185 return getChain().getOptions(index); 186 } 187 188 public Boolean getDisplayIdAndLabel() { 189 return displayIdAndLabel; 190 } 191 192 public void setDisplayIdAndLabel(Boolean displayIdAndLabel) { 193 this.displayIdAndLabel = displayIdAndLabel; 194 } 195 196 public Boolean getDisplayObsoleteEntries() { 197 return displayObsoleteEntries; 198 } 199 200 public void setDisplayObsoleteEntries(Boolean showObsolete) { 201 displayObsoleteEntries = showObsolete; 202 } 203 204 public void setOnchange(String onchange) { 205 this.onchange = onchange; 206 } 207 208 public String getOnchange() { 209 return onchange; 210 } 211 212 public ChainSelect getChain() { 213 UIComponent component = getParent(); 214 while (component != null && !(component instanceof ChainSelect)) { 215 component = component.getParent(); 216 } 217 return (ChainSelect) component; 218 } 219 220 public Object getProperty(String name) { 221 ValueBinding vb = getValueBinding(name); 222 if (vb != null) { 223 return vb.getValue(FacesContext.getCurrentInstance()); 224 } else { 225 return getAttributes().get(name); 226 } 227 } 228 229 public String getStringProperty(String name, String defaultValue) { 230 String value = (String) getProperty(name); 231 return value != null ? value : defaultValue; 232 } 233 234 public Boolean getBooleanProperty(String name, Boolean defaultValue) { 235 Boolean value = (Boolean) getProperty(name); 236 return value != null ? value : defaultValue; 237 } 238 239 public String getOrdering() { 240 return ordering; 241 } 242 243 public void setOrdering(String sortCriteria) { 244 ordering = sortCriteria; 245 } 246 247 public String getDisplayValueOnlySeparator() { 248 return displayValueOnlySeparator; 249 } 250 251 public void setDisplayValueOnlySeparator(String displayValueOnlySeparator) { 252 this.displayValueOnlySeparator = displayValueOnlySeparator; 253 } 254 255 public boolean isAjaxUpdated() { 256 return ajaxUpdated; 257 } 258 259 public void setAjaxUpdated(boolean ajaxUpdated) { 260 this.ajaxUpdated = ajaxUpdated; 261 } 262 263 public Integer getIndex() { 264 return index; 265 } 266 267 public void setIndex(Integer index) { 268 this.index = index; 269 } 270 271 public String getCssStyle() { 272 return cssStyle; 273 } 274 275 public void setCssStyle(String cssStyle) { 276 this.cssStyle = cssStyle; 277 } 278 279 public String getCssStyleClass() { 280 return cssStyleClass; 281 } 282 283 public void setCssStyleClass(String cssStyleClass) { 284 this.cssStyleClass = cssStyleClass; 285 } 286 287 public String getSize() { 288 return size; 289 } 290 291 public void setSize(String size) { 292 this.size = size; 293 } 294 295 public Boolean getLocalize() { 296 return localize; 297 } 298 299 public void setLocalize(Boolean localize) { 300 this.localize = localize; 301 } 302 303 // / 304 public ChainSelectListboxComponent[] createSingleComponents() { 305 306 final int ncomp = directoriesNames.size(); 307 ChainSelectListboxComponent[] sComps = new ChainSelectListboxComponent[ncomp]; 308 309 int i = 0; 310 for (String dirName : directoriesNames) { 311 ChainSelectListboxComponent comp = new ChainSelectListboxComponent(); 312 313 comp.setId(getId() + i); 314 comp.setIndex(i); 315 comp.setDirectoryName(dirName); 316 comp.setCssStyle(cssStyle); 317 comp.setCssStyleClass(cssStyleClass); 318 comp.setLocalize(localize); 319 comp.setSize(size); 320 321 String id1 = getId().split(":")[0]; 322 String id2 = getId(); 323 // XXX AT: yeah, right, that seems to be a very good idea. 324 // "A4J.AJAX.Submit('_viewRoot','j_id202',event,{'parameters':{'j_id202:j_id286':'j_id202:j_id286'},'actionUrl':'/nuxeo/documents/tabs/document_externe_edit.faces'})"; 325 onchange = "A4J.AJAX.Submit('_viewRoot','" + id1 + "',event,{'parameters':{'" + id2 + "':'" + id2 326 + "'},'actionUrl':'" + BaseURL.getContextPath() + "/documents/tabs/document_externe_edit.faces'})"; 327 328 comp.setOnchange(onchange); 329 330 // VocabularyEntryList directoryValues = 331 // getDirectoriesValues().get(0); 332 // comp.setDirectoryValues(directoryValues); 333 334 comp.setParent(getParent()); 335 336 final List<UIComponent> children = comp.getChildren(); 337 children.addAll(getChildren()); 338 339 sComps[i++] = comp; 340 } 341 342 return sComps; 343 } 344 345 public String getDisplay() { 346 return display; 347 } 348 349 public void setDisplay(String display) { 350 this.display = display; 351 } 352 353 /* 354 * @Override public boolean getRendersChildren() { return true; } 355 */ 356}