KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > icesoft > faces > component > paneltabset > PanelTab


1 /*
2  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3  *
4  * "The contents of this file are subject to the Mozilla Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License at
7  * http://www.mozilla.org/MPL/
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
11  * License for the specific language governing rights and limitations under
12  * the License.
13  *
14  * The Original Code is ICEfaces 1.5 open source software code, released
15  * November 5, 2006. The Initial Developer of the Original Code is ICEsoft
16  * Technologies Canada, Corp. Portions created by ICEsoft are Copyright (C)
17  * 2004-2006 ICEsoft Technologies Canada, Corp. All Rights Reserved.
18  *
19  * Contributor(s): _____________________.
20  *
21  * Alternatively, the contents of this file may be used under the terms of
22  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"
23  * License), in which case the provisions of the LGPL License are
24  * applicable instead of those above. If you wish to allow use of your
25  * version of this file only under the terms of the LGPL License and not to
26  * allow others to use your version of this file under the MPL, indicate
27  * your decision by deleting the provisions above and replace them with
28  * the notice and other provisions required by the LGPL License. If you do
29  * not delete the provisions above, a recipient may use your version of
30  * this file under either the MPL or the LGPL License."
31  *
32  */

33 /* Original Copyright
34  * Copyright 2004 The Apache Software Foundation.
35  *
36  * Licensed under the Apache License, Version 2.0 (the "License");
37  * you may not use this file except in compliance with the License.
38  * You may obtain a copy of the License at
39  *
40  * http://www.apache.org/licenses/LICENSE-2.0
41  *
42  * Unless required by applicable law or agreed to in writing, software
43  * distributed under the License is distributed on an "AS IS" BASIS,
44  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
45  * See the License for the specific language governing permissions and
46  * limitations under the License.
47  */

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 JavaDoc;
56 import org.w3c.dom.Node JavaDoc;
57
58 import javax.faces.component.html.HtmlPanelGroup;
59 import javax.faces.context.FacesContext;
60 import javax.faces.el.ValueBinding;
61
62 /**
63  * PanelTab is a JSF component class that represents an ICEfaces tab panel.
64  * <p/>
65  * The component extends the javax.faces.component.html.HtmlPanelGroup.
66  */

