KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

77     public void setVisible(boolean visible) {
78         this.visible = Boolean.valueOf(visible);
79     }
80
81     /**
82      * <p>Return the value of the <code>visible</code> property.</p>
83      */

84     public boolean getVisible() {
85         if (visible != null) {
86             return visible.booleanValue();
87         }
88         ValueBinding vb = getValueBinding("visible");
89         Boolean JavaDoc boolVal =
90                 vb != null ? (Boolean JavaDoc) vb.getValue(getFacesContext()) : null;
91         return boolVal != null ? boolVal.booleanValue() : DEFAULT_VISIBLE;
92     }
93
94     /**
95      * <p>Set the value of the <code>effect</code> property.</p>
96      */

97     public void setEffect(Effect effect) {
98         this.effect = effect;
99         JavascriptContext
100                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
101     }
102
103     /**
104      * <p>Return the value of the <code>effect</code> property.</p>
105      */

106     public Effect getEffect() {
107         if (effect != null) {
108             return effect;
109         }
110         ValueBinding vb = getValueBinding("effect");
111         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
112     }
113
114     /**
115      * <p>Set the value of the <code>renderedOnUserRole</code> property.</p>
116      */

117     public void setRenderedOnUserRole(String JavaDoc renderedOnUserRole) {
118         this.renderedOnUserRole = renderedOnUserRole;
119     }
120
121     /**
122      * <p>Return the value of the <code>renderedOnUserRole</code> property.</p>
123      */

124     public String JavaDoc getRenderedOnUserRole() {
125         if (renderedOnUserRole != null) {
126             return renderedOnUserRole;
127         }
128         ValueBinding vb = getValueBinding("renderedOnUserRole");
129         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
130     }
131
132     /**
133      * <p>Return the value of the <code>rendered</code> property.</p>
134      */

135     public boolean isRendered() {
136         if (!Util.isRenderedOnUserRole(this)) {
137             return false;
138         }
139         return super.isRendered();
140     }
141
142     /**
143      * <p>Gets the state of the instance as a <code>Serializable</code>
144      * Object.</p>
145      */

146     public Object JavaDoc saveState(FacesContext context) {
147         Object JavaDoc values[] = new Object JavaDoc[5];
148         values[0] = super.saveState(context);
149         values[1] = renderedOnUserRole;
150         values[2] = effect;
151         values[3] = visible;
152         return ((Object JavaDoc) (values));
153     }
154
155     /**
156      * <p>Perform any processing required to restore the state from the entries
157      * in the state Object.</p>
158      */

159     public void restoreState(FacesContext context, Object JavaDoc state) {
160         Object JavaDoc values[] = (Object JavaDoc[]) state;
161         super.restoreState(context, values[0]);
162         renderedOnUserRole = (String JavaDoc) values[1];
163         effect = (Effect) values[2];
164         visible = (Boolean JavaDoc) values[3];
165     }
166
167
168     /**
169      * <p>Return the value of the <code>styleClass</code> property.</p>
170      */

171     public String JavaDoc getStyleClass() {
172         return Util.getQualifiedStyleClass(this,
173                 super.getStyleClass(),
174                 CSS_DEFAULT.PANEL_GRID_DEFAULT_STYLE_CLASS,
175                 "styleClass");
176         
177     }
178
179     /**
180      * <p>Return the value of the <code>headerClass</code> property.</p>
181      */

182     public String JavaDoc getHeaderClass() {
183         return Util.getQualifiedStyleClass(this,
184                 super.getHeaderClass(),
185                 CSS_DEFAULT.HEADER,
186                 "headerClass");
187     }
188
189     /**
190      * <p>Return the value of the <code>footerClass</code> property.</p>
191      */

192     public String JavaDoc getFooterClass() {
193         return Util.getQualifiedStyleClass(this,
194                 super.getFooterClass(),
195                 CSS_DEFAULT.FOOTER,
196                 "footerClass");
197     }
198 }
199
Popular Tags