1 33 48 49 package com.icesoft.faces.component.paneltabset; 50 51 import com.icesoft.faces.component.CSS_DEFAULT; 52 import com.icesoft.faces.component.ext.taglib.Util; 53 import com.icesoft.faces.context.DOMContext; 54 import com.icesoft.faces.renderkit.dom_html_basic.HTML; 55 import org.w3c.dom.Element ; 56 import org.w3c.dom.Node ; 57 58 import javax.faces.component.html.HtmlPanelGroup; 59 import javax.faces.context.FacesContext; 60 import javax.faces.el.ValueBinding; 61 62 67 public class PanelTab 68 extends HtmlPanelGroup { 69 72 public static final String COMPONENT_TYPE = "com.icesoft.faces.PanelTab"; 73 76 public static final String COMPONENT_FAMILY = "javax.faces.Panel"; 77 80 private static final String DEFAULT_RENDERER_TYPE = "javax.faces.Group"; 81 84 private String enabledOnUserRole = null; 85 88 private String renderedOnUserRole = null; 89 92 private String style = null; 93 96 private String styleClass = null; 97 100 private String label = null; 101 104 private Boolean disabled = null; 105 108 private String icon = null; 109 112 private Boolean iconAlignRight = Boolean.FALSE; 113 114 115 118 public void setStyle(String style) { 119 this.style = style; 120 } 121 122 125 public String getStyle() { 126 if (style != null) { 127 return style; 128 } 129 ValueBinding vb = getValueBinding("style"); 130 return vb != null ? (String ) vb.getValue(getFacesContext()) : null; 131 } 132 133 136 public void setStyleClass(String styleClass) { 137 this.styleClass = styleClass; 138 } 139 140 143 public String getStyleClass() { 144 return Util.getQualifiedStyleClass(this, 145 styleClass, 146 CSS_DEFAULT.PANEL_TAB_DEFAULT_STYLECLASS, 147 "styleClass"); 148 } 149 150 153 public void setEnabledOnUserRole(String enabledOnUserRole) { 154 this.enabledOnUserRole = enabledOnUserRole; 155 } 156 157 160 public String getEnabledOnUserRole() { 161 if (enabledOnUserRole != null) { 162 return enabledOnUserRole; 163 } 164 ValueBinding vb = getValueBinding("enabledOnUserRole"); 165 return vb != null ? (String ) vb.getValue(getFacesContext()) : null; 166 } 167 168 171 public void setRenderedOnUserRole(String renderedOnUserRole) { 172 this.renderedOnUserRole = renderedOnUserRole; 173 } 174 175 178 public String getRenderedOnUserRole() { 179 if (renderedOnUserRole != null) { 180 return renderedOnUserRole; 181 } 182 ValueBinding vb = getValueBinding("renderedOnUserRole"); 183 return vb != null ? (String ) vb.getValue(getFacesContext()) : null; 184 } 185 186 190 public PanelTab() { 191 setRendererType(DEFAULT_RENDERER_TYPE); 192 } 193 194 197 public String getFamily() { 198 return COMPONENT_FAMILY; 199 } 200 201 204 public void setLabel(String label) { 205 this.label = label; 206 } 207 208 211 public String getLabel() { 212 if (label != null) { 213 return label; 214 } 215 ValueBinding vb = getValueBinding("label"); 216 return vb != null ? (String ) vb.getValue(getFacesContext()) : null; 217 } 218 219 222 public void setDisabled(boolean disabled) { 223 this.disabled = new Boolean (disabled); 224 ValueBinding vb = getValueBinding("disabled"); 225 if (vb != null) { 226 vb.setValue(getFacesContext(), this.disabled); 227 this.disabled = null; 228 } 229 } 230 231 234 public boolean isDisabled() { 235 if (!Util.isEnabledOnUserRole(this)) { 236 return true; 237 } 238 239 if (disabled != null) { 240 return disabled.booleanValue(); 241 } 242 ValueBinding vb = getValueBinding("disabled"); 243 Boolean v = 244 vb != null ? (Boolean ) vb.getValue(getFacesContext()) : null; 245 return v != null ? v.booleanValue() : false; 246 } 247 248 251 public Object saveState(FacesContext context) { 252 Object values[] = new Object [20]; 253 values[0] = super.saveState(context); 254 values[1] = label; 255 values[2] = disabled; 256 values[3] = enabledOnUserRole; 257 values[4] = renderedOnUserRole; 258 values[5] = style; 259 values[6] = styleClass; 260 values[7] = dir; 261 values[8] = lang; 262 values[9] = title; 263 values[10] = onclick; 264 values[11] = ondblclick; 265 values[12] = onmousedown; 266 values[13] = onmouseup; 267 values[14] = onmouseover; 268 values[15] = onmousemove; 269 values[16] = onmouseout; 270 values[17] = onkeypress; 271 values[18] = onkeydown; 272 values[19] = onkeyup; 273 return ((Object ) (values)); 274 } 275 276 279 public void restoreState(FacesContext context, Object state) { 280 Object values[] = (Object []) state; 281 super.restoreState(context, values[0]); 282 label = (String ) values[1]; 283 disabled = (Boolean ) values[2]; 284 enabledOnUserRole = (String ) values[3]; 285 renderedOnUserRole = (String ) values[4]; 286 style = (String ) values[5]; 287 styleClass = (String ) values[6]; 288 dir = (String ) values[7]; 289 lang = (String ) values[8]; 290 title = (String ) values[9]; 291 onclick = (String ) values[10]; 292 ondblclick = (String ) values[11]; 293 onmousedown = (String ) values[12]; 294 onmouseup = (String ) values[13]; 295 onmouseover = (String ) values[14]; 296 onmousemove = (String ) values[15]; 297 onmouseout = (String ) values[16]; 298 onkeypress = (String ) values[17]; 299 onkeydown = (String ) values[18]; 300 onkeyup = (String ) values[19]; 301 } 302 303 306 public boolean isRendered() { 307 if (!Util.isRenderedOnUserRole(this)) { 308 return false; 309 } 310 return super.isRendered(); 311 } 312 313 private String dir = null; 314 private String lang = null; 315 private String title = null; 316 private String onclick = null; 317 private String ondblclick = null; 318 private String onmousedown = null; 319 private String onmouseup = null; 320 private String onmouseover = null; 321 private String onmousemove = null; 322 private String onmouseout = null; 323 private String onkeypress = null; 324 private String onkeydown = null; 325 private String onkeyup = null; 326 327 328 331 public void setDir(String dir) { 332 this.dir = dir; 333 } 334 335 338 public void setLang(String lang) { 339 this.lang = lang; 340 } 341 342 345 public void setTitle(String title) { 346 this.title = title; 347 } 348 349 352 public void setOnclick(String onclick) { 353 this.onclick = onclick; 354 } 355 356 359 public void setOndblclick(String ondblclick) { 360 this.ondblclick = ondblclick; 361 } 362 363 366 public void setOnkeydown(String onkeydown) { 367 this.onkeydown = onkeydown; 368 } 369 370 373 public void setOnkeypress(String onkeypress) { 374 this.onkeypress = onkeypress; 375 } 376 377 380 public void setOnkeyup(String onkeyup) { 381 this.onkeyup = onkeyup; 382 } 383 384 387 public void setOnmousedown(String onmousedown) { 388 this.onmousedown = onmousedown; 389 } 390 391 394 public void setOnmousemove(String onmousemove) { 395 this.onmousemove = onmousemove; 396 } 397 398 401 public void setOnmouseout(String onmouseout) { 402 this.onmouseout = onmouseout; 403 } 404 405 408 public void setOnmouseover(String onmouseover) { 409 this.onmouseover = onmouseover; 410 } 411 412 415 public void setOnmouseup(String onmouseup) { 416 this.onmouseup = onmouseup; 417 } 418 419 422 public String getDir() { 423 if (dir != null) { 424 return dir; 425 } 426 ValueBinding vb = getValueBinding("dir"); 427 return vb != null ? (String ) vb.getValue(getFacesContext()) : null; 428 } 429 430 433 public String getLang() { 434 if (lang != null) { 435 return lang; 436 } 437 ValueBinding vb = getValueBinding("lang"); 438 return vb != null ? (String ) vb.getValue(getFacesContext()) : null; 439 } 440 441 444 public String getTitle() { 445 if (title != null) { 446 return title; 447 } 448 ValueBinding vb = getValueBinding("title"); 449 return vb != null ? (String ) vb.getValue(getFacesContext()) : null; 450 } 451 452 455 public String getOnclick() { 456 if (onclick != null) { 457 return onclick; 458 } 459 ValueBinding vb = getValueBinding("onclick"); 460 return vb != null ? (String ) vb.getValue(getFacesContext()) : null; 461 } 462 463 466 public String getOndblclick() { 467 if (ondblclick != null) { 468 return ondblclick; 469 } 470 ValueBinding vb = getValueBinding("ondblclick"); 471 return vb != null ? (String ) vb.getValue(getFacesContext()) : null; 472 } 473 474 477 public String getOnmousedown() { 478 if (onmousedown != null) { 479 return onmousedown; 480 } 481 ValueBinding vb = getValueBinding("onmousedown"); 482 return vb != null ? (String ) vb.getValue(getFacesContext()) : null; 483 } 484 485 488 public String getOnmouseup() { 489 if (onmouseup != null) { 490 return onmouseup; 491 } 492 ValueBinding vb = getValueBinding("onmouseup"); 493 return vb != null ? (String ) vb.getValue(getFacesContext()) : null; 494 } 495 496 499 public String getOnmouseover() { 500 if (onmouseover != null) { 501 return onmouseover; 502 } 503 ValueBinding vb = getValueBinding("onmouseover"); 504 return vb != null ? (String ) vb.getValue(getFacesContext()) : null; 505 } 506 507 510 public String getOnmousemove() { 511 if (onmousemove != null) { 512 return onmousemove; 513 } 514 ValueBinding vb = getValueBinding("onmousemove"); 515 return vb != null ? (String ) vb.getValue(getFacesContext()) : null; 516 } 517 518 521 public String getOnmouseout() { 522 if (onmouseout != null) { 523 return onmouseout; 524 } 525 ValueBinding vb = getValueBinding("onmouseout"); 526 return vb != null ? (String ) vb.getValue(getFacesContext()) : null; 527 } 528 529 532 public String getOnkeypress() { 533 if (onkeypress != null) { 534 return onkeypress; 535 } 536 ValueBinding vb = getValueBinding("onkeypress"); 537 return vb != null ? (String ) vb.getValue(getFacesContext()) : null; 538 } 539 540 543 public String getOnkeydown() { 544 if (onkeydown != null) { 545 return onkeydown; 546 } 547 ValueBinding vb = getValueBinding("onkeydown"); 548 return vb != null ? (String ) vb.getValue(getFacesContext()) : null; 549 } 550 551 554 public String getOnkeyup() { 555 if (onkeyup != null) { 556 return onkeyup; 557 } 558 ValueBinding vb = getValueBinding("onkeyup"); 559 return vb != null ? (String ) vb.getValue(getFacesContext()) : null; 560 } 561 562 565 public void setIcon(String icon) { 566 this.icon = icon; 567 } 568 569 572 public String getIcon() { 573 if (icon != null) { 574 return icon; 575 } 576 ValueBinding vb = getValueBinding("icon"); 577 return vb != null ? (String ) vb.getValue(getFacesContext()) : null; 578 } 579 580 583 public void setIconAlignRight(boolean iconAlignRight) { 584 this.iconAlignRight = new Boolean (iconAlignRight); 585 } 586 587 590 public boolean isIconAlignRight() { 591 if (iconAlignRight != null) { 592 return iconAlignRight.booleanValue(); 593 } 594 ValueBinding vb = getValueBinding("iconAlignRight"); 595 return vb != null ? 596 ((Boolean ) vb.getValue(getFacesContext())).booleanValue() : 597 false; 598 } 599 600 606 void addHeaderText(DOMContext domContext, Node parent, Node child, 607 PanelTabSet tabSet) { 608 Element table = (Element ) domContext.createElement(HTML.TABLE_ELEM); 609 table.setAttribute(HTML.CELLPADDING_ATTR,"0"); 610 table.setAttribute(HTML.CELLSPACING_ATTR,"0"); 611 Element tr = (Element ) domContext.createElement(HTML.TR_ELEM); 612 Element labelTd = (Element ) domContext.createElement(HTML.TD_ELEM); 613 table.appendChild(tr); 614 parent.appendChild(table); 615 labelTd.appendChild(child); 616 617 parent.appendChild(table); 618 if (getIcon() == null) { 619 tr.appendChild(labelTd); 620 return; 621 } 622 623 Element iconTd = (Element ) domContext.createElement(HTML.TD_ELEM); 624 Element icon = (Element ) domContext.createElement(HTML.IMG_ELEM); 625 icon.setAttribute(HTML.SRC_ATTR, getIcon()); 626 icon.setAttribute(HTML.BORDER_ATTR, "border"); 627 iconTd.appendChild(icon); 628 629 String iconClass = CSS_DEFAULT.PANEL_TAB_HEADER_ICON_DEFAULT_CLASS; 630 631 if (isIconAlignRight()) { 632 tr.appendChild(labelTd); 633 tr.appendChild(iconTd); 634 iconClass += CSS_DEFAULT.PANEL_TAB_SET_DEFAULT_RIGHT; 635 } else { 636 tr.appendChild(iconTd); 637 tr.appendChild(labelTd); 638 iconClass += CSS_DEFAULT.PANEL_TAB_SET_DEFAULT_LEFT; 639 } 640 iconClass = Util.getQualifiedStyleClass(tabSet,iconClass); 641 icon.setAttribute(HTML.CLASS_ATTR, iconClass); 642 } 643 644 String getTabOnClass(String placement) { 645 return Util.getQualifiedStyleClass(this, 646 CSS_DEFAULT.PANEL_TAB_SET_DEFAULT_TABONCLASS + 647 placement); 648 } 649 650 String getTabOffClass(String placement) { 651 return Util.getQualifiedStyleClass(this, 652 CSS_DEFAULT.PANEL_TAB_SET_DEFAULT_TABOFFCLASS + 653 placement); 654 } 655 656 String getTabOverClass(String placement) { 657 return Util.getQualifiedStyleClass(this, 658 CSS_DEFAULT.PANEL_TAB_SET_DEFAULT_TABOVERCLASS + 659 placement); 660 } 661 } 662 | Popular Tags |