1 33 48 package com.icesoft.faces.component.paneltabset; 49 50 import com.icesoft.faces.component.CSS_DEFAULT; 51 import com.icesoft.faces.component.ext.taglib.Util; 52 import com.icesoft.faces.component.panelseries.UISeries; 53 54 import javax.faces.component.UIComponent; 55 import javax.faces.component.UIForm; 56 import javax.faces.component.UINamingContainer; 57 import javax.faces.context.FacesContext; 58 import javax.faces.el.EvaluationException; 59 import javax.faces.el.MethodBinding; 60 import javax.faces.el.ValueBinding; 61 import javax.faces.event.AbortProcessingException; 62 import javax.faces.event.FacesEvent; 63 import javax.faces.event.FacesListener; 64 import javax.faces.event.PhaseId; 65 66 import java.util.ArrayList ; 67 import java.util.Iterator ; 68 import java.util.List ; 69 70 80 public class PanelTabSet 81 extends UISeries { 82 83 84 87 private MethodBinding _tabChangeListener = null; 88 89 92 public void decode(FacesContext context) { 93 reconcileListeners(); 94 super.decode(context); 95 } 96 97 101 public void applyPhase(FacesContext context, PhaseId phaseId) { 102 if (context == null) { 103 throw new NullPointerException ("Null context in PanelTabSet"); 104 } 105 108 int tabIdx = 0; 109 int selectedIndex = getSelectedIndex(); 110 111 if (super.getValue() != null) { 112 int rowIndex = super.getFirst(); 113 setRowIndex(rowIndex); 114 int rowsToBeDisplayed = getRows(); 115 int rowsDisplayed = 0; 116 UIComponent child = 117 getUIComponent((UIComponent) getChildren().get(0)); 118 while (isRowAvailable()) { 119 if (rowsToBeDisplayed > 0 && 120 rowsDisplayed >= rowsToBeDisplayed) { 121 break; 122 } 123 124 if (child instanceof PanelTab) { 125 if (tabIdx == selectedIndex) { 126 applyPhase(context, child, phaseId); 127 } 128 tabIdx++; 129 } 130 rowsDisplayed++; 131 rowIndex++; 132 setRowIndex(rowIndex); 133 } 134 setRowIndex(-1); 135 } else { 136 137 Iterator it = getFacetsAndChildren(); 138 139 while (it.hasNext()) { 140 UIComponent childOrFacet = 141 getUIComponent((UIComponent) it.next()); 142 if (childOrFacet instanceof PanelTab) { 143 if (tabIdx == selectedIndex) { 144 applyPhase(context, childOrFacet, phaseId); 145 } 146 tabIdx++; 147 } else { 148 applyPhase(context, childOrFacet, phaseId); 149 } 150 } 151 } 152 153 } 154 155 160 public void applyPhase(FacesContext context, UIComponent component, 161 PhaseId phaseId) { 162 if (phaseId == PhaseId.APPLY_REQUEST_VALUES) { 163 component.processDecodes(context); 164 } else if (phaseId == PhaseId.PROCESS_VALIDATIONS) { 165 component.processValidators(context); 166 } else if (phaseId == PhaseId.UPDATE_MODEL_VALUES) { 167 component.processUpdates(context); 168 } else { 169 throw new IllegalArgumentException (); 170 } 171 } 172 173 176 public void processDecodes(javax.faces.context.FacesContext context) { 177 if (context == null) { 178 throw new NullPointerException ("context"); 179 } 180 181 if (!isRendered()) { 182 return; 183 } 184 185 decode(context); 186 applyPhase(context, PhaseId.APPLY_REQUEST_VALUES); 187 } 188 189 192 public void processValidators(FacesContext context) { 193 194 if (context == null) { 195 throw new NullPointerException (); 196 } 197 if (!isRendered()) { 198 return; 199 } 200 applyPhase(context, PhaseId.PROCESS_VALIDATIONS); 201 } 202 203 204 207 public void processUpdates(FacesContext context) { 208 209 if (context == null) { 210 throw new NullPointerException (); 211 } 212 if (!isRendered()) { 213 return; 214 } 215 applyPhase(context, PhaseId.UPDATE_MODEL_VALUES); 216 } 217 218 private UIComponent getUIComponent(UIComponent uiComponent) { 219 if (uiComponent instanceof UINamingContainer || 220 uiComponent instanceof UIForm) { 221 List children = uiComponent.getChildren(); 222 for (int i = 0, len = children.size(); i < len; i++) { 223 uiComponent = getUIComponent((UIComponent) children.get(i)); 224 } 225 } 226 return uiComponent; 227 } 228 229 232 private List listenerList = new ArrayList (); 233 public void addTabChangeListener(TabChangeListener listener) { 234 listenerList.add(listener); 235 addFacesListener(listener); 236 } 237 238 241 public void removeTabChangeListener(TabChangeListener listener) { 242 listenerList.remove(listener); 243 removeFacesListener(listener); 244 } 245 246 249 private void reconcileListeners(){ 250 FacesListener[] listener = getFacesListeners(TabChangeListener.class); 251 for (int i=0; i< listener.length; i++) { 252 super.removeFacesListener(listener[i]); 253 } 254 Iterator it = listenerList.iterator(); 255 while(it.hasNext()) { 256 super.addFacesListener((TabChangeListener)it.next()); 257 } 258 } 259 260 263 public MethodBinding getTabChangeListener() { 264 return _tabChangeListener; 265 } 266 267 270 public void setTabChangeListener(MethodBinding tabChangeListener) { 271 _tabChangeListener = tabChangeListener; 272 } 273 274 277 public void broadcast(FacesEvent event) throws AbortProcessingException { 278 if (event instanceof TabChangeEvent) { 279 TabChangeEvent tabChangeEvent = (TabChangeEvent) event; 280 if (tabChangeEvent.getComponent() == this) { 281 setSelectedIndex(tabChangeEvent.getNewTabIndex()); 282 } 284 } 285 286 super.broadcast(event); 287 288 if (event instanceof TabChangeEvent) { 289 TabChangeEvent tabChangeEvent = (TabChangeEvent) event; 290 MethodBinding tabChangeListenerBinding = getTabChangeListener(); 291 if (tabChangeListenerBinding != null) { 292 try { 293 tabChangeListenerBinding.invoke( 294 getFacesContext(), new Object []{tabChangeEvent}); 295 } 296 catch (EvaluationException e) { 297 Throwable cause = e.getCause(); 298 if (cause != null && 299 cause instanceof AbortProcessingException) { 300 throw(AbortProcessingException) cause; 301 } else { 302 throw e; 303 } 304 } 305 } 306 } 307 } 308 309 312 public boolean isRendered() { 313 if (!Util.isRenderedOnUserRole(this)) { 314 return false; 315 } 316 return super.isRendered(); 317 } 318 319 322 public static final String COMPONENT_TYPE = "com.icesoft.faces.PanelTabSet"; 323 326 public static final String COMPONENT_FAMILY = "javax.faces.Panel"; 327 330 private static final String DEFAULT_RENDERER_TYPE = 331 "com.icesoft.faces.TabbedPane"; 332 335 private static final int DEFAULT_SELECTEDINDEX = 0; 336 339 private final String DEFAULT_TABPLACEMENT = 340 "Top"; 342 final static String TABPLACEMENT_BOTTOM = 343 "bottom"; 346 349 private static final String DEFAULT_BG_COLOR = "#FFFFFF"; 350 353 private Integer _selectedIndex = null; 354 358 private String _tabPlacement = null; 359 362 private String _bgcolor = null; 363 366 private String _style = null; 367 370 private String _styleClass = null; 371 372 376 public PanelTabSet() { 377 setRendererType(DEFAULT_RENDERER_TYPE); 378 } 379 380 383 public String getFamily() { 384 return COMPONENT_FAMILY; 385 } 386 387 390 void setSelectedIndex(Integer selectedIndex) { 391 _selectedIndex = selectedIndex; 392 } 393 394 397 public void setSelectedIndex(int selectedIndex) { 398 _selectedIndex = new Integer (selectedIndex); 399 } 400 401 404 public int getSelectedIndex() { 405 if (_selectedIndex != null) { 406 return _selectedIndex.intValue(); 407 } 408 ValueBinding vb = getValueBinding("selectedIndex"); 409 Number v = vb != null ? (Number ) vb.getValue(getFacesContext()) : null; 410 return v != null ? v.intValue() : DEFAULT_SELECTEDINDEX; 411 } 412 413 416 public void setBgcolor(String bgcolor) { 417 _bgcolor = bgcolor; 418 } 419 420 423 public String getBgcolor() { 424 if (_bgcolor != null) { 425 return _bgcolor; 426 } 427 ValueBinding vb = getValueBinding("bgcolor"); 428 return vb != null ? (String ) vb.getValue(getFacesContext()) : 429 DEFAULT_BG_COLOR; 430 } 431 432 private int border = 0; 433 private boolean border_set = false; 434 435 441 public int getBorder() { 442 if (this.border_set) { 443 return this.border; 444 } 445 ValueBinding _vb = getValueBinding("border"); 446 if (_vb != null) { 447 Object _result = _vb.getValue(getFacesContext()); 448 if (_result == null) { 449 return 0; 450 } else { 451 return ((Integer ) _result).intValue(); 452 } 453 } else { 454 return this.border; 455 } 456 } 457 458 463 public void setBorder(int border) { 464 this.border = border; 465 this.border_set = true; 466 } 467 468 471 public void setStyle(String style) { 472 _style = style; 473 } 474 475 478 public String getStyle() { 479 if (_style != null) { 480 return _style; 481 } 482 ValueBinding vb = getValueBinding("style"); 483 return vb != null ? (String ) vb.getValue(getFacesContext()) : null; 484 } 485 486 489 public void setStyleClass(String styleClass) { 490 _styleClass = styleClass; 491 } 492 493 496 public String getStyleClass() { 497 return Util.getQualifiedStyleClass(this, 498 _styleClass, 499 CSS_DEFAULT.PANEL_TAB_SET_DEFAULT_TAB_SET, 500 "styleClass"); 501 } 502 503 506 public void setTabPlacement(String tabPlacement) { 507 _tabPlacement = tabPlacement; 508 } 509 510 514 public String getTabPlacement() { 515 if (_tabPlacement != null) { 516 return _tabPlacement; 517 } 518 ValueBinding vb = getValueBinding("tabPlacement"); 519 return vb != null ? (String ) vb.getValue(getFacesContext()) : 520 this.DEFAULT_TABPLACEMENT; 521 } 522 523 526 public Object saveState(FacesContext context) { 527 Object values[] = new Object [29]; 528 values[0] = super.saveState(context); 529 values[1] = _selectedIndex; 530 values[2] = _bgcolor; 531 values[3] = saveAttachedState(context, _tabChangeListener); 532 values[4] = _style; 533 values[5] = _styleClass; 534 values[6] = _tabPlacement; 535 values[7] = onclick; 536 values[8] = ondblclick; 537 values[9] = onmousedown; 538 values[10] = onmouseup; 539 values[11] = onmouseover; 540 values[12] = onmousemove; 541 values[13] = onmouseout; 542 values[14] = onkeypress; 543 values[15] = onkeydown; 544 values[16] = onkeyup; 545 values[17] = align; 546 values[18] = new Integer (border); 547 values[19] = cellpadding; 548 values[20] = cellspacing; 549 values[21] = frame; 550 values[22] = rules; 551 values[23] = summary; 552 values[24] = height; 553 values[25] = width; 554 values[26] = dir; 555 values[27] = lang; 556 values[28] = title; 557 return ((Object ) (values)); 558 } 559 560 563 public void restoreState(FacesContext context, Object state) { 564 Object values[] = (Object []) state; 565 super.restoreState(context, values[0]); 566 _selectedIndex = (Integer ) values[1]; 567 _bgcolor = (String ) values[2]; 568 _tabChangeListener = 569 (MethodBinding) restoreAttachedState(context, values[3]); 570 _style = (String ) values[4]; 571 _styleClass = (String ) values[5]; 572 _tabPlacement = (String ) values[6]; 573 onclick = (String ) values[7]; 574 ondblclick = (String ) values[8]; 575 onmousedown = (String ) values[9]; 576 onmouseup = (String ) values[10]; 577 onmouseover = (String ) values[11]; 578 onmousemove = (String ) values[12]; 579 onmouseout = (String ) values[13]; 580 onkeypress = (String ) values[14]; 581 onkeydown = (String ) values[15]; 582 onkeyup = (String ) values[16]; 583 align = (String ) values[17]; 584 border = ((Integer ) values[18]).intValue(); 585 cellpadding = (String ) values[19]; 586 cellspacing = (String ) values[20]; 587 frame = (String ) values[21]; 588 rules = (String ) values[22]; 589 summary = (String ) values[23]; 590 height = (String ) values[24]; 591 width = (String ) values[25]; 592 dir = (String ) values[26]; 593 lang = (String ) values[27]; 594 title = (String ) values[28]; 595 } 596 597 private String onclick; 598 private String ondblclick; 599 private String onmousedown = null; 600 private String onmouseup = null; 601 private String onmouseover = null; 602 private String onmousemove = null; 603 private String onmouseout = null; 604 private String onkeypress = null; 605 private String onkeydown = null; 606 private String onkeyup = null; 607 private String align = null; 608 private String cellpadding = null; 609 private String cellspacing = null; 610 private String frame = null; 611 private String rules = null; 612 private String summary = null; 613 private String height = null; 614 private String width = null; 615 private String dir = null; 616 private String lang = null; 617 private String title = null; 618 619 622 public void setAlign(String align) { 623 this.align = align; 624 } 625 626 629 public void setCellpadding(String cellpadding) { 630 this.cellpadding = cellpadding; 631 } 632 633 636 public void setCellspacing(String cellspacing) { 637 this.cellspacing = cellspacing; 638 } 639 640 643 public void setFrame(String frame) { 644 this.frame = frame; 645 } 646 647 650 public void setHeight(String height) { 651 this.height = height; 652 } 653 654 657 public void setOnclick(String onclick) { 658 this.onclick = onclick; 659 } 660 661 664 public void setOndblclick(String ondblclick) { 665 this.ondblclick = ondblclick; 666 } 667 668 671 public void setOnkeydown(String onkeydown) { 672 this.onkeydown = onkeydown; 673 } 674 675 678 public void setOnkeypress(String onkeypress) { 679 this.onkeypress = onkeypress; 680 } 681 682 685 public void setOnkeyup(String onkeyup) { 686 this.onkeyup = onkeyup; 687 } 688 689 692 public void setOnmousedown(String onmousedown) { 693 this.onmousedown = onmousedown; 694 } 695 696 699 public void setOnmousemove(String onmousemove) { 700 this.onmousemove = onmousemove; 701 } 702 703 706 public void setOnmouseout(String onmouseout) { 707 this.onmouseout = onmouseout; 708 } 709 710 713 public void setOnmouseover(String onmouseover) { 714 this.onmouseover = onmouseover; 715 } 716 717 720 public void setOnmouseup(String onmouseup) { 721 this.onmouseup = onmouseup; 722 } 723 724 727 public void setRules(String rules) { 728 this.rules = rules; 729 } 730 731 734 public void setSummary(String summary) { 735 this.summary = summary; 736 } 737 738 741 public void setWidth(String width) { 742 this.width = width; 743 } 744 745 748 public void setDir(String dir) { 749 this.dir = dir; 750 } 751 752 755 public void setLang(String lang) { 756 this.lang = lang; 757 } 758 759 762 public void setTitle(String title) { 763 this.title = title; 764 } 765 766 769 public String getOnclick() { 770 if (onclick != null) { 771 return onclick; 772 } 773 ValueBinding vb = getValueBinding("onclick"); 774 return vb != null ? (String ) vb.getValue(getFacesContext()) : null; 775 } 776 777 780 public String getOndblclick() { 781 if (ondblclick != null) { 782 return ondblclick; 783 } 784 ValueBinding vb = getValueBinding("ondblclick"); 785 return vb != null ? (String ) vb.getValue(getFacesContext()) : null; 786 } 787 788 791 public String getOnmousedown() { 792 if (onmousedown != null) { 793 return onmousedown; 794 } 795 ValueBinding vb = getValueBinding("onmousedown"); 796 return vb != null ? (String ) vb.getValue(getFacesContext()) : null; 797 } 798 799 802 public String getOnmouseup() { 803 if (onmouseup != null) { 804 return onmouseup; 805 } 806 ValueBinding vb = getValueBinding("onmouseup"); 807 return vb != null ? (String ) vb.getValue(getFacesContext()) : null; 808 } 809 810 813 public String getOnmouseover() { 814 if (onmouseover != null) { 815 return onmouseover; 816 } 817 ValueBinding vb = getValueBinding("onmouseover"); 818 return vb != null ? (String ) vb.getValue(getFacesContext()) : null; 819 } 820 821 824 public String getOnmousemove() { 825 if (onmousemove != null) { 826 return onmousemove; 827 } 828 ValueBinding vb = getValueBinding("onmousemove"); 829 return vb != null ? (String ) vb.getValue(getFacesContext()) : null; 830 } 831 832 835 public String getOnmouseout() { 836 if (onmouseout != null) { 837 return onmouseout; 838 } 839 ValueBinding vb = getValueBinding("onmouseout"); 840 return vb != null ? (String ) vb.getValue(getFacesContext()) : null; 841 } 842 843 846 public String getOnkeypress() { 847 if (onkeypress != null) { 848 return onkeypress; 849 } 850 ValueBinding vb = getValueBinding("onkeypress"); 851 return vb != null ? (String ) vb.getValue(getFacesContext()) : null; 852 } 853 854 857 public String getOnkeydown() { 858 if (onkeydown != null) { 859 return onkeydown; 860 } 861 ValueBinding vb = getValueBinding("onkeydown"); 862 return vb != null ? (String ) vb.getValue(getFacesContext()) : null; 863 } 864 865 868 public String getOnkeyup() { 869 if (onkeyup != null) { 870 return onkeyup; 871 } 872 ValueBinding vb = getValueBinding("onkeyup"); 873 return vb != null ? (String ) vb.getValue(getFacesContext()) : null; 874 } 875 876 879 public String getAlign() { 880 if (align != null) { 881 return align; 882 } 883 ValueBinding vb = getValueBinding("align"); 884 return vb != null ? (String ) vb.getValue(getFacesContext()) : null; 885 } 886 887 888 891 public String getCellpadding() { 892 if (cellpadding != null) { 893 return cellpadding; 894 } 895 ValueBinding vb = getValueBinding("cellpadding"); 896 return vb != null ? (String ) vb.getValue(getFacesContext()) : null; 897 } 898 899 902 public String getCellspacing() { 903 if (cellspacing != null) { 904 return cellspacing; 905 } 906 ValueBinding vb = getValueBinding("cellspacing"); 907 return vb != null ? (String ) vb.getValue(getFacesContext()) : null; 908 } 909 910 913 public String getFrame() { 914 if (frame != null) { 915 return frame; 916 } 917 ValueBinding vb = getValueBinding("frame"); 918 return vb != null ? (String ) vb.getValue(getFacesContext()) : null; 919 } 920 921 924 public String getRules() { 925 if (rules != null) { 926 return rules; 927 } 928 ValueBinding vb = getValueBinding("rules"); 929 return vb != null ? (String ) vb.getValue(getFacesContext()) : null; 930 } 931 932 935 public String getSummary() { 936 if (summary != null) { 937 return summary; 938 } 939 ValueBinding vb = getValueBinding("summary"); 940 return vb != null ? (String ) vb.getValue(getFacesContext()) : null; 941 } 942 943 946 public String getHeight() { 947 if (height != null) { 948 return height; 949 } 950 ValueBinding vb = getValueBinding("height"); 951 return vb != null ? (String ) vb.getValue(getFacesContext()) : null; 952 } 953 954 957 public String getWidth() { 958 if (width != null) { 959 return width; 960 } 961 ValueBinding vb = getValueBinding("width"); 962 return vb != null ? (String ) vb.getValue(getFacesContext()) : null; 963 } 964 965 968 public String getDir() { 969 if (dir != null) { 970 return dir; 971 } 972 ValueBinding vb = getValueBinding("dir"); 973 return vb != null ? (String ) vb.getValue(getFacesContext()) : null; 974 } 975 976 979 public String getLang() { 980 if (lang != null) { 981 return lang; 982 } 983 ValueBinding vb = getValueBinding("lang"); 984 return vb != null ? (String ) vb.getValue(getFacesContext()) : null; 985 } 986 987 990 public String getTitle() { 991 if (title != null) { 992 return title; 993 } 994 ValueBinding vb = getValueBinding("title"); 995 return vb != null ? (String ) vb.getValue(getFacesContext()) : null; 996 } 997 998 private String renderedOnUserRole = null; 999 1000 1005 public void setRenderedOnUserRole(String renderedOnUserRole) { 1006 this.renderedOnUserRole = renderedOnUserRole; 1007 } 1008 1009 1014 public String getRenderedOnUserRole() { 1015 if (renderedOnUserRole != null) { 1016 return renderedOnUserRole; 1017 } 1018 ValueBinding vb = getValueBinding("renderedOnUserRole"); 1019 return vb != null ? (String ) vb.getValue(getFacesContext()) : null; 1020 } 1021 1022 private static final boolean DEFAULT_VISIBLE = true; 1023 private Boolean visible = null; 1024 1025 1030 public void setVisible(boolean visible) { 1031 this.visible = Boolean.valueOf(visible); 1032 } 1033 1034 1039 public boolean isVisible() { 1040 if (visible != null) { 1041 return visible.booleanValue(); 1042 } 1043 ValueBinding vb = getValueBinding("visible"); 1044 Boolean boolVal = 1045 vb != null ? (Boolean ) vb.getValue(getFacesContext()) : null; 1046 return boolVal != null ? boolVal.booleanValue() : DEFAULT_VISIBLE; 1047 } 1048 1049 1050 String getContentClass() { 1051 String contentClass = CSS_DEFAULT.PANEL_TAB_CONTENTS_CLASS; 1052 if (getTabPlacement().equalsIgnoreCase(TABPLACEMENT_BOTTOM)) { 1053 contentClass +=CSS_DEFAULT.PANEL_TAB_SET_DEFAULT_BOTTOM; 1054 } 1055 return Util.getQualifiedStyleClass(this, 1056 contentClass); 1057 } 1058 1059 String getSpacerClass() { 1060 String spacerClass = CSS_DEFAULT.PANEL_TAB_SET_DEFAULT_TABSPACER; 1061 if (getTabPlacement().equalsIgnoreCase(TABPLACEMENT_BOTTOM)) { 1062 spacerClass +=CSS_DEFAULT.PANEL_TAB_SET_DEFAULT_BOTTOM; 1063 } 1064 return Util.getQualifiedStyleClass(this, 1065 spacerClass); 1066 } 1067} 1068 | Popular Tags |