KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > icesoft > faces > component > ext > HtmlOutputLabel


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
34 package com.icesoft.faces.component.ext;
35
36 import com.icesoft.faces.component.CSS_DEFAULT;
37 import com.icesoft.faces.component.ext.taglib.Util;
38 import com.icesoft.faces.context.effects.CurrentStyle;
39 import com.icesoft.faces.context.effects.Effect;
40 import com.icesoft.faces.context.effects.JavascriptContext;
41
42 import javax.faces.context.FacesContext;
43 import javax.faces.el.ValueBinding;
44
45
46 /**
47  * This is an extension of javax.faces.component.html.HtmlOutputLabel, which
48  * provides some additional behavior to this component such as: <ul> <li>changes
49  * the component's rendered state based on the authentication</li> <li>adds
50  * effects to the component</li> <ul>
51  */

52 public class HtmlOutputLabel
53         extends javax.faces.component.html.HtmlOutputLabel {
54     public static final String JavaDoc COMPONENT_TYPE =
55             "com.icesoft.faces.HtmlOutputLabel";
56     public static final String JavaDoc RENDERER_TYPE = "com.icesoft.faces.Label";
57     private static final boolean DEFAULT_VISIBLE = true;
58     private String JavaDoc styleClass = null;
59     private String JavaDoc renderedOnUserRole = null;
60     private Effect effect;
61     private Boolean JavaDoc visible = null;
62     private CurrentStyle currentStyle;
63
64     public HtmlOutputLabel() {
65         super();
66         setRendererType(RENDERER_TYPE);
67     }
68
69     public void setValueBinding(String JavaDoc s, ValueBinding vb) {
70         if (s != null && s.indexOf("effect") != -1) {
71             // If this is an effect attribute make sure Ice Extras is included
72
JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
73                                          getFacesContext());
74         }
75         super.setValueBinding(s, vb);
76     }
77
78     /**
79      * <p>Set the value of the <code>effect</code> property.</p>
80      */

81     public void setEffect(Effect effect) {
82         this.effect = effect;
83         JavascriptContext
84                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
85     }
86
87     /**
88      * <p>Return the value of the <code>effect</code> property.</p>
89      */

90     public Effect getEffect() {
91         if (effect != null) {
92             return effect;
93         }
94         ValueBinding vb = getValueBinding("effect");
95         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
96     }
97
98     /**
99      * <p>Set the value of the <code>visible</code> property.</p>
100      */

101     public void setVisible(boolean visible) {
102         this.visible = Boolean.valueOf(visible);
103     }
104
105     /**
106      * <p>Return the value of the <code>visible</code> property.</p>
107      */

108     public boolean getVisible() {
109         if (visible != null) {
110             return visible.booleanValue();
111         }
112         ValueBinding vb = getValueBinding("visible");
113         Boolean JavaDoc boolVal =
114                 vb != null ? (Boolean JavaDoc) vb.getValue(getFacesContext()) : null;
115         return boolVal != null ? boolVal.booleanValue() : DEFAULT_VISIBLE;
116     }
117
118     /**
119      * <p>Set the value of the <code>styleClass</code> property.</p>
120      */

121     public void setStyleClass(String JavaDoc styleClass) {
122         this.styleClass = styleClass;
123     }
124
125     /**
126      * <p>Return the value of the <code>styleClass</code> property.</p>
127      */

128     public String JavaDoc getStyleClass() {
129         return Util.getQualifiedStyleClass(this,
130                 styleClass,
131                 CSS_DEFAULT.OUTPUT_LABEL_DEFAULT_STYLE_CLASS,
132                 "styleClass");
133                
134     }
135
136     /**
137      * <p>Set the value of the <code>renderedOnUserRole</code> property.</p>
138      */

139     public void setRenderedOnUserRole(String JavaDoc renderedOnUserRole) {
140         this.renderedOnUserRole = renderedOnUserRole;
141     }
142
143     /**
144      * <p>Return the value of the <code>renderedOnUserRole</code> property.</p>
145      */

146     public String JavaDoc getRenderedOnUserRole() {
147         if (renderedOnUserRole != null) {
148             return renderedOnUserRole;
149         }
150         ValueBinding vb = getValueBinding("renderedOnUserRole");
151         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
152     }
153
154     /**
155      * <p>Return the value of the <code>rendered</code> property.</p>
156      */

157     public boolean isRendered() {
158         if (!Util.isRenderedOnUserRole(this)) {
159             return false;
160         }
161         return super.isRendered();
162     }
163
164     /**
165      * <p>Return the value of the <code>currentStyle</code> property.</p>
166      */

167     public CurrentStyle getCurrentStyle() {
168         return currentStyle;
169     }
170
171     /**
172      * <p>Set the value of the <code>currentStyle</code> property.</p>
173      */

174     public void setCurrentStyle(CurrentStyle currentStyle) {
175         this.currentStyle = currentStyle;
176     }
177
178     /**
179      * <p>Gets the state of the instance as a <code>Serializable</code>
180      * Object.</p>
181      */

182     public Object JavaDoc saveState(FacesContext context) {
183         Object JavaDoc values[] = new Object JavaDoc[6];
184         values[0] = super.saveState(context);
185         values[1] = renderedOnUserRole;
186         values[2] = styleClass;
187         values[3] = effect;
188         values[4] = currentStyle;
189         values[5] = visible;
190         return ((Object JavaDoc) (values));
191     }
192
193     /**
194      * <p>Perform any processing required to restore the state from the entries
195      * in the state Object.</p>
196      */

197     public void restoreState(FacesContext context, Object JavaDoc state) {
198         Object JavaDoc values[] = (Object JavaDoc[]) state;
199         super.restoreState(context, values[0]);
200         renderedOnUserRole = (String JavaDoc) values[1];
201         styleClass = (String JavaDoc) values[2];
202         effect = (Effect) values[3];
203         currentStyle = (CurrentStyle) values[4];
204         visible = (Boolean JavaDoc) values[5];
205     }
206 }
207
Popular Tags