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.CurrentStyle;
039: import com.icesoft.faces.context.effects.Effect;
040: import com.icesoft.faces.context.effects.JavascriptContext;
041:
042: import javax.faces.context.FacesContext;
043: import javax.faces.el.ValueBinding;
044:
045: /**
046: * This is an extension of javax.faces.component.html.HtmlOutputLabel, which
047: * provides some additional behavior to this component such as: <ul> <li>changes
048: * the component's rendered state based on the authentication</li> <li>adds
049: * effects to the component</li> <ul>
050: */
051: public class HtmlOutputLabel extends
052: javax.faces.component.html.HtmlOutputLabel {
053: public static final String COMPONENT_TYPE = "com.icesoft.faces.HtmlOutputLabel";
054: public static final String RENDERER_TYPE = "com.icesoft.faces.Label";
055: private static final boolean DEFAULT_VISIBLE = true;
056: private String styleClass = null;
057: private String renderedOnUserRole = null;
058: private Effect effect;
059: private Boolean visible = null;
060: private CurrentStyle currentStyle;
061:
062: public HtmlOutputLabel() {
063: super ();
064: setRendererType(RENDERER_TYPE);
065: }
066:
067: public void setValueBinding(String s, ValueBinding vb) {
068: if (s != null && s.indexOf("effect") != -1) {
069: // If this is an effect attribute make sure Ice Extras is included
070: JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
071: getFacesContext());
072: }
073: super .setValueBinding(s, vb);
074: }
075:
076: /**
077: * <p>Set the value of the <code>effect</code> property.</p>
078: */
079: public void setEffect(Effect effect) {
080: this .effect = effect;
081: JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
082: getFacesContext());
083: }
084:
085: /**
086: * <p>Return the value of the <code>effect</code> property.</p>
087: */
088: public Effect getEffect() {
089: if (effect != null) {
090: return effect;
091: }
092: ValueBinding vb = getValueBinding("effect");
093: return vb != null ? (Effect) vb.getValue(getFacesContext())
094: : null;
095: }
096:
097: /**
098: * <p>Set the value of the <code>visible</code> property.</p>
099: */
100: public void setVisible(boolean visible) {
101: this .visible = Boolean.valueOf(visible);
102: }
103:
104: /**
105: * <p>Return the value of the <code>visible</code> property.</p>
106: */
107: public boolean getVisible() {
108: if (visible != null) {
109: return visible.booleanValue();
110: }
111: ValueBinding vb = getValueBinding("visible");
112: Boolean boolVal = vb != null ? (Boolean) vb
113: .getValue(getFacesContext()) : null;
114: return boolVal != null ? boolVal.booleanValue()
115: : DEFAULT_VISIBLE;
116: }
117:
118: /**
119: * <p>Set the value of the <code>styleClass</code> property.</p>
120: */
121: public void setStyleClass(String styleClass) {
122: this .styleClass = styleClass;
123: }
124:
125: /**
126: * <p>Return the value of the <code>styleClass</code> property.</p>
127: */
128: public String getStyleClass() {
129: return Util.getQualifiedStyleClass(this , styleClass,
130: CSS_DEFAULT.OUTPUT_LABEL_DEFAULT_STYLE_CLASS,
131: "styleClass");
132:
133: }
134:
135: /**
136: * <p>Set the value of the <code>renderedOnUserRole</code> property.</p>
137: */
138: public void setRenderedOnUserRole(String renderedOnUserRole) {
139: this .renderedOnUserRole = renderedOnUserRole;
140: }
141:
142: /**
143: * <p>Return the value of the <code>renderedOnUserRole</code> property.</p>
144: */
145: public String getRenderedOnUserRole() {
146: if (renderedOnUserRole != null) {
147: return renderedOnUserRole;
148: }
149: ValueBinding vb = getValueBinding("renderedOnUserRole");
150: return vb != null ? (String) vb.getValue(getFacesContext())
151: : 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 saveState(FacesContext context) {
183: Object values[] = new Object[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) (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 state) {
198: Object values[] = (Object[]) state;
199: super .restoreState(context, values[0]);
200: renderedOnUserRole = (String) values[1];
201: styleClass = (String) values[2];
202: effect = (Effect) values[3];
203: currentStyle = (CurrentStyle) values[4];
204: visible = (Boolean) values[5];
205: }
206: }
|