1 33 34 package com.icesoft.faces.component.panelborder; 35 36 import com.icesoft.faces.component.CSS_DEFAULT; 37 import com.icesoft.faces.component.ext.taglib.Util; 38 39 import javax.faces.component.UIComponent; 40 import javax.faces.component.html.HtmlPanelGroup; 41 import javax.faces.context.FacesContext; 42 import javax.faces.el.ValueBinding; 43 import java.util.ArrayList ; 44 import java.util.List ; 45 46 59 public class PanelBorder 60 extends HtmlPanelGroup { 61 public static final String COMPONENT_TYPE = 62 "com.icesoft.faces.BorderLayout"; 63 public static final String COMPONENT_FAMILY = "javax.faces.Panel"; 64 public static final String DEFAULT_RENDERER_TYPE = 65 "com.icesoft.faces.BorderLayout"; 66 67 public static final String NORTH_LAYOUT = "north"; 68 public static final String WEST_LAYOUT = "west"; 69 public static final String CENTER_LAYOUT = "center"; 70 public static final String EAST_LAYOUT = "east"; 71 public static final String SOUTH_LAYOUT = "south"; 72 73 private String _layout = null; 74 private String styleClass = null; 75 private String style = null; 76 private String align = null; 77 private String border = null; 78 private String bgcolor = null; 79 private String cellpadding = null; 80 private String cellspacing = null; 81 private String frame = null; 82 private String rules = null; 83 private String summary = null; 84 private String height = null; 85 private String width = null; 86 private String dir = null; 87 private String lang = null; 88 private String title = null; 89 private String renderedOnUserRole = null; 90 91 List defaultLayout = new ArrayList (); 92 93 96 public UIComponent getNorth() { 97 return (UIComponent) getFacet(PanelBorder.NORTH_LAYOUT); 98 } 99 100 103 public UIComponent getWest() { 104 return (UIComponent) getFacet(PanelBorder.WEST_LAYOUT); 105 } 106 107 110 public UIComponent getEast() { 111 return (UIComponent) getFacet(PanelBorder.EAST_LAYOUT); 112 } 113 114 117 public UIComponent getCenter() { 118 return (UIComponent) getFacet(PanelBorder.CENTER_LAYOUT); 119 } 120 121 124 public UIComponent getSouth() { 125 return (UIComponent) getFacet(PanelBorder.SOUTH_LAYOUT); 126 } 127 128 131 public boolean isRendered() { 132 if (!Util.isRenderedOnUserRole(this)) { 133 return false; 134 } 135 return super.isRendered(); 136 } 137 138 public PanelBorder() { 139 setRendererType(DEFAULT_RENDERER_TYPE); 140 defaultLayout.add(PanelBorder.NORTH_LAYOUT); 141 defaultLayout.add(PanelBorder.EAST_LAYOUT); 142 defaultLayout.add(PanelBorder.SOUTH_LAYOUT); 143 defaultLayout.add(PanelBorder.WEST_LAYOUT); 144 defaultLayout.add(PanelBorder.CENTER_LAYOUT); 145 } 146 147 151 public String getFamily() { 152 return COMPONENT_FAMILY; 153 } 154 155 158 public void setLayout(String layout) { 159 _layout = layout; 160 } 161 162 166 public String getLayout() { 167 if (_layout != null) { 168 return _layout; 169 } 170 ValueBinding vb = getValueBinding("layout"); 171 return vb != null ? (String ) vb.getValue(getFacesContext()) : "none"; 172 } 173 174 177 public String getNorthClass() { 178 return Util.getQualifiedStyleClass(this, 179 CSS_DEFAULT.PANEL_BORDER_DEFAULT_NORTH_CLASS); 180 } 181 182 185 public String getWestClass() { 186 return Util.getQualifiedStyleClass(this, 187 CSS_DEFAULT.PANEL_BORDER_DEFAULT_WEST_CLASS); 188 } 189 190 193 public String getEastClass() { 194 return Util.getQualifiedStyleClass(this, 195 CSS_DEFAULT.PANEL_BORDER_DEFAULT_EAST_CLASS); 196 } 197 198 201 public String getCenterClass() { 202 return Util.getQualifiedStyleClass(this, 203 CSS_DEFAULT.PANEL_BORDER_DEFAULT_CENTER_CLASS); 204 } 205 206 207 210 public String getSouthClass() { 211 return Util.getQualifiedStyleClass(this, 212 CSS_DEFAULT.PANEL_BORDER_DEFAULT_SOUTH_CLASS); 213 } 214 215 218 public void setStyleClass(String styleClass) { 219 this.styleClass = styleClass; 220 } 221 222 225 public String getStyleClass() { 226 return Util.getQualifiedStyleClass(this, 227 styleClass, 228 CSS_DEFAULT.PANEL_BORDER_DEFAULT, 229 "styleClass"); 230 231 } 232 233 236 public String getStyle() { 237 if (style != null) { 238 return style; 239 } 240 ValueBinding vb = getValueBinding("style"); 241 return vb != null ? (String ) vb.getValue(getFacesContext()) : null; 242 } 243 244 247 public void setStyle(String style) { 248 this.style = style; 249 } 250 251 252 256 public Object saveState(FacesContext context) { 257 Object values[] = new Object [17]; 258 values[0] = super.saveState(context); 259 values[1] = _layout; 260 values[2] = styleClass; 261 values[3] = renderedOnUserRole; 262 values[4] = align; 263 values[5] = border; 264 values[6] = bgcolor; 265 values[7] = cellpadding; 266 values[8] = cellspacing; 267 values[9] = frame; 268 values[10] = rules; 269 values[11] = summary; 270 values[12] = height; 271 values[13] = width; 272 values[14] = dir; 273 values[15] = lang; 274 values[16] = title; 275 return ((Object ) (values)); 276 } 277 278 282 public void restoreState(FacesContext context, Object state) { 283 Object values[] = (Object []) state; 284 super.restoreState(context, values[0]); 285 _layout = (String ) values[1]; 286 styleClass = (String ) values[2]; 287 renderedOnUserRole = (String ) values[3]; 288 align = (String ) values[4]; 289 border = (String ) values[5]; 290 bgcolor = (String ) values[6]; 291 cellpadding = (String ) values[7]; 292 cellspacing = (String ) values[8]; 293 frame = (String ) values[9]; 294 rules = (String ) values[10]; 295 summary = (String ) values[11]; 296 height = (String ) values[12]; 297 width = (String ) values[13]; 298 dir = (String ) values[14]; 299 lang = (String ) values[15]; 300 title = (String ) values[16]; 301 } 302 303 306 public void setRenderedOnUserRole(String renderedOnUserRole) { 307 this.renderedOnUserRole = renderedOnUserRole; 308 } 309 310 313 public String getRenderedOnUserRole() { 314 if (renderedOnUserRole != null) { 315 return renderedOnUserRole; 316 } 317 ValueBinding vb = getValueBinding("renderedOnUserRole"); 318 return vb != null ? (String ) vb.getValue(getFacesContext()) : null; 319 } 320 321 322 public void setAlign(String align) { 323 this.align = align; 324 } 325 326 public void setBorder(String border) { 327 this.border = border; 328 } 329 330 public void setBgcolor(String bgcolor) { 331 this.bgcolor = bgcolor; 332 } 333 334 public void setCellpadding(String cellpadding) { 335 this.cellpadding = cellpadding; 336 } 337 338 public void setCellspacing(String cellspacing) { 339 this.cellspacing = cellspacing; 340 } 341 342 public void setFrame(String frame) { 343 this.frame = frame; 344 } 345 346 public void setHeight(String height) { 347 this.height = height; 348 } 349 350 public void setRules(String rules) { 351 this.rules = rules; 352 } 353 354 public void setSummary(String summary) { 355 this.summary = summary; 356 } 357 358 public void setWidth(String width) { 359 this.width = width; 360 } 361 362 public void setDir(String dir) { 363 this.dir = dir; 364 } 365 366 public void setLang(String lang) { 367 this.lang = lang; 368 } 369 370 public void setTitle(String title) { 371 this.title = title; 372 } 373 374 377 public String getAlign() { 378 if (align != null) { 379 return align; 380 } 381 ValueBinding vb = getValueBinding("align"); 382 return vb != null ? (String ) vb.getValue(getFacesContext()) : null; 383 } 384 385 388 public String getBorder() { 389 if (border != null) { 390 return border; 391 } 392 ValueBinding vb = getValueBinding("border"); 393 return vb != null ? (String ) vb.getValue(getFacesContext()) : null; 394 } 395 396 399 public String getBgcolor() { 400 if (bgcolor != null) { 401 return bgcolor; 402 } 403 ValueBinding vb = getValueBinding("bgcolor"); 404 return vb != null ? (String ) vb.getValue(getFacesContext()) : null; 405 } 406 407 410 public String getCellpadding() { 411 if (cellpadding != null) { 412 return cellpadding; 413 } 414 ValueBinding vb = getValueBinding("cellpadding"); 415 return vb != null ? (String ) vb.getValue(getFacesContext()) : null; 416 } 417 418 421 public String getCellspacing() { 422 if (cellspacing != null) { 423 return cellspacing; 424 } 425 ValueBinding vb = getValueBinding("cellspacing"); 426 return vb != null ? (String ) vb.getValue(getFacesContext()) : null; 427 } 428 429 432 public String getFrame() { 433 if (frame != null) { 434 return frame; 435 } 436 ValueBinding vb = getValueBinding("frame"); 437 return vb != null ? (String ) vb.getValue(getFacesContext()) : null; 438 } 439 440 443 public String getRules() { 444 if (rules != null) { 445 return rules; 446 } 447 ValueBinding vb = getValueBinding("rules"); 448 return vb != null ? (String ) vb.getValue(getFacesContext()) : null; 449 } 450 451 454 public String getSummary() { 455 if (summary != null) { 456 return summary; 457 } 458 ValueBinding vb = getValueBinding("summary"); 459 return vb != null ? (String ) vb.getValue(getFacesContext()) : null; 460 } 461 462 465 public String getHeight() { 466 if (height != null) { 467 return height; 468 } 469 ValueBinding vb = getValueBinding("height"); 470 return vb != null ? (String ) vb.getValue(getFacesContext()) : null; 471 } 472 473 476 public String getWidth() { 477 if (width != null) { 478 return width; 479 } 480 ValueBinding vb = getValueBinding("width"); 481 return vb != null ? (String ) vb.getValue(getFacesContext()) : null; 482 } 483 484 487 public String getDir() { 488 if (dir != null) { 489 return dir; 490 } 491 ValueBinding vb = getValueBinding("dir"); 492 return vb != null ? (String ) vb.getValue(getFacesContext()) : null; 493 } 494 495 498 public String getLang() { 499 if (lang != null) { 500 return lang; 501 } 502 ValueBinding vb = getValueBinding("lang"); 503 return vb != null ? (String ) vb.getValue(getFacesContext()) : null; 504 } 505 506 509 public String getTitle() { 510 if (title != null) { 511 return title; 512 } 513 ValueBinding vb = getValueBinding("title"); 514 return vb != null ? (String ) vb.getValue(getFacesContext()) : null; 515 } 516 517 518 private boolean renderCenter = true; 519 private boolean renderCenterSet = false; 520 521 public boolean isRenderCenter() { 522 if (getLayout().endsWith(PanelBorder.CENTER_LAYOUT)) { 523 return false; 524 } 525 if (getLayout().equalsIgnoreCase(PanelBorderRenderer.DEFAULT_LAYOUT)) { 526 return true; 527 } 528 if (this.renderCenterSet) { 529 return (this.renderCenter); 530 } 531 ValueBinding vb = getValueBinding("renderCenter"); 532 if (vb != null) { 533 return (Boolean.TRUE.equals(vb.getValue(getFacesContext()))); 534 } else { 535 return (this.renderCenter); 536 } 537 } 538 539 public void setRenderCenter(boolean renderCenter) { 540 if (renderCenter != this.renderCenter) { 541 this.renderCenter = renderCenter; 542 } 543 this.renderCenterSet = true; 544 } 545 546 547 private boolean renderEast = true; 548 private boolean renderEastSet = false; 549 550 public boolean isRenderEast() { 551 if (getLayout().endsWith(PanelBorder.EAST_LAYOUT) || 552 getLayout().equalsIgnoreCase(PanelBorderRenderer.CENTER_ONLY)) { 553 return false; 554 } 555 if (getLayout().equalsIgnoreCase(PanelBorderRenderer.DEFAULT_LAYOUT)) { 556 return true; 557 } 558 if (this.renderEastSet) { 559 return (this.renderEast); 560 } 561 ValueBinding vb = getValueBinding("renderEast"); 562 if (vb != null) { 563 return (Boolean.TRUE.equals(vb.getValue(getFacesContext()))); 564 } else { 565 return (this.renderEast); 566 } 567 } 568 569 public void setRenderEast(boolean renderEast) { 570 if (renderEast != this.renderEast) { 571 this.renderEast = renderEast; 572 } 573 this.renderEastSet = true; 574 } 575 576 private boolean renderNorth = true; 577 private boolean renderNorthSet = false; 578 579 public boolean isRenderNorth() { 580 if (getLayout().endsWith(PanelBorder.NORTH_LAYOUT) || 581 getLayout().equalsIgnoreCase(PanelBorderRenderer.CENTER_ONLY)) { 582 return false; 583 } 584 if (getLayout().equalsIgnoreCase(PanelBorderRenderer.DEFAULT_LAYOUT)) { 585 return true; 586 } 587 if (this.renderNorthSet) { 588 return (this.renderNorth); 589 } 590 ValueBinding vb = getValueBinding("renderNorth"); 591 if (vb != null) { 592 return (Boolean.TRUE.equals(vb.getValue(getFacesContext()))); 593 } else { 594 return (this.renderNorth); 595 } 596 } 597 598 public void setRenderNorth(boolean renderNorth) { 599 if (renderNorth != this.renderNorth) { 600 this.renderNorth = renderNorth; 601 } 602 this.renderNorthSet = true; 603 } 604 605 private boolean renderSouth = true; 606 private boolean renderSouthSet = false; 607 608 public boolean isRenderSouth() { 609 if (getLayout().endsWith(PanelBorder.SOUTH_LAYOUT) || 610 getLayout().equalsIgnoreCase(PanelBorderRenderer.CENTER_ONLY)) { 611 return false; 612 } 613 if (getLayout().equalsIgnoreCase(PanelBorderRenderer.DEFAULT_LAYOUT)) { 614 return true; 615 } 616 if (this.renderSouthSet) { 617 return (this.renderSouth); 618 } 619 ValueBinding vb = getValueBinding("renderSouth"); 620 if (vb != null) { 621 return (Boolean.TRUE.equals(vb.getValue(getFacesContext()))); 622 } else { 623 return (this.renderSouth); 624 } 625 } 626 627 public void setRenderSouth(boolean renderSouth) { 628 if (renderSouth != this.renderSouth) { 629 this.renderSouth = renderSouth; 630 } 631 this.renderSouthSet = true; 632 } 633 634 private boolean renderWest = true; 635 private boolean renderWestSet = false; 636 637 public boolean isRenderWest() { 638 if (getLayout().endsWith(PanelBorder.WEST_LAYOUT) || 639 getLayout().equalsIgnoreCase(PanelBorderRenderer.CENTER_ONLY)) { 640 return false; 641 } 642 if (getLayout().equalsIgnoreCase(PanelBorderRenderer.DEFAULT_LAYOUT)) { 643 return true; 644 } 645 if (this.renderWestSet) { 646 return (this.renderWest); 647 } 648 ValueBinding vb = getValueBinding("renderWest"); 649 if (vb != null) { 650 return (Boolean.TRUE.equals(vb.getValue(getFacesContext()))); 651 } else { 652 return (this.renderWest); 653 } 654 } 655 656 public void setRenderWest(boolean renderWest) { 657 if (renderWest != this.renderWest) { 658 this.renderWest = renderWest; 659 } 660 this.renderWestSet = true; 661 } 662 663 public List getLayoutAsList() { 664 665 if (isRenderCenter()) { 666 if (!defaultLayout.contains(PanelBorder.CENTER_LAYOUT)) { 667 defaultLayout.add(PanelBorder.CENTER_LAYOUT); 668 } 669 } else { 670 defaultLayout.remove(PanelBorder.CENTER_LAYOUT); 671 } 672 if (isRenderEast()) { 673 if (!defaultLayout.contains(PanelBorder.EAST_LAYOUT)) { 674 defaultLayout.add(PanelBorder.EAST_LAYOUT); 675 } 676 } else { 677 defaultLayout.remove(PanelBorder.EAST_LAYOUT); 678 } 679 if (isRenderNorth()) { 680 if (!defaultLayout.contains(PanelBorder.NORTH_LAYOUT)) { 681 defaultLayout.add(PanelBorder.NORTH_LAYOUT); 682 } 683 } else { 684 defaultLayout.remove(PanelBorder.NORTH_LAYOUT); 685 } 686 if (isRenderSouth()) { 687 if (!defaultLayout.contains(PanelBorder.SOUTH_LAYOUT)) { 688 defaultLayout.add(PanelBorder.SOUTH_LAYOUT); 689 } 690 } else { 691 defaultLayout.remove(PanelBorder.SOUTH_LAYOUT); 692 } 693 if (isRenderWest()) { 694 if (!defaultLayout.contains(PanelBorder.WEST_LAYOUT)) { 695 defaultLayout.add(PanelBorder.WEST_LAYOUT); 696 } 697 } else { 698 defaultLayout.remove(PanelBorder.WEST_LAYOUT); 699 } 700 701 return defaultLayout; 702 } 703 704 705 } 706 | Popular Tags |