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:
034: package com.icesoft.faces.component.ext;
035:
036: import com.icesoft.faces.component.CSS_DEFAULT;
037: import com.icesoft.faces.component.ext.taglib.Util;
038: import com.icesoft.faces.context.effects.Effect;
039: import com.icesoft.faces.context.effects.JavascriptContext;
040:
041: import javax.faces.context.FacesContext;
042: import javax.faces.el.ValueBinding;
043:
044: /**
045: * This is an extension of javax.faces.component.html.HtmlPanelGrid, which
046: * provides some additional behavior to this component such as: <ul> <li>changes
047: * the component's rendered state based on the authentication</li> <li>adds
048: * effects to the component</li> <ul>
049: */
050: public class HtmlPanelGrid extends
051: javax.faces.component.html.HtmlPanelGrid {
052: public static final String COMPONENT_TYPE = "com.icesoft.faces.HtmlPanelGrid";
053: public static final String RENDERER_TYPE = "com.icesoft.faces.Grid";
054: private static final boolean DEFAULT_VISIBLE = true;
055: private String renderedOnUserRole = null;
056: private Effect effect;
057: private Boolean visible = null;
058:
059: public HtmlPanelGrid() {
060: super ();
061: setRendererType(RENDERER_TYPE);
062: }
063:
064: public void setValueBinding(String s, ValueBinding vb) {
065: if (s != null && s.indexOf("effect") != -1) {
066: // If this is an effect attribute make sure Ice Extras is included
067: JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
068: getFacesContext());
069: }
070: super .setValueBinding(s, vb);
071: }
072:
073: /**
074: * <p>Set the value of the <code>visible</code> property.</p>
075: */
076: public void setVisible(boolean visible) {
077: this .visible = Boolean.valueOf(visible);
078: }
079:
080: /**
081: * <p>Return the value of the <code>visible</code> property.</p>
082: */
083: public boolean getVisible() {
084: if (visible != null) {
085: return visible.booleanValue();
086: }
087: ValueBinding vb = getValueBinding("visible");
088: Boolean boolVal = vb != null ? (Boolean) vb
089: .getValue(getFacesContext()) : null;
090: return boolVal != null ? boolVal.booleanValue()
091: : DEFAULT_VISIBLE;
092: }
093:
094: /**
095: * <p>Set the value of the <code>effect</code> property.</p>
096: */
097: public void setEffect(Effect effect) {
098: this .effect = effect;
099: JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
100: 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())
112: : null;
113: }
114:
115: /**
116: * <p>Set the value of the <code>renderedOnUserRole</code> property.</p>
117: */
118: public void setRenderedOnUserRole(String renderedOnUserRole) {
119: this .renderedOnUserRole = renderedOnUserRole;
120: }
121:
122: /**
123: * <p>Return the value of the <code>renderedOnUserRole</code> property.</p>
124: */
125: public String getRenderedOnUserRole() {
126: if (renderedOnUserRole != null) {
127: return renderedOnUserRole;
128: }
129: ValueBinding vb = getValueBinding("renderedOnUserRole");
130: return vb != null ? (String) vb.getValue(getFacesContext())
131: : null;
132: }
133:
134: /**
135: * <p>Return the value of the <code>rendered</code> property.</p>
136: */
137: public boolean isRendered() {
138: if (!Util.isRenderedOnUserRole(this )) {
139: return false;
140: }
141: return super .isRendered();
142: }
143:
144: /**
145: * <p>Gets the state of the instance as a <code>Serializable</code>
146: * Object.</p>
147: */
148: public Object saveState(FacesContext context) {
149: Object values[] = new Object[5];
150: values[0] = super .saveState(context);
151: values[1] = renderedOnUserRole;
152: values[2] = effect;
153: values[3] = visible;
154: return ((Object) (values));
155: }
156:
157: /**
158: * <p>Perform any processing required to restore the state from the entries
159: * in the state Object.</p>
160: */
161: public void restoreState(FacesContext context, Object state) {
162: Object values[] = (Object[]) state;
163: super .restoreState(context, values[0]);
164: renderedOnUserRole = (String) values[1];
165: effect = (Effect) values[2];
166: visible = (Boolean) values[3];
167: }
168:
169: /**
170: * <p>Return the value of the <code>styleClass</code> property.</p>
171: */
172: public String getStyleClass() {
173: return Util.getQualifiedStyleClass(this , 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 getHeaderClass() {
183: return Util.getQualifiedStyleClass(this ,
184: super .getHeaderClass(), CSS_DEFAULT.HEADER,
185: "headerClass");
186: }
187:
188: /**
189: * <p>Return the value of the <code>footerClass</code> property.</p>
190: */
191: public String getFooterClass() {
192: return Util.getQualifiedStyleClass(this ,
193: super .getFooterClass(), CSS_DEFAULT.FOOTER,
194: "footerClass");
195: }
196: }
|