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