KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > icesoft > faces > component > outputprogress > OutputProgress


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.outputprogress;
35
36 import com.icesoft.faces.component.CSS_DEFAULT;
37 import com.icesoft.faces.component.ext.taglib.Util;
38 import com.icesoft.faces.util.DOMUtils;
39
40 import org.w3c.dom.Element JavaDoc;
41 import org.w3c.dom.Text JavaDoc;
42
43 import javax.faces.component.UIComponentBase;
44 import javax.faces.context.FacesContext;
45 import javax.faces.el.ValueBinding;
46
47 /**
48  * OutputProgress is a JSF component class repersenting the ICEfaces progress
49  * bar. This component can be used to output progress information to users when
50  * a long running server-side process is necessary. The component can be run in
51  * 2 modes; "determinate" and "indeterminate".
52  * <p/>
53  * OutputProgress extends the JSF UIComponentBase class.
54  * <p/>
55  * By default this component is rendered by the "com.icesoft.faces.Bar" renderer
56  * type.
57  */

58 public class OutputProgress extends UIComponentBase {
59
60     private final String JavaDoc DEFAULT_LABEL_POSITION = "embed";
61
62     private String JavaDoc label = null;
63
64     private String JavaDoc labelPosition = null;
65
66     private String JavaDoc labelComplete = null;
67
68     private String JavaDoc styleClass = null;
69
70     private boolean labelPositionChanged = false;
71
72     private String JavaDoc style = null;
73
74     private Integer JavaDoc value = null;
75
76     private Text JavaDoc textNode = null;
77
78     private Element JavaDoc barNode = null;
79
80     private Boolean JavaDoc indeterminate = null;
81
82     private String JavaDoc renderedOnUserRole;
83
84     /*
85       * (non-Javadoc)
86       *
87       * @see javax.faces.component.UIComponent#getFamily()
88       */

89     public String JavaDoc getFamily() {
90         return "com.icesoft.faces.Progress";
91     }
92
93     /*
94       * (non-Javadoc)
95       *
96       * @see javax.faces.component.UIComponent#getRendererType()
97       */

98     public String JavaDoc getRendererType() {
99         return "com.icesoft.faces.Bar";
100     }
101
102     /**
103      * <p>
104      * Set the value of the <code>textNode</code> property. </p>
105      */

106     public void setTextNode(Text JavaDoc textNode) {
107         this.textNode = textNode;
108     }
109
110     /**
111      * <p>
112      * Return the value of the <code>textNode</code> property. </p>
113      */

114     public Text JavaDoc getTextNode() {
115         return textNode;
116     }
117
118     /**
119      * <p>
120      * Set the value of the <code>barNode</code> property. </p>
121      */

122     public void setBarNode(Element JavaDoc barNode) {
123         this.barNode = barNode;
124     }
125
126     /**
127      * <p>
128      * Return the value of the <code>barNode</code> property. </p>
129      */

130     public Element JavaDoc getBarNode() {
131         return barNode;
132     }
133
134     /**
135      * <p>
136      * Set the value of the <code>label</code> property. </p>
137      */

138     public void setLabel(String JavaDoc label) {
139         this.label = label;
140     }
141
142     /**
143      * <p>
144      * Set the value of the <code>labelPosition</code> property. </p>
145      */

146     public void setLabelPosition(String JavaDoc labelPosition) {
147         this.labelPosition = labelPosition;
148     }
149
150     /**
151      * <p>
152      * Set the value of the <code>labelComplete</code> property. </p>
153      */

154     public void setLabelComplete(String JavaDoc labelComplete) {
155         this.labelComplete = labelComplete;
156     }
157
158     public String JavaDoc getStyle() {
159         if (style != null) {
160             return style;
161         }
162         ValueBinding vb = getValueBinding("style");
163         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
164     }
165
166     /**
167      * <p>
168      * Set the value of the <code>style</code> property. </p>
169      */

170     public void setStyle(String JavaDoc style) {
171         this.style = style;
172     }
173
174     /**
175      * <p>
176      * Set the value of the <code>value</code> property. </p>
177      */

178     public void setValue(int value) {
179         this.value = new Integer JavaDoc(value);
180     }
181
182     /**
183      * <p>
184      * Return the value of the <code>value</code> property. </p>
185      */

186     public int getValue() {
187         if (value != null) {
188             return value.intValue();
189         }
190         ValueBinding vb = getValueBinding("value");
191         return vb != null ? ((Integer JavaDoc) vb.getValue(getFacesContext()))
192                 .intValue() : 0;
193     }
194
195     /**
196      * <p>
197      * Return the value of the <code>label</code> property. </p>
198      */

199     public String JavaDoc getLabel() {
200         if (label != null) {
201             return label;
202         }
203         ValueBinding vb = getValueBinding("label");
204         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
205     }
206
207     public boolean getIndeterminate() {
208         if (indeterminate != null) {
209             return indeterminate.booleanValue();
210         }
211         ValueBinding vb = getValueBinding("indeterminate");
212         if (vb != null) {
213             return ((Boolean JavaDoc) vb.getValue(getFacesContext())).booleanValue();
214         }
215         return false;
216     }
217
218     public void setIndeterminate(boolean b) {
219         indeterminate = new Boolean JavaDoc(b);
220     }
221
222     /**
223      * <p>
224      * Return the value of the <code>progressLabel</code> property. </p>
225      */

226     public String JavaDoc getProgressLabel() {
227         if (getLabel() == null && getIndeterminate()) {
228             return "in progress...";
229         } else if (getLabel() != null){
230             return DOMUtils.escapeAnsi(getLabel());
231         } else {
232             return getLabel();
233         }
234     }
235
236     /**
237      * <p>
238      * Return the value of the <code>labelPosition</code> property. </p>
239      */

240     public String JavaDoc getLabelPosition() {
241         if (labelPosition != null) {
242             return labelPosition;
243         }
244         ValueBinding vb = getValueBinding("labelPosition");
245         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext())
246                : DEFAULT_LABEL_POSITION;
247     }
248
249     /**
250      * <p>
251      * Return the value of the <code>labelComplete</code> property. </p>
252      */

