001: /*
002: * Version: MPL 1.1/GPL 2.0/LGPL 2.1
003: *
004: * "The contents of this file are subject to the Mozilla Public License
005: * Version 1.1 (the "License"); you may not use this file except in
006: * compliance with the License. You may obtain a copy of the License at
007: * http://www.mozilla.org/MPL/
008: *
009: * Software distributed under the License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
011: * License for the specific language governing rights and limitations under
012: * the License.
013: *
014: * The Original Code is ICEfaces 1.5 open source software code, released
015: * November 5, 2006. The Initial Developer of the Original Code is ICEsoft
016: * Technologies Canada, Corp. Portions created by ICEsoft are Copyright (C)
017: * 2004-2006 ICEsoft Technologies Canada, Corp. All Rights Reserved.
018: *
019: * Contributor(s): _____________________.
020: *
021: * Alternatively, the contents of this file may be used under the terms of
022: * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"
023: * License), in which case the provisions of the LGPL License are
024: * applicable instead of those above. If you wish to allow use of your
025: * version of this file only under the terms of the LGPL License and not to
026: * allow others to use your version of this file under the MPL, indicate
027: * your decision by deleting the provisions above and replace them with
028: * the notice and other provisions required by the LGPL License. If you do
029: * not delete the provisions above, a recipient may use your version of
030: * this file under either the MPL or the LGPL License."
031: *
032: */
033: /* Original Copyright
034: * Copyright 2004 The Apache Software Foundation.
035: *
036: * Licensed under the Apache License, Version 2.0 (the "License");
037: * you may not use this file except in compliance with the License.
038: * You may obtain a copy of the License at
039: *
040: * http://www.apache.org/licenses/LICENSE-2.0
041: *
042: * Unless required by applicable law or agreed to in writing, software
043: * distributed under the License is distributed on an "AS IS" BASIS,
044: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
045: * See the License for the specific language governing permissions and
046: * limitations under the License.
047: */
048:
049: package com.icesoft.faces.component.paneltabset;
050:
051: import com.icesoft.faces.component.CSS_DEFAULT;
052: import com.icesoft.faces.component.ext.taglib.Util;
053: import com.icesoft.faces.context.DOMContext;
054: import com.icesoft.faces.renderkit.dom_html_basic.HTML;
055: import org.w3c.dom.Element;
056: import org.w3c.dom.Node;
057:
058: import javax.faces.component.html.HtmlPanelGroup;
059: import javax.faces.context.FacesContext;
060: import javax.faces.el.ValueBinding;
061:
062: /**
063: * PanelTab is a JSF component class that represents an ICEfaces tab panel.
064: * <p/>
065: * The component extends the javax.faces.component.html.HtmlPanelGroup.
066: */
067: public class PanelTab extends HtmlPanelGroup {
068: /**
069: * The component type.
070: */
071: public static final String COMPONENT_TYPE = "com.icesoft.faces.PanelTab";
072: /**
073: * The component family.
074: */
075: public static final String COMPONENT_FAMILY = "javax.faces.Panel";
076: /**
077: * The default renderer type.
078: */
079: private static final String DEFAULT_RENDERER_TYPE = "javax.faces.Group";
080: /**
081: * The current enabledOnUserRole state.
082: */
083: private String enabledOnUserRole = null;
084: /**
085: * The current renderedOnUserRole state.
086: */
087: private String renderedOnUserRole = null;
088: /**
089: * The current style.
090: */
091: private String style = null;
092: /**
093: * The current style class name.
094: */
095: private String styleClass = null;
096: /**
097: * The current label.
098: */
099: private String label = null;
100: /**
101: * The current disabled state.
102: */
103: private Boolean disabled = null;
104: /**
105: * The current icon.
106: */
107: private String icon = null;
108: /**
109: * The current icon.
110: */
111: private Boolean iconAlignRight = Boolean.FALSE;
112:
113: /* (non-Javadoc)
114: * @see javax.faces.component.html.HtmlPanelGroup#setStyle(java.lang.String)
115: */
116: public void setStyle(String style) {
117: this .style = style;
118: }
119:
120: /* (non-Javadoc)
121: * @see javax.faces.component.html.HtmlPanelGroup#getStyle()
122: */
123: public String getStyle() {
124: if (style != null) {
125: return style;
126: }
127: ValueBinding vb = getValueBinding("style");
128: return vb != null ? (String) vb.getValue(getFacesContext())
129: : null;
130: }
131:
132: /* (non-Javadoc)
133: * @see javax.faces.component.html.HtmlPanelGroup#setStyleClass(java.lang.String)
134: */
135: public void setStyleClass(String styleClass) {
136: this .styleClass = styleClass;
137: }
138:
139: /* (non-Javadoc)
140: * @see javax.faces.component.html.HtmlPanelGroup#getStyleClass()
141: */
142: public String getStyleClass() {
143: return Util.getQualifiedStyleClass(this , styleClass,
144: CSS_DEFAULT.PANEL_TAB_DEFAULT_STYLECLASS, "styleClass");
145: }
146:
147: /**
148: * @param enabledOnUserRole
149: */
150: public void setEnabledOnUserRole(String enabledOnUserRole) {
151: this .enabledOnUserRole = enabledOnUserRole;
152: }
153:
154: /**
155: * @return the value of enabledOnUserRole
156: */
157: public String getEnabledOnUserRole() {
158: if (enabledOnUserRole != null) {
159: return enabledOnUserRole;
160: }
161: ValueBinding vb = getValueBinding("enabledOnUserRole");
162: return vb != null ? (String) vb.getValue(getFacesContext())
163: : null;
164: }
165:
166: /**
167: * @param renderedOnUserRole
168: */
169: public void setRenderedOnUserRole(String renderedOnUserRole) {
170: this .renderedOnUserRole = renderedOnUserRole;
171: }
172:
173: /**
174: * @return the value of renderedOnUserRole
175: */
176: public String getRenderedOnUserRole() {
177: if (renderedOnUserRole != null) {
178: return renderedOnUserRole;
179: }
180: ValueBinding vb = getValueBinding("renderedOnUserRole");
181: return vb != null ? (String) vb.getValue(getFacesContext())
182: : null;
183: }
184:
185: /**
186: * Creates an instance and sets the default renderer type to
187: * "javax.faces.Group".
188: */
189: public PanelTab() {
190: setRendererType(DEFAULT_RENDERER_TYPE);
191: }
192:
193: /* (non-Javadoc)
194: * @see javax.faces.component.UIComponent#getFamily()
195: */
196: public String getFamily() {
197: return COMPONENT_FAMILY;
198: }
199:
200: /**
201: * @param label
202: */
203: public void setLabel(String label) {
204: this .label = label;
205: }
206:
207: /**
208: * @return the value of label
209: */
210: public String getLabel() {
211: if (label != null) {
212: return label;
213: }
214: ValueBinding vb = getValueBinding("label");
215: return vb != null ? (String) vb.getValue(getFacesContext())
216: : null;
217: }
218:
219: /**
220: * @param disabled
221: */
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: /**
232: * @return the value of disabled
233: */
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 = vb != null ? (Boolean) vb
244: .getValue(getFacesContext()) : null;
245: return v != null ? v.booleanValue() : false;
246: }
247:
248: /* (non-Javadoc)
249: * @see javax.faces.component.StateHolder#saveState(javax.faces.context.FacesContext)
250: */
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: /* (non-Javadoc)
277: * @see javax.faces.component.StateHolder#restoreState(javax.faces.context.FacesContext, java.lang.Object)
278: */
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: /* (non-Javadoc)
304: * @see javax.faces.component.UIComponent#isRendered()
305: */
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: * @param dir
329: */
330: public void setDir(String dir) {
331: this .dir = dir;
332: }
333:
334: /**
335: * @param lang
336: */
337: public void setLang(String lang) {
338: this .lang = lang;
339: }
340:
341: /**
342: * @param title
343: */
344: public void setTitle(String title) {
345: this .title = title;
346: }
347:
348: /**
349: * @param onclick
350: */
351: public void setOnclick(String onclick) {
352: this .onclick = onclick;
353: }
354:
355: /**
356: * @param ondblclick
357: */
358: public void setOndblclick(String ondblclick) {
359: this .ondblclick = ondblclick;
360: }
361:
362: /**
363: * @param onkeydown
364: */
365: public void setOnkeydown(String onkeydown) {
366: this .onkeydown = onkeydown;
367: }
368:
369: /**
370: * @param onkeypress
371: */
372: public void setOnkeypress(String onkeypress) {
373: this .onkeypress = onkeypress;
374: }
375:
376: /**
377: * @param onkeyup
378: */
379: public void setOnkeyup(String onkeyup) {
380: this .onkeyup = onkeyup;
381: }
382:
383: /**
384: * @param onmousedown
385: */
386: public void setOnmousedown(String onmousedown) {
387: this .onmousedown = onmousedown;
388: }
389:
390: /**
391: * @param onmousemove
392: */
393: public void setOnmousemove(String onmousemove) {
394: this .onmousemove = onmousemove;
395: }
396:
397: /**
398: * @param onmouseout
399: */
400: public void setOnmouseout(String onmouseout) {
401: this .onmouseout = onmouseout;
402: }
403:
404: /**
405: * @param onmouseover
406: */
407: public void setOnmouseover(String onmouseover) {
408: this .onmouseover = onmouseover;
409: }
410:
411: /**
412: * @param onmouseup
413: */
414: public void setOnmouseup(String onmouseup) {
415: this .onmouseup = onmouseup;
416: }
417:
418: /**
419: * @return the value of dir property
420: */
421: public String getDir() {
422: if (dir != null) {
423: return dir;
424: }
425: ValueBinding vb = getValueBinding("dir");
426: return vb != null ? (String) vb.getValue(getFacesContext())
427: : null;
428: }
429:
430: /**
431: * @return the value of lang property
432: */
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())
439: : null;
440: }
441:
442: /**
443: * @return the value of title property
444: */
445: public String getTitle() {
446: if (title != null) {
447: return title;
448: }
449: ValueBinding vb = getValueBinding("title");
450: return vb != null ? (String) vb.getValue(getFacesContext())
451: : null;
452: }
453:
454: /**
455: * @return the value of onclick property
456: */
457: public String getOnclick() {
458: if (onclick != null) {
459: return onclick;
460: }
461: ValueBinding vb = getValueBinding("onclick");
462: return vb != null ? (String) vb.getValue(getFacesContext())
463: : null;
464: }
465:
466: /**
467: * @return the value of ondblclick property
468: */
469: public String getOndblclick() {
470: if (ondblclick != null) {
471: return ondblclick;
472: }
473: ValueBinding vb = getValueBinding("ondblclick");
474: return vb != null ? (String) vb.getValue(getFacesContext())
475: : null;
476: }
477:
478: /**
479: * @return the value of onmousedown property
480: */
481: public String getOnmousedown() {
482: if (onmousedown != null) {
483: return onmousedown;
484: }
485: ValueBinding vb = getValueBinding("onmousedown");
486: return vb != null ? (String) vb.getValue(getFacesContext())
487: : null;
488: }
489:
490: /**
491: * @return the value of onmouseup property
492: */
493: public String getOnmouseup() {
494: if (onmouseup != null) {
495: return onmouseup;
496: }
497: ValueBinding vb = getValueBinding("onmouseup");
498: return vb != null ? (String) vb.getValue(getFacesContext())
499: : null;
500: }
501:
502: /**
503: * @return the value of onmouseover property
504: */
505: public String getOnmouseover() {
506: if (onmouseover != null) {
507: return onmouseover;
508: }
509: ValueBinding vb = getValueBinding("onmouseover");
510: return vb != null ? (String) vb.getValue(getFacesContext())
511: : null;
512: }
513:
514: /**
515: * @return the value of onmousemove property
516: */
517: public String getOnmousemove() {
518: if (onmousemove != null) {
519: return onmousemove;
520: }
521: ValueBinding vb = getValueBinding("onmousemove");
522: return vb != null ? (String) vb.getValue(getFacesContext())
523: : null;
524: }
525:
526: /**
527: * @return the value of onmouseout property
528: */
529: public String getOnmouseout() {
530: if (onmouseout != null) {
531: return onmouseout;
532: }
533: ValueBinding vb = getValueBinding("onmouseout");
534: return vb != null ? (String) vb.getValue(getFacesContext())
535: : null;
536: }
537:
538: /**
539: * @return the value of onkeypress property
540: */
541: public String getOnkeypress() {
542: if (onkeypress != null) {
543: return onkeypress;
544: }
545: ValueBinding vb = getValueBinding("onkeypress");
546: return vb != null ? (String) vb.getValue(getFacesContext())
547: : null;
548: }
549:
550: /**
551: * @return the value of onkeydown property
552: */
553: public String getOnkeydown() {
554: if (onkeydown != null) {
555: return onkeydown;
556: }
557: ValueBinding vb = getValueBinding("onkeydown");
558: return vb != null ? (String) vb.getValue(getFacesContext())
559: : null;
560: }
561:
562: /**
563: * @return the value of onkeyup property
564: */
565: public String getOnkeyup() {
566: if (onkeyup != null) {
567: return onkeyup;
568: }
569: ValueBinding vb = getValueBinding("onkeyup");
570: return vb != null ? (String) vb.getValue(getFacesContext())
571: : null;
572: }
573:
574: /**
575: * @param icon
576: */
577: public void setIcon(String icon) {
578: this .icon = icon;
579: }
580:
581: /**
582: * @return icon
583: */
584: public String getIcon() {
585: if (icon != null) {
586: return icon;
587: }
588: ValueBinding vb = getValueBinding("icon");
589: return vb != null ? (String) vb.getValue(getFacesContext())
590: : null;
591: }
592:
593: /**
594: * @param iconAlignRight
595: */
596: public void setIconAlignRight(boolean iconAlignRight) {
597: this .iconAlignRight = new Boolean(iconAlignRight);
598: }
599:
600: /**
601: * @return iconAlignRight
602: */
603: public boolean isIconAlignRight() {
604: if (iconAlignRight != null) {
605: return iconAlignRight.booleanValue();
606: }
607: ValueBinding vb = getValueBinding("iconAlignRight");
608: return vb != null ? ((Boolean) vb.getValue(getFacesContext()))
609: .booleanValue() : false;
610: }
611:
612: /**
613: * @param domContext
614: * @param parent
615: * @param child
616: * @param tabSet
617: */
618: void addHeaderText(DOMContext domContext, Node parent, Node child,
619: PanelTabSet tabSet) {
620: Element table = (Element) domContext
621: .createElement(HTML.TABLE_ELEM);
622: table.setAttribute(HTML.CELLPADDING_ATTR, "0");
623: table.setAttribute(HTML.CELLSPACING_ATTR, "0");
624: Element tr = (Element) domContext.createElement(HTML.TR_ELEM);
625: Element labelTd = (Element) domContext
626: .createElement(HTML.TD_ELEM);
627: table.appendChild(tr);
628: parent.appendChild(table);
629: labelTd.appendChild(child);
630:
631: parent.appendChild(table);
632: if (getIcon() == null) {
633: tr.appendChild(labelTd);
634: return;
635: }
636:
637: Element iconTd = (Element) domContext
638: .createElement(HTML.TD_ELEM);
639: Element icon = (Element) domContext
640: .createElement(HTML.IMG_ELEM);
641: icon.setAttribute(HTML.SRC_ATTR, getIcon());
642: icon.setAttribute(HTML.BORDER_ATTR, "border");
643: iconTd.appendChild(icon);
644:
645: String iconClass = CSS_DEFAULT.PANEL_TAB_HEADER_ICON_DEFAULT_CLASS;
646:
647: if (isIconAlignRight()) {
648: tr.appendChild(labelTd);
649: tr.appendChild(iconTd);
650: iconClass += CSS_DEFAULT.PANEL_TAB_SET_DEFAULT_RIGHT;
651: } else {
652: tr.appendChild(iconTd);
653: tr.appendChild(labelTd);
654: iconClass += CSS_DEFAULT.PANEL_TAB_SET_DEFAULT_LEFT;
655: }
656: iconClass = Util.getQualifiedStyleClass(tabSet, iconClass);
657: icon.setAttribute(HTML.CLASS_ATTR, iconClass);
658: }
659:
660: String getTabOnClass(String placement) {
661: return Util.getQualifiedStyleClass(this ,
662: CSS_DEFAULT.PANEL_TAB_SET_DEFAULT_TABONCLASS
663: + placement);
664: }
665:
666: String getTabOffClass(String placement) {
667: return Util.getQualifiedStyleClass(this ,
668: CSS_DEFAULT.PANEL_TAB_SET_DEFAULT_TABOFFCLASS
669: + placement);
670: }
671:
672: String getTabOverClass(String placement) {
673: return Util.getQualifiedStyleClass(this,
674: CSS_DEFAULT.PANEL_TAB_SET_DEFAULT_TABOVERCLASS
675: + placement);
676: }
677: }
|