1 17 package org.alfresco.web.ui.repo.component.shelf; 18 19 import java.io.IOException ; 20 import java.util.Iterator ; 21 import java.util.Map ; 22 23 import javax.faces.component.NamingContainer; 24 import javax.faces.component.UIComponent; 25 import javax.faces.context.FacesContext; 26 import javax.faces.context.ResponseWriter; 27 import javax.faces.el.MethodBinding; 28 import javax.faces.el.ValueBinding; 29 import javax.faces.event.AbortProcessingException; 30 import javax.faces.event.ActionEvent; 31 import javax.faces.event.FacesEvent; 32 33 import org.alfresco.web.ui.common.PanelGenerator; 34 import org.alfresco.web.ui.common.Utils; 35 import org.alfresco.web.ui.common.WebResources; 36 import org.alfresco.web.ui.common.component.SelfRenderingComponent; 37 38 41 public class UIShelf extends SelfRenderingComponent 42 { 43 46 49 public String getFamily() 50 { 51 return "org.alfresco.faces.Shelf"; 52 } 53 54 57 public void restoreState(FacesContext context, Object state) 58 { 59 Object values[] = (Object [])state; 60 super.restoreState(context, values[0]); 62 this.groupPanel = (String )values[1]; 63 this.groupBgcolor = (String )values[2]; 64 this.selectedGroupPanel = (String )values[3]; 65 this.selectedGroupBgcolor = (String )values[4]; 66 this.innerGroupPanel = (String )values[5]; 67 this.innerGroupBgcolor = (String )values[6]; 68 this.groupExpandedActionListener = (MethodBinding)values[7]; 69 } 70 71 74 public Object saveState(FacesContext context) 75 { 76 Object values[] = new Object [8]; 77 values[0] = super.saveState(context); 79 values[1] = this.groupPanel; 80 values[2] = this.groupBgcolor; 81 values[3] = this.selectedGroupPanel; 82 values[4] = this.selectedGroupBgcolor; 83 values[5] = this.innerGroupPanel; 84 values[6] = this.innerGroupBgcolor; 85 values[7] = this.groupExpandedActionListener; 86 return values; 87 } 88 89 92 public void setGroupExpandedActionListener(MethodBinding binding) 93 { 94 this.groupExpandedActionListener = binding; 95 } 96 97 100 public MethodBinding getGroupExpandedActionListener() 101 { 102 return this.groupExpandedActionListener; 103 } 104 105 108 public void decode(FacesContext context) 109 { 110 Map requestMap = context.getExternalContext().getRequestParameterMap(); 111 String fieldId = getHiddenFieldName(); 112 String value = (String )requestMap.get(fieldId); 113 114 if (value != null && value.length() != 0) 116 { 117 int sepIndex = value.indexOf(NamingContainer.SEPARATOR_CHAR); 118 int groupIndex = Integer.parseInt( value.substring(0, sepIndex) ); 119 boolean expanded = Boolean.parseBoolean( value.substring(sepIndex + 1) ); 120 121 ShelfEvent event = new ShelfEvent(this, groupIndex, expanded); 123 this.queueEvent(event); 124 } 125 } 126 127 130 public void broadcast(FacesEvent event) throws AbortProcessingException 131 { 132 if (event instanceof ShelfEvent) 133 { 134 ShelfEvent shelfEvent = (ShelfEvent)event; 135 136 int index = 0; 138 for (Iterator i=this.getChildren().iterator(); i.hasNext(); index++) 139 { 140 UIComponent child = (UIComponent)i.next(); 141 if (index == shelfEvent.Index && child instanceof UIShelfGroup) 142 { 143 ((UIShelfGroup)child).setExpanded(shelfEvent.Expanded); 145 break; 146 } 147 } 148 149 if (getGroupExpandedActionListener() != null) 151 { 152 Utils.processActionMethod(getFacesContext(), getGroupExpandedActionListener(), shelfEvent); 153 } 154 } 155 else 156 { 157 super.broadcast(event); 158 } 159 } 160 161 164 public void encodeBegin(FacesContext context) throws IOException 165 { 166 if (isRendered() == false) 167 { 168 return; 169 } 170 171 ResponseWriter out = context.getResponseWriter(); 172 173 out.write("<table border=0 cellspacing=2 cellpadding=0 width=100%>"); 175 } 176 177 180 public void encodeChildren(FacesContext context) throws IOException 181 { 182 if (isRendered() == false) 183 { 184 return; 185 } 186 187 ResponseWriter out = context.getResponseWriter(); 188 189 int index = 0; 191 for (Iterator i=this.getChildren().iterator(); i.hasNext(); index++) 192 { 193 UIComponent child = (UIComponent)i.next(); 194 if (child instanceof UIShelfGroup) 195 { 196 UIShelfGroup group = (UIShelfGroup)child; 197 if (group.isRendered() == true) 198 { 199 boolean isExpanded = group.isExpanded(); out.write("<tr><td>"); 202 203 String contextPath = context.getExternalContext().getRequestContextPath(); 204 205 String groupPanel; 207 String groupBgcolor; 208 if (isExpanded == false) 209 { 210 groupPanel = getGroupPanel(); 211 groupBgcolor = getGroupBgcolor(); 212 } 213 else 214 { 215 groupPanel = getSelectedGroupPanel(); 216 groupBgcolor = getSelectedGroupBgcolor(); 217 } 218 if (groupBgcolor == null) 219 { 220 groupBgcolor = PanelGenerator.BGCOLOR_WHITE; 221 } 222 if (groupPanel != null) 223 { 224 PanelGenerator.generatePanelStart(out, contextPath, groupPanel, groupBgcolor); 225 } 226 227 out.write("<div style='padding-top:2px;padding-bottom:4px'><nobr>"); 229 out.write("<a HREF='#' onclick=\""); 230 String value = Integer.toString(index) + NamingContainer.SEPARATOR_CHAR + Boolean.toString(!isExpanded); 232 out.write(Utils.generateFormSubmit(context, this, getHiddenFieldName(), value)); 233 out.write("\">"); 234 if (isExpanded == true) 235 { 236 out.write(Utils.buildImageTag(context, WebResources.IMAGE_EXPANDED, 11, 11, "")); 237 } 238 else 239 { 240 out.write(Utils.buildImageTag(context, WebResources.IMAGE_COLLAPSED, 11, 11, "")); 241 } 242 out.write("</a> "); 243 244 String label = group.getLabel(); 246 out.write("<span"); 247 outputAttribute(out, group.getAttributes().get("style"), "style"); 248 outputAttribute(out, group.getAttributes().get("styleClass"), "class"); 249 out.write('>'); 250 out.write(Utils.encode(label)); 251 out.write("</span>"); 252 out.write("</nobr></div>"); 253 254 if (isExpanded == true) 255 { 256 String innerGroupPanel = getInnerGroupPanel(); 258 String innerGroupBgcolor = getInnerGroupBgcolor(); 259 if (innerGroupBgcolor == null) 260 { 261 innerGroupBgcolor = PanelGenerator.BGCOLOR_WHITE; 262 } 263 if (innerGroupPanel != null) 264 { 265 PanelGenerator.generatePanelStart(out, contextPath, innerGroupPanel, innerGroupBgcolor); 266 } 267 268 Utils.encodeRecursive(context, group); 270 271 if (innerGroupPanel != null) 272 { 273 PanelGenerator.generatePanelEnd(out, contextPath, innerGroupPanel); 274 } 275 } 276 277 PanelGenerator.generatePanelEnd(out, contextPath, groupPanel); 279 out.write("</td></tr>"); 280 } 281 } 282 } 283 } 284 285 288 public void encodeEnd(FacesContext context) throws IOException 289 { 290 if (isRendered() == false) 291 { 292 return; 293 } 294 295 ResponseWriter out = context.getResponseWriter(); 296 297 out.write("</table>"); 298 } 299 300 303 public boolean getRendersChildren() 304 { 305 return true; 306 } 307 308 309 312 315 public String getGroupPanel() 316 { 317 ValueBinding vb = getValueBinding("groupPanel"); 318 if (vb != null) 319 { 320 this.groupPanel = (String )vb.getValue(getFacesContext()); 321 } 322 323 return this.groupPanel; 324 } 325 326 329 public void setGroupPanel(String groupPanel) 330 { 331 this.groupPanel = groupPanel; 332 } 333 334 337 public String getGroupBgcolor() 338 { 339 ValueBinding vb = getValueBinding("groupBgcolor"); 340 if (vb != null) 341 { 342 this.groupBgcolor = (String )vb.getValue(getFacesContext()); 343 } 344 345 return this.groupBgcolor; 346 } 347 348 351 public void setGroupBgcolor(String groupBgcolor) 352 { 353 this.groupBgcolor = groupBgcolor; 354 } 355 356 359 public String getSelectedGroupPanel() 360 { 361 ValueBinding vb = getValueBinding("selectedGroupPanel"); 362 if (vb != null) 363 { 364 this.selectedGroupPanel = (String )vb.getValue(getFacesContext()); 365 } 366 367 return this.selectedGroupPanel; 368 } 369 370 373 public void setSelectedGroupPanel(String selectedGroupPanel) 374 { 375 this.selectedGroupPanel = selectedGroupPanel; 376 } 377 378 381 public String getSelectedGroupBgcolor() 382 { 383 ValueBinding vb = getValueBinding("selectedGroupBgcolor"); 384 if (vb != null) 385 { 386 this.selectedGroupBgcolor = (String )vb.getValue(getFacesContext()); 387 } 388 389 return this.selectedGroupBgcolor; 390 } 391 392 395 public void setSelectedGroupBgcolor(String selectedGroupBgcolor) 396 { 397 this.selectedGroupBgcolor = selectedGroupBgcolor; 398 } 399 400 403 public String getInnerGroupPanel() 404 { 405 ValueBinding vb = getValueBinding("innerGroupPanel"); 406 if (vb != null) 407 { 408 this.innerGroupPanel = (String )vb.getValue(getFacesContext()); 409 } 410 411 return this.innerGroupPanel; 412 } 413 414 417 public void setInnerGroupPanel(String innerGroupPanel) 418 { 419 this.innerGroupPanel = innerGroupPanel; 420 } 421 422 425 public String getInnerGroupBgcolor() 426 { 427 ValueBinding vb = getValueBinding("innerGroupBgcolor"); 428 if (vb != null) 429 { 430 this.innerGroupBgcolor = (String )vb.getValue(getFacesContext()); 431 } 432 433 return this.innerGroupBgcolor; 434 } 435 436 439 public void setInnerGroupBgcolor(String innerGroupBgcolor) 440 { 441 this.innerGroupBgcolor = innerGroupBgcolor; 442 } 443 444 445 448 454 private String getHiddenFieldName() 455 { 456 return getClientId(getFacesContext()); 457 } 458 459 460 463 466 public static class ShelfEvent extends ActionEvent 467 { 468 public ShelfEvent(UIComponent component, int index, boolean expanded) 469 { 470 super(component); 471 Expanded = expanded; 472 Index = index; 473 } 474 475 public boolean Expanded; 476 public int Index; 477 } 478 479 480 483 484 private String groupPanel; 485 private String groupBgcolor; 486 private String selectedGroupPanel; 487 private String selectedGroupBgcolor; 488 private String innerGroupPanel; 489 private String innerGroupBgcolor; 490 private MethodBinding groupExpandedActionListener; 491 } 492 | Popular Tags |