253     public String JavaDoc getLabelComplete() {
254         if (labelComplete != null) {
255             return labelComplete;
256         }
257         ValueBinding vb = getValueBinding("labelComplete");
258         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
259     }
260
261     /**
262      * <p>
263      * Return the value of the <code>progressLabelComplete</code> property.
264      * </p>
265      */

266     public String JavaDoc getProgressLabelComplete() {
267         if (getLabelComplete() == null && getIndeterminate()) {
268             return "&nbsp;";
269         } else if (getLabelComplete() != null) {
270             return DOMUtils.escapeAnsi(getLabelComplete());
271         } else {
272             return getLabelComplete();
273         }
274     }
275
276     /**
277      * <p>
278      * Set the value of the <code>styleClass</code> property. </p>
279      */

280     public void setStyleClass(String JavaDoc styleClass) {
281         this.styleClass = styleClass;
282     }
283
284     /**
285      * <p>
286      * Return the value of the <code>styleClass</code> property. </p>
287      */

288     public String JavaDoc getStyleClass() {
289         return Util.getQualifiedStyleClass(this,
290                     styleClass,
291                     CSS_DEFAULT.OUTPUT_PROGRESS_BASE_CLASS,
292                     "styleClass");
293     }
294     
295     public String JavaDoc getTextClass() {
296         return Util.getQualifiedStyleClass(this,
297                 CSS_DEFAULT.OUTPUT_PROGRESS_TEXT_STYLE_CLASS);
298     }
299
300     public String JavaDoc getBackgroundClass() {
301         return Util.getQualifiedStyleClass(this,
302                 CSS_DEFAULT.OUTPUT_PROGRESS_BG_STYLE_CLASS);
303     }
304     
305     public String JavaDoc getFillClass() {
306         return Util.getQualifiedStyleClass(this,
307                 CSS_DEFAULT.OUTPUT_PROGRESS_FILL_STYLE_CLASS);
308     }
309     
310     public String JavaDoc getIndeterminateActiveClass() {
311         return Util.getQualifiedStyleClass(this,
312                 CSS_DEFAULT.OUTPUT_PROGRESS_INDETERMINATE_ACTIVE_CLASS);
313     }
314     
315     public String JavaDoc getIndeterminateInactiveClass() {
316         return Util.getQualifiedStyleClass(this,
317                 CSS_DEFAULT.OUTPUT_PROGRESS_INDETERMINATE_INACTIVE_CLASS);
318     }
319     /**
320      * <p>
321      * Return the value of the <code>rendered</code> property. </p>
322      */

323     public boolean isRendered() {
324         if (!Util.isRenderedOnUserRole(this)) {
325             return false;
326         }
327         return super.isRendered();
328     }
329
330     /**
331      * <p>
332      * Gets the state of the instance as a <code>Serializable</code> Object.
333      * </p>
334      */

335     public Object JavaDoc saveState(FacesContext context) {
336         Object JavaDoc values[] = new Object JavaDoc[10];
337         values[0] = super.saveState(context);
338         values[1] = label;
339         values[2] = labelPosition;
340         values[3] = labelComplete;
341         values[4] = new Boolean JavaDoc(labelPositionChanged);
342         values[5] = value;
343         values[6] = textNode;
344         values[7] = barNode;
345         values[8] = style;
346         values[9] = renderedOnUserRole;
347         return ((Object JavaDoc) (values));
348     }
349
350     /**
351      * <p>
352      * Perform any processing required to restore the state from the entries in
353      * the state Object. </p>
354      */

355     public void restoreState(FacesContext context, Object JavaDoc state) {
356         Object JavaDoc values[] = (Object JavaDoc[]) state;
357         super.restoreState(context, values[0]);
358         label = (String JavaDoc) values[1];
359         labelPosition = (String JavaDoc) values[2];
360         labelComplete = (String JavaDoc) values[3];
361         labelPositionChanged = ((Boolean JavaDoc) values[4]).booleanValue();
362         value = (Integer JavaDoc) values[5];
363         textNode = (Text JavaDoc) values[6];
364         barNode = (Element JavaDoc) values[7];
365         style = (String JavaDoc) values[8];
366         renderedOnUserRole = (String JavaDoc) values[9];
367     }
368
369     /**
370      * <p>Set the value of the <code>renderedOnUserRole</code> property.</p>
371      */

372     public void setRenderedOnUserRole(String JavaDoc renderedOnUserRole) {
373         this.renderedOnUserRole = renderedOnUserRole;
374     }
375
376     /**
377      * <p>Return the value of the <code>renderedOnUserRole</code> property.</p>
378      */

379     public String JavaDoc getRenderedOnUserRole() {
380         if (renderedOnUserRole != null) {
381             return renderedOnUserRole;
382         }
383         ValueBinding vb = getValueBinding("renderedOnUserRole");
384         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
385     }
386
387 }
388
Popular Tags