1 17 package org.alfresco.web.ui.common.component; 18 19 import java.io.IOException ; 20 import java.util.Map ; 21 22 import javax.faces.component.NamingContainer; 23 import javax.faces.component.UICommand; 24 import javax.faces.component.UIComponent; 25 import javax.faces.component.UIForm; 26 import javax.faces.context.FacesContext; 27 import javax.faces.context.ResponseWriter; 28 import javax.faces.el.MethodBinding; 29 import javax.faces.el.ValueBinding; 30 import javax.faces.event.AbortProcessingException; 31 import javax.faces.event.ActionEvent; 32 import javax.faces.event.FacesEvent; 33 34 import org.alfresco.web.ui.common.PanelGenerator; 35 import org.alfresco.web.ui.common.Utils; 36 import org.alfresco.web.ui.common.WebResources; 37 38 41 public class UIPanel extends UICommand 42 { 43 46 49 public UIPanel() 50 { 51 setRendererType(null); 52 } 53 54 57 public String getFamily() 58 { 59 return "org.alfresco.faces.Controls"; 60 } 61 62 67 public UIComponent getTitleComponent() 68 { 69 UIComponent titleComponent = null; 70 71 String facetsId = getFacetsId(); 73 if (facetsId != null) 74 { 75 UIForm parent = Utils.getParentForm(FacesContext.getCurrentInstance(), this); 76 UIComponent facetsComponent = parent.findComponent(facetsId); 77 if (facetsComponent != null) 78 { 79 titleComponent = facetsComponent.getFacet("title"); 81 } 82 } 83 84 return titleComponent; 85 } 86 87 90 public void encodeBegin(FacesContext context) throws IOException 91 { 92 if (isRendered() == false) 93 { 94 return; 95 } 96 97 ResponseWriter out = context.getResponseWriter(); 98 99 UIComponent titleComponent = getTitleComponent(); 101 102 String label = getLabel(); 104 if (label != null || isProgressive() == true || titleComponent != null) 105 { 106 this.hasAdornments = true; 107 } 108 109 String bgcolor = getBgcolor(); 111 if (bgcolor == null) 112 { 113 bgcolor = PanelGenerator.BGCOLOR_WHITE; 114 } 115 116 if ((getTitleBgcolor() != null) && (getTitleBorder() != null) && 119 (getBorder() != null) && this.hasAdornments) 120 { 121 this.hasBorderedTitleArea = true; 122 } 123 124 if (this.hasBorderedTitleArea) 126 { 127 PanelGenerator.generatePanelStart( 128 out, 129 context.getExternalContext().getRequestContextPath(), 130 getTitleBorder(), 131 getTitleBgcolor()); 132 } 133 else if (getBorder() != null) 134 { 135 PanelGenerator.generatePanelStart( 136 out, 137 context.getExternalContext().getRequestContextPath(), 138 getBorder(), 139 bgcolor); 140 } 141 142 if (this.hasAdornments) 143 { 144 out.write("<table border='0' cellspacing='0' cellpadding='0' width='100%'><tr><td>"); 146 } 147 148 if (isProgressive() == true) 151 { 152 out.write("<a HREF='#' onclick=\""); 153 String value = getClientId(context) + NamingContainer.SEPARATOR_CHAR + Boolean.toString(!isExpanded()); 154 out.write(Utils.generateFormSubmit(context, this, getHiddenFieldName(), value)); 155 out.write("\">"); 156 157 if (isExpanded() == true) 158 { 159 out.write(Utils.buildImageTag(context, WebResources.IMAGE_EXPANDED, 11, 11, "")); 160 } 161 else 162 { 163 out.write(Utils.buildImageTag(context, WebResources.IMAGE_COLLAPSED, 11, 11, "")); 164 } 165 166 out.write("</a> "); 167 } 168 169 if (label != null) 171 { 172 out.write("<span"); 173 Utils.outputAttribute(out, getAttributes().get("style"), "style"); 174 Utils.outputAttribute(out, getAttributes().get("styleClass"), "class"); 175 out.write('>'); 176 177 out.write(Utils.encode(label)); 178 179 out.write("</span>"); 180 } 181 182 if (this.hasAdornments) 183 { 184 out.write("</td>"); 185 } 186 187 if (titleComponent != null) 189 { 190 out.write("<td align='right'>"); 191 Utils.encodeRecursive(context, titleComponent); 192 out.write("</td>"); 193 } 194 195 if (this.hasAdornments) 196 { 197 out.write("</tr></table>"); 198 } 199 200 if (this.hasBorderedTitleArea && isExpanded()) 202 { 203 PanelGenerator.generateTitledPanelMiddle( 204 out, 205 context.getExternalContext().getRequestContextPath(), 206 getTitleBorder(), 207 getBorder(), 208 getBgcolor()); 209 } 210 } 211 212 215 public void encodeEnd(FacesContext context) throws IOException 216 { 217 if (isRendered() == false) 218 { 219 return; 220 } 221 222 ResponseWriter out = context.getResponseWriter(); 223 224 if (this.hasBorderedTitleArea && isExpanded() == false) 226 { 227 PanelGenerator.generatePanelEnd( 228 out, 229 context.getExternalContext().getRequestContextPath(), 230 getTitleBorder()); 231 } 232 else if (getBorder() != null) 233 { 234 PanelGenerator.generatePanelEnd( 235 out, 236 context.getExternalContext().getRequestContextPath(), 237 getBorder()); 238 } 239 } 240 241 244 public void decode(FacesContext context) 245 { 246 Map requestMap = context.getExternalContext().getRequestParameterMap(); 247 String fieldId = getHiddenFieldName(); 248 String value = (String )requestMap.get(fieldId); 249 250 if (value != null && value.startsWith(getClientId(context))) 252 { 253 value = value.substring(getClientId(context).length() + 1); 255 256 ExpandedEvent event = new ExpandedEvent(this, Boolean.parseBoolean(value)); 258 queueEvent(event); 259 260 } 273 } 274 275 278 public void broadcast(FacesEvent event) throws AbortProcessingException 279 { 280 if (event instanceof ExpandedEvent) 281 { 282 setExpanded( ((ExpandedEvent)event).State ); 284 285 if (getExpandedActionListener() != null) 286 { 287 Utils.processActionMethod(getFacesContext(), getExpandedActionListener(), (ExpandedEvent)event); 288 } 289 } 290 else 291 { 292 super.broadcast(event); 293 } 294 } 295 296 299 public void restoreState(FacesContext context, Object state) 300 { 301 Object values[] = (Object [])state; 302 super.restoreState(context, values[0]); 304 setExpanded( ((Boolean )values[1]).booleanValue() ); 305 this.progressive = (Boolean )values[2]; 306 this.border = (String )values[3]; 307 this.bgcolor = (String )values[4]; 308 this.label = (String )values[5]; 309 this.titleBgcolor = (String )values[6]; 310 this.titleBorder = (String )values[7]; 311 this.expandedActionListener = (MethodBinding)values[8]; 312 this.facetsId = (String )values[9]; 313 } 314 315 318 public Object saveState(FacesContext context) 319 { 320 Object values[] = new Object [10]; 321 values[0] = super.saveState(context); 323 values[1] = (isExpanded() ? Boolean.TRUE : Boolean.FALSE); 324 values[2] = this.progressive; 325 values[3] = this.border; 326 values[4] = this.bgcolor; 327 values[5] = this.label; 328 values[6] = this.titleBgcolor; 329 values[7] = this.titleBorder; 330 values[8] = this.expandedActionListener; 331 values[9] = this.facetsId; 332 return values; 333 } 334 335 336 339 342 public void setExpandedActionListener(MethodBinding binding) 343 { 344 this.expandedActionListener = binding; 345 } 346 347 350 public MethodBinding getExpandedActionListener() 351 { 352 return this.expandedActionListener; 353 } 354 355 358 public String getBgcolor() 359 { 360 ValueBinding vb = getValueBinding("bgcolor"); 361 if (vb != null) 362 { 363 this.bgcolor = (String )vb.getValue(getFacesContext()); 364 } 365 366 return this.bgcolor; 367 } 368 369 372 public void setBgcolor(String bgcolor) 373 { 374 this.bgcolor = bgcolor; 375 } 376 377 380 public String getBorder() 381 { 382 ValueBinding vb = getValueBinding("border"); 383 if (vb != null) 384 { 385 this.border = (String )vb.getValue(getFacesContext()); 386 } 387 388 return this.border; 389 } 390 391 394 public void setBorder(String border) 395 { 396 this.border = border; 397 } 398 399 402 public String getTitleBgcolor() 403 { 404 ValueBinding vb = getValueBinding("titleBgcolor"); 405 if (vb != null) 406 { 407 this.titleBgcolor = (String )vb.getValue(getFacesContext()); 408 } 409 410 return this.titleBgcolor; 411 } 412 413 416 public void setTitleBgcolor(String titleBgcolor) 417 { 418 this.titleBgcolor = titleBgcolor; 419 } 420 421 424 public String getTitleBorder() 425 { 426 ValueBinding vb = getValueBinding("titleBorder"); 427 if (vb != null) 428 { 429 this.titleBorder = (String )vb.getValue(getFacesContext()); 430 } 431 432 return this.titleBorder; 433 } 434 435 438 public void setTitleBorder(String titleBorder) 439 { 440 this.titleBorder = titleBorder; 441 } 442 443 446 public String getLabel() 447 { 448 ValueBinding vb = getValueBinding("label"); 449 if (vb != null) 450 { 451 this.label = (String )vb.getValue(getFacesContext()); 452 } 453 454 return this.label; 455 } 456 457 460 public void setLabel(String label) 461 { 462 this.label = label; 463 } 464 465 468 public boolean isProgressive() 469 { 470 ValueBinding vb = getValueBinding("progressive"); 471 if (vb != null) 472 { 473 this.progressive = (Boolean )vb.getValue(getFacesContext()); 474 } 475 476 if (this.progressive != null) 477 { 478 return this.progressive.booleanValue(); 479 } 480 else 481 { 482 return false; 484 } 485 } 486 487 490 public void setProgressive(boolean progressive) 491 { 492 this.progressive = Boolean.valueOf(progressive); 493 } 494 495 498 public boolean isExpanded() 499 { 500 ValueBinding vb = getValueBinding("expanded"); 501 if (vb != null) 502 { 503 this.expanded = (Boolean )vb.getValue(getFacesContext()); 504 } 505 506 if (this.expanded != null) 507 { 508 return this.expanded.booleanValue(); 509 } 510 else 511 { 512 return true; 514 } 515 } 516 517 522 public void setExpanded(boolean expanded) 523 { 524 this.expanded = Boolean.valueOf(expanded); 525 } 526 527 532 public String getFacetsId() 533 { 534 ValueBinding vb = getValueBinding("facets"); 535 if (vb != null) 536 { 537 this.facetsId = (String )vb.getValue(getFacesContext()); 538 } 539 540 return this.facetsId; 541 } 542 543 548 public void setFacetsId(String facets) 549 { 550 this.facetsId = facets; 551 } 552 553 554 557 564 private String getHiddenFieldName() 565 { 566 UIForm form = Utils.getParentForm(getFacesContext(), this); 567 return form.getClientId(getFacesContext()) + NamingContainer.SEPARATOR_CHAR + "panel"; 568 } 569 570 571 574 private String border = null; 576 private String bgcolor = null; 577 private String titleBorder = null; 578 private String titleBgcolor = null; 579 private Boolean progressive = null; 580 private String label = null; 581 private String facetsId = null; 582 private MethodBinding expandedActionListener = null; 583 584 private boolean hasAdornments = false; 586 private boolean hasBorderedTitleArea = false; 587 private Boolean expanded = Boolean.TRUE; 588 589 590 593 596 public static class ExpandedEvent extends ActionEvent 597 { 598 public ExpandedEvent(UIComponent component, boolean state) 599 { 600 super(component); 601 State = state; 602 } 603 604 public boolean State; 605 } 606 } 607 | Popular Tags |