67 public class PanelTab
68         extends HtmlPanelGroup {
69     /**
70      * The component type.
71      */

72     public static final String JavaDoc COMPONENT_TYPE = "com.icesoft.faces.PanelTab";
73     /**
74      * The component family.
75      */

76     public static final String JavaDoc COMPONENT_FAMILY = "javax.faces.Panel";
77     /**
78      * The default renderer type.
79      */

80     private static final String JavaDoc DEFAULT_RENDERER_TYPE = "javax.faces.Group";
81     /**
82      * The current enabledOnUserRole state.
83      */

84     private String JavaDoc enabledOnUserRole = null;
85     /**
86      * The current renderedOnUserRole state.
87      */

88     private String JavaDoc renderedOnUserRole = null;
89     /**
90      * The current style.
91      */

92     private String JavaDoc style = null;
93     /**
94      * The current style class name.
95      */

96     private String JavaDoc styleClass = null;
97     /**
98      * The current label.
99      */

100     private String JavaDoc label = null;
101     /**
102      * The current disabled state.
103      */

104     private Boolean JavaDoc disabled = null;
105     /**
106      * The current icon.
107      */

108     private String JavaDoc icon = null;
109     /**
110      * The current icon.
111      */

112     private Boolean JavaDoc iconAlignRight = Boolean.FALSE;
113
114
115     /* (non-Javadoc)
116     * @see javax.faces.component.html.HtmlPanelGroup#setStyle(java.lang.String)
117     */

118     public void setStyle(String JavaDoc style) {
119         this.style = style;
120     }
121
122     /* (non-Javadoc)
123      * @see javax.faces.component.html.HtmlPanelGroup#getStyle()
124      */

125     public String JavaDoc getStyle() {
126         if (style != null) {
127             return style;
128         }
129         ValueBinding vb = getValueBinding("style");
130         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
131     }
132
133     /* (non-Javadoc)
134      * @see javax.faces.component.html.HtmlPanelGroup#setStyleClass(java.lang.String)
135      */

136     public void setStyleClass(String JavaDoc styleClass) {
137         this.styleClass = styleClass;
138     }
139
140     /* (non-Javadoc)
141      * @see javax.faces.component.html.HtmlPanelGroup#getStyleClass()
142      */

143     public String JavaDoc getStyleClass() {
144         return Util.getQualifiedStyleClass(this,
145                 styleClass,
146                 CSS_DEFAULT.PANEL_TAB_DEFAULT_STYLECLASS,
147                 "styleClass");
148     }
149
150     /**
151      * @param enabledOnUserRole
152      */

153     public void setEnabledOnUserRole(String JavaDoc enabledOnUserRole) {
154         this.enabledOnUserRole = enabledOnUserRole;
155     }
156
157     /**
158      * @return the value of enabledOnUserRole
159      */

160     public String JavaDoc getEnabledOnUserRole() {
161         if (enabledOnUserRole != null) {
162             return enabledOnUserRole;
163         }
164         ValueBinding vb = getValueBinding("enabledOnUserRole");
165         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
166     }
167
168     /**
169      * @param renderedOnUserRole
170      */

171     public void setRenderedOnUserRole(String JavaDoc renderedOnUserRole) {
172         this.renderedOnUserRole = renderedOnUserRole;
173     }
174
175     /**
176      * @return the value of renderedOnUserRole
177      */

178     public String JavaDoc getRenderedOnUserRole() {
179         if (renderedOnUserRole != null) {
180             return renderedOnUserRole;
181         }
182         ValueBinding vb = getValueBinding("renderedOnUserRole");
183         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
184     }
185
186     /**
187      * Creates an instance and sets the default renderer type to
188      * "javax.faces.Group".
189      */

190     public PanelTab() {
191         setRendererType(DEFAULT_RENDERER_TYPE);
192     }
193
194     /* (non-Javadoc)
195      * @see javax.faces.component.UIComponent#getFamily()
196      */

197     public String JavaDoc getFamily() {
198         return COMPONENT_FAMILY;
199     }
200
201     /**
202      * @param label
203      */

204     public void setLabel(String JavaDoc label) {
205         this.label = label;
206     }
207
208     /**
209      * @return the value of label
210      */

211     public String JavaDoc getLabel() {
212         if (label != null) {
213             return label;
214         }
215         ValueBinding vb = getValueBinding("label");
216         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
217     }
218
219     /**
220      * @param disabled
221      */

222     public void setDisabled(boolean disabled) {
223         this.disabled = new Boolean JavaDoc(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 JavaDoc v =
244                 vb != null ? (Boolean JavaDoc) vb.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 JavaDoc saveState(FacesContext context) {
252         Object JavaDoc values[] = new Object JavaDoc[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 JavaDoc) (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 JavaDoc state) {
280         Object JavaDoc values[] = (Object JavaDoc[]) state;
281         super.restoreState(context, values[0]);
282         label = (String JavaDoc) values[1];
283         disabled = (Boolean JavaDoc) values[2];
284         enabledOnUserRole = (String JavaDoc) values[3];
285         renderedOnUserRole = (String JavaDoc) values[4];
286         style = (String JavaDoc) values[5];
287         styleClass = (String JavaDoc) values[6];
288         dir = (String JavaDoc) values[7];
289         lang = (String JavaDoc) values[8];
290         title = (String JavaDoc) values[9];
291         onclick = (String JavaDoc) values[10];
292         ondblclick = (String JavaDoc) values[11];
293         onmousedown = (String JavaDoc) values[12];
294         onmouseup = (String JavaDoc) values[13];
295         onmouseover = (String JavaDoc) values[14];
296         onmousemove = (String JavaDoc) values[15];
297         onmouseout = (String JavaDoc) values[16];
298         onkeypress = (String JavaDoc) values[17];
299         onkeydown = (String JavaDoc) values[18];
300         onkeyup = (String JavaDoc) 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 JavaDoc dir = null;
314     private String JavaDoc lang = null;
315     private String JavaDoc title = null;
316     private String JavaDoc onclick = null;
317     private String JavaDoc ondblclick = null;
318     private String JavaDoc onmousedown = null;
319     private String JavaDoc onmouseup = null;
320     private String JavaDoc onmouseover = null;
321     private String JavaDoc onmousemove = null;
322     private String JavaDoc onmouseout = null;
323     private String JavaDoc onkeypress = null;
324     private String JavaDoc onkeydown = null;
325     private String JavaDoc onkeyup = null;
326
327
328     /**
329      * @param dir
330      */

331     public void setDir(String JavaDoc dir) {
332         this.dir = dir;
333     }
334
335     /**
336      * @param lang
337      */

338     public void setLang(String JavaDoc lang) {
339         this.lang = lang;
340     }
341
342     /**
343      * @param title
344      */

345     public void setTitle(String JavaDoc title) {
346         this.title = title;
347     }
348
349     /**
350      * @param onclick
351      */

352     public void setOnclick(String JavaDoc onclick) {
353         this.onclick = onclick;
354     }
355
356     /**
357      * @param ondblclick
358      */

359     public void setOndblclick(String JavaDoc ondblclick) {
360         this.ondblclick = ondblclick;
361     }
362
363     /**
364      * @param onkeydown
365      */

366     public void setOnkeydown(String JavaDoc onkeydown) {
367         this.onkeydown = onkeydown;
368     }
369
370     /**
371      * @param onkeypress
372      */

373     public void setOnkeypress(String JavaDoc onkeypress) {
374         this.onkeypress = onkeypress;
375     }
376
377     /**
378      * @param onkeyup
379      */

380     public void setOnkeyup(String JavaDoc onkeyup) {
381         this.onkeyup = onkeyup;
382     }
383
384     /**
385      * @param onmousedown
386      */

387     public void setOnmousedown(String JavaDoc onmousedown) {
388         this.onmousedown = onmousedown;
389     }
390
391     /**
392      * @param onmousemove
393      */

394     public void setOnmousemove(String JavaDoc onmousemove) {
395         this.onmousemove = onmousemove;
396     }
397
398     /**
399      * @param onmouseout
400      */

401     public void setOnmouseout(String JavaDoc onmouseout) {
402         this.onmouseout = onmouseout;
403     }
404
405     /**
406      * @param onmouseover
407      */

408     public void setOnmouseover(String JavaDoc onmouseover) {
409         this.onmouseover = onmouseover;
410     }
411
412     /**
413      * @param onmouseup
414      */

415     public void setOnmouseup(String JavaDoc onmouseup) {
416         this.onmouseup = onmouseup;
417     }
418
419     /**
420      * @return the value of dir property
421      */

422     public String JavaDoc getDir() {
423         if (dir != null) {
424             return dir;
425         }
426         ValueBinding vb = getValueBinding("dir");
427         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
428     }
429
430     /**
431      * @return the value of lang property
432      */

433     public String JavaDoc getLang() {
434         if (lang != null) {
435             return lang;
436         }
437         ValueBinding vb = getValueBinding("lang");
438         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
439     }
440
441     /**
442      * @return the value of title property
443      */

444     public String JavaDoc getTitle() {
445         if (title != null) {
446             return title;
447         }
448         ValueBinding vb = getValueBinding("title");
449         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
450     }
451
452     /**
453      * @return the value of onclick property
454      */

455     public String JavaDoc getOnclick() {
456         if (onclick != null) {
457             return onclick;
458         }
459         ValueBinding vb = getValueBinding("onclick");
460         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
461     }
462
463     /**
464      * @return the value of ondblclick property
465      */

466     public String JavaDoc getOndblclick() {
467         if (ondblclick != null) {
468             return ondblclick;
469         }
470         ValueBinding vb = getValueBinding("ondblclick");
471         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
472     }
473
474     /**
475      * @return the value of onmousedown property
476      */

477     public String JavaDoc getOnmousedown() {
478         if (onmousedown != null) {
479             return onmousedown;
480         }
481         ValueBinding vb = getValueBinding("onmousedown");
482         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
483     }
484
485     /**
486      * @return the value of onmouseup property
487      */

488     public String JavaDoc getOnmouseup() {
489         if (onmouseup != null) {
490             return onmouseup;
491         }
492         ValueBinding vb = getValueBinding("onmouseup");
493         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
494     }
495
496     /**
497      * @return the value of onmouseover property
498      */

499     public String JavaDoc getOnmouseover() {
500         if (onmouseover != null) {
501             return onmouseover;
502         }
503         ValueBinding vb = getValueBinding("onmouseover");
504         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
505     }
506
507     /**
508      * @return the value of onmousemove property
509      */

510     public String JavaDoc getOnmousemove() {
511         if (onmousemove != null) {
512             return onmousemove;
513         }
514         ValueBinding vb = getValueBinding("onmousemove");
515         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
516     }
517
518     /**
519      * @return the value of onmouseout property
520      */

521     public String JavaDoc getOnmouseout() {
522         if (onmouseout != null) {
523             return onmouseout;
524         }
525         ValueBinding vb = getValueBinding("onmouseout");
526         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
527     }
528
529     /**
530      * @return the value of onkeypress property
531      */

532     public String JavaDoc getOnkeypress() {
533         if (onkeypress != null) {
534             return onkeypress;
535         }
536         ValueBinding vb = getValueBinding("onkeypress");
537         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
538     }
539
540     /**
541      * @return the value of onkeydown property
542      */

543     public String JavaDoc getOnkeydown() {
544         if (onkeydown != null) {
545             return onkeydown;
546         }
547         ValueBinding vb = getValueBinding("onkeydown");
548         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
549     }
550
551     /**
552      * @return the value of onkeyup property
553      */

554     public String JavaDoc getOnkeyup() {
555         if (onkeyup != null) {
556             return onkeyup;
557         }
558         ValueBinding vb = getValueBinding("onkeyup");
559         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
560     }
561
562     /**
563      * @param icon
564      */

565     public void setIcon(String JavaDoc icon) {
566         this.icon = icon;
567     }
568
569     /**
570      * @return icon
571      */

572     public String JavaDoc getIcon() {
573         if (icon != null) {
574             return icon;
575         }
576         ValueBinding vb = getValueBinding("icon");
577         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
578     }
579
580     /**
581      * @param iconAlignRight
582      */

583     public void setIconAlignRight(boolean iconAlignRight) {
584         this.iconAlignRight = new Boolean JavaDoc(iconAlignRight);
585     }
586
587     /**
588      * @return iconAlignRight
589      */

590     public boolean isIconAlignRight() {
591         if (iconAlignRight != null) {
592             return iconAlignRight.booleanValue();
593         }
594         ValueBinding vb = getValueBinding("iconAlignRight");
595         return vb != null ?
596                ((Boolean JavaDoc) vb.getValue(getFacesContext())).booleanValue() :
597                false;
598     }
599
600     /**
601      * @param domContext
602      * @param parent
603      * @param child
604      * @param tabSet
605      */

606     void addHeaderText(DOMContext domContext, Node JavaDoc parent, Node JavaDoc child,
607                        PanelTabSet tabSet) {
608         Element JavaDoc table = (Element JavaDoc) domContext.createElement(HTML.TABLE_ELEM);
609         table.setAttribute(HTML.CELLPADDING_ATTR,"0");
610         table.setAttribute(HTML.CELLSPACING_ATTR,"0");
611         Element JavaDoc tr = (Element JavaDoc) domContext.createElement(HTML.TR_ELEM);
612         Element JavaDoc labelTd = (Element JavaDoc) 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 JavaDoc iconTd = (Element JavaDoc) domContext.createElement(HTML.TD_ELEM);
624         Element JavaDoc icon = (Element JavaDoc) 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 JavaDoc 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 JavaDoc getTabOnClass(String JavaDoc placement) {
645         return Util.getQualifiedStyleClass(this,
646                 CSS_DEFAULT.PANEL_TAB_SET_DEFAULT_TABONCLASS +
647                 placement);
648     }
649     
650     String JavaDoc getTabOffClass(String JavaDoc placement) {
651         return Util.getQualifiedStyleClass(this,
652         CSS_DEFAULT.PANEL_TAB_SET_DEFAULT_TABOFFCLASS +
653         placement);
654     }
655     
656     String JavaDoc getTabOverClass(String JavaDoc placement) {
657         return Util.getQualifiedStyleClass(this,
658                 CSS_DEFAULT.PANEL_TAB_SET_DEFAULT_TABOVERCLASS +
659                 placement);
660     }
661 }
662
Popular Tags