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.outputprogress;
035:
036: import com.icesoft.faces.component.CSS_DEFAULT;
037: import com.icesoft.faces.component.ext.taglib.Util;
038: import com.icesoft.faces.util.DOMUtils;
039:
040: import org.w3c.dom.Element;
041: import org.w3c.dom.Text;
042:
043: import javax.faces.component.UIComponentBase;
044: import javax.faces.context.FacesContext;
045: import javax.faces.el.ValueBinding;
046:
047: /**
048: * OutputProgress is a JSF component class repersenting the ICEfaces progress
049: * bar. This component can be used to output progress information to users when
050: * a long running server-side process is necessary. The component can be run in
051: * 2 modes; "determinate" and "indeterminate".
052: * <p/>
053: * OutputProgress extends the JSF UIComponentBase class.
054: * <p/>
055: * By default this component is rendered by the "com.icesoft.faces.Bar" renderer
056: * type.
057: */
058: public class OutputProgress extends UIComponentBase {
059:
060: private final String DEFAULT_LABEL_POSITION = "embed";
061:
062: private String label = null;
063:
064: private String labelPosition = null;
065:
066: private String labelComplete = null;
067:
068: private String styleClass = null;
069:
070: private boolean labelPositionChanged = false;
071:
072: private String style = null;
073:
074: private Integer value = null;
075:
076: private Boolean indeterminate = null;
077:
078: private String renderedOnUserRole;
079:
080: /*
081: * (non-Javadoc)
082: *
083: * @see javax.faces.component.UIComponent#getFamily()
084: */
085: public String getFamily() {
086: return "com.icesoft.faces.Progress";
087: }
088:
089: /*
090: * (non-Javadoc)
091: *
092: * @see javax.faces.component.UIComponent#getRendererType()
093: */
094: public String getRendererType() {
095: return "com.icesoft.faces.Bar";
096: }
097:
098: /**
099: * <p>
100: * Set the value of the <code>label</code> property. </p>
101: */
102: public void setLabel(String label) {
103: this .label = label;
104: }
105:
106: /**
107: * <p>
108: * Set the value of the <code>labelPosition</code> property. </p>
109: */
110: public void setLabelPosition(String labelPosition) {
111: this .labelPosition = labelPosition;
112: }
113:
114: /**
115: * <p>
116: * Set the value of the <code>labelComplete</code> property. </p>
117: */
118: public void setLabelComplete(String labelComplete) {
119: this .labelComplete = labelComplete;
120: }
121:
122: public String getStyle() {
123: if (style != null) {
124: return style;
125: }
126: ValueBinding vb = getValueBinding("style");
127: return vb != null ? (String) vb.getValue(getFacesContext())
128: : null;
129: }
130:
131: /**
132: * <p>
133: * Set the value of the <code>style</code> property. </p>
134: */
135: public void setStyle(String style) {
136: this .style = style;
137: }
138:
139: /**
140: * <p>
141: * Set the value of the <code>value</code> property. </p>
142: */
143: public void setValue(int value) {
144: this .value = new Integer(value);
145: }
146:
147: /**
148: * <p>
149: * Return the value of the <code>value</code> property. </p>
150: */
151: public int getValue() {
152: if (value != null) {
153: return value.intValue();
154: }
155: ValueBinding vb = getValueBinding("value");
156: return vb != null ? ((Integer) vb.getValue(getFacesContext()))
157: .intValue() : 0;
158: }
159:
160: /**
161: * <p>
162: * Return the value of the <code>label</code> property. </p>
163: */
164: public String getLabel() {
165: if (label != null) {
166: return label;
167: }
168: ValueBinding vb = getValueBinding("label");
169: return vb != null ? (String) vb.getValue(getFacesContext())
170: : null;
171: }
172:
173: public boolean getIndeterminate() {
174: if (indeterminate != null) {
175: return indeterminate.booleanValue();
176: }
177: ValueBinding vb = getValueBinding("indeterminate");
178: if (vb != null) {
179: return ((Boolean) vb.getValue(getFacesContext()))
180: .booleanValue();
181: }
182: return false;
183: }
184:
185: public void setIndeterminate(boolean b) {
186: indeterminate = new Boolean(b);
187: }
188:
189: /**
190: * <p>
191: * Return the value of the <code>progressLabel</code> property. </p>
192: */
193: public String getProgressLabel() {
194: if (getLabel() == null && getIndeterminate()) {
195: return "in progress...";
196: } else if (getLabel() != null) {
197: return DOMUtils.escapeAnsi(getLabel());
198: } else {
199: return getLabel();
200: }
201: }
202:
203: /**
204: * <p>
205: * Return the value of the <code>labelPosition</code> property. </p>
206: */
207: public String getLabelPosition() {
208: if (labelPosition != null) {
209: return labelPosition;
210: }
211: ValueBinding vb = getValueBinding("labelPosition");
212: return vb != null ? (String) vb.getValue(getFacesContext())
213: : DEFAULT_LABEL_POSITION;
214: }
215:
216: /**
217: * <p>
218: * Return the value of the <code>labelComplete</code> property. </p>
219: */
220: public String getLabelComplete() {
221: if (labelComplete != null) {
222: return labelComplete;
223: }
224: ValueBinding vb = getValueBinding("labelComplete");
225: return vb != null ? (String) vb.getValue(getFacesContext())
226: : null;
227: }
228:
229: /**
230: * <p>
231: * Return the value of the <code>progressLabelComplete</code> property.
232: * </p>
233: */
234: public String getProgressLabelComplete() {
235: if (getLabelComplete() == null && getIndeterminate()) {
236: return " ";
237: } else if (getLabelComplete() != null) {
238: return DOMUtils.escapeAnsi(getLabelComplete());
239: } else {
240: return getLabelComplete();
241: }
242: }
243:
244: /**
245: * <p>
246: * Set the value of the <code>styleClass</code> property. </p>
247: */
248: public void setStyleClass(String styleClass) {
249: this .styleClass = styleClass;
250: }
251:
252: /**
253: * <p>
254: * Return the value of the <code>styleClass</code> property. </p>
255: */
256: public String getStyleClass() {
257: return Util.getQualifiedStyleClass(this , styleClass,
258: CSS_DEFAULT.OUTPUT_PROGRESS_BASE_CLASS, "styleClass");
259: }
260:
261: public String getTextClass() {
262: return Util.getQualifiedStyleClass(this ,
263: CSS_DEFAULT.OUTPUT_PROGRESS_TEXT_STYLE_CLASS);
264: }
265:
266: public String getBackgroundClass() {
267: return Util.getQualifiedStyleClass(this ,
268: CSS_DEFAULT.OUTPUT_PROGRESS_BG_STYLE_CLASS);
269: }
270:
271: public String getFillClass() {
272: return Util.getQualifiedStyleClass(this ,
273: CSS_DEFAULT.OUTPUT_PROGRESS_FILL_STYLE_CLASS);
274: }
275:
276: public String getIndeterminateActiveClass() {
277: return Util.getQualifiedStyleClass(this ,
278: CSS_DEFAULT.OUTPUT_PROGRESS_INDETERMINATE_ACTIVE_CLASS);
279: }
280:
281: public String getIndeterminateInactiveClass() {
282: return Util
283: .getQualifiedStyleClass(
284: this ,
285: CSS_DEFAULT.OUTPUT_PROGRESS_INDETERMINATE_INACTIVE_CLASS);
286: }
287:
288: /**
289: * <p>
290: * Return the value of the <code>rendered</code> property. </p>
291: */
292: public boolean isRendered() {
293: if (!Util.isRenderedOnUserRole(this )) {
294: return false;
295: }
296: return super .isRendered();
297: }
298:
299: /**
300: * <p>
301: * Gets the state of the instance as a <code>Serializable</code> Object.
302: * </p>
303: */
304: public Object saveState(FacesContext context) {
305: Object values[] = new Object[8];
306: values[0] = super .saveState(context);
307: values[1] = label;
308: values[2] = labelPosition;
309: values[3] = labelComplete;
310: values[4] = new Boolean(labelPositionChanged);
311: values[5] = value;
312: values[6] = style;
313: values[7] = renderedOnUserRole;
314: return ((Object) (values));
315: }
316:
317: /**
318: * <p>
319: * Perform any processing required to restore the state from the entries in
320: * the state Object. </p>
321: */
322: public void restoreState(FacesContext context, Object state) {
323: Object values[] = (Object[]) state;
324: super .restoreState(context, values[0]);
325: label = (String) values[1];
326: labelPosition = (String) values[2];
327: labelComplete = (String) values[3];
328: labelPositionChanged = ((Boolean) values[4]).booleanValue();
329: value = (Integer) values[5];
330: style = (String) values[6];
331: renderedOnUserRole = (String) values[7];
332: }
333:
334: /**
335: * <p>Set the value of the <code>renderedOnUserRole</code> property.</p>
336: */
337: public void setRenderedOnUserRole(String renderedOnUserRole) {
338: this .renderedOnUserRole = renderedOnUserRole;
339: }
340:
341: /**
342: * <p>Return the value of the <code>renderedOnUserRole</code> property.</p>
343: */
344: public String getRenderedOnUserRole() {
345: if (renderedOnUserRole != null) {
346: return renderedOnUserRole;
347: }
348: ValueBinding vb = getValueBinding("renderedOnUserRole");
349: return vb != null ? (String) vb.getValue(getFacesContext())
350: : null;
351: }
352:
353: }
|