KickJava   Java API By Example, From Geeks To Geeks.

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


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.IceExtended;
38 import com.icesoft.faces.component.ext.taglib.Util;
39 import com.icesoft.faces.context.BridgeFacesContext;
40 import com.icesoft.faces.context.effects.CurrentStyle;
41 import com.icesoft.faces.context.effects.Effect;
42 import com.icesoft.faces.context.effects.JavascriptContext;
43
44 import javax.faces.context.FacesContext;
45 import javax.faces.el.ValueBinding;
46
47
48 /**
49  * This is an extension of javax.faces.component.html.HtmlSelectBooleanCheckbox,
50  * which provides some additional behavior to this component such as: <ul>
51  * <li>default classes for enabled and disabled state</li> <li>provides partial
52  * submit mechanism</li> <li>changes the component's enabled and rendered state
53  * based on the authentication</li> <li>adds effects to the component</li> <ul>
54  */

55 public class HtmlSelectBooleanCheckbox
56         extends javax.faces.component.html.HtmlSelectBooleanCheckbox
57         implements IceExtended {
58
59     public static final String JavaDoc COMPONENT_TYPE =
60             "com.icesoft.faces.HtmlSelectBooleanCheckbox";
61     public static final String JavaDoc RENDERER_TYPE = "com.icesoft.faces.Checkbox";
62     private static final boolean DEFAULT_VISIBLE = true;
63     private String JavaDoc styleClass = null;
64     private Boolean JavaDoc partialSubmit = null;
65     private String JavaDoc enabledOnUserRole = null;
66     private String JavaDoc renderedOnUserRole = null;
67     private Effect effect;
68     private Boolean JavaDoc visible = null;
69
70     private CurrentStyle currentStyle;
71
72     private Effect onclickeffect;
73     private Effect ondblclickeffect;
74     private Effect onmousedowneffect;
75     private Effect onmouseupeffect;
76     private Effect onmousemoveeffect;
77     private Effect onmouseovereffect;
78     private Effect onmouseouteffect;
79     private Effect onchangeeffect;
80     private Effect onkeypresseffect;
81     private Effect onkeydowneffect;
82     private Effect onkeyupeffect;
83
84     public HtmlSelectBooleanCheckbox() {
85         super();
86         setRendererType(RENDERER_TYPE);
87     }
88
89     /**
90      * This method is used to communicate a focus request from the application
91      * to the client browser.
92      */

93     public void requestFocus() {
94         ((BridgeFacesContext) FacesContext.getCurrentInstance())
95                 .setFocusId("null");
96         JavascriptContext.focus(FacesContext.getCurrentInstance(),
97                                 this.getClientId(
98                                         FacesContext.getCurrentInstance()));
99     }
100
101     public void setValueBinding(String JavaDoc s, ValueBinding vb) {
102         if (s != null && s.indexOf("effect") != -1) {
103             // If this is an effect attribute make sure Ice Extras is included
104
JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
105                                          getFacesContext());
106         }
107         super.setValueBinding(s, vb);
108     }
109
110     /**
111      * <p>Set the value of the <code>visible</code> property.</p>
112      */

113     public void setVisible(boolean visible) {
114         this.visible = Boolean.valueOf(visible);
115     }
116
117     /**
118      * <p>Return the value of the <code>visible</code> property.</p>
119      */

120     public boolean getVisible() {
121         if (visible != null) {
122             return visible.booleanValue();
123         }
124         ValueBinding vb = getValueBinding("visible");
125         Boolean JavaDoc boolVal =
126                 vb != null ? (Boolean JavaDoc) vb.getValue(getFacesContext()) : null;
127         return boolVal != null ? boolVal.booleanValue() : DEFAULT_VISIBLE;
128     }
129
130     /**
131      * <p>Set the value of the <code>effect</code> property.</p>
132      */

133     public void setEffect(Effect effect) {
134         this.effect = effect;
135         JavascriptContext
136                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
137     }
138
139     /**
140      * <p>Return the value of the <code>effect</code> property.</p>
141      */

142     public Effect getEffect() {
143         if (effect != null) {
144             return effect;
145         }
146         ValueBinding vb = getValueBinding("effect");
147         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
148     }
149
150     /**
151      * <p>Set the value of the <code>partialSubmit</code> property.</p>
152      */

153     public void setPartialSubmit(boolean partialSubmit) {
154         this.partialSubmit = Boolean.valueOf(partialSubmit);
155     }
156
157     /**
158      * <p>Return the value of the <code>partialSubmit</code> property.</p>
159      */

160     public boolean getPartialSubmit() {
161         if (partialSubmit != null) {
162             return partialSubmit.booleanValue();
163         }
164         ValueBinding vb = getValueBinding("partialSubmit");
165         Boolean JavaDoc boolVal =
166                 vb != null ? (Boolean JavaDoc) vb.getValue(getFacesContext()) : null;
167         return boolVal != null ? boolVal.booleanValue() :
168                Util.isParentPartialSubmit(this);
169     }
170
171     /**
172      * <p>Set the value of the <code>enabledOnUserRole</code> property.</p>
173      */

174     public void setEnabledOnUserRole(String JavaDoc enabledOnUserRole) {
175         this.enabledOnUserRole = enabledOnUserRole;
176     }
177
178     /**
179      * <p>Return the value of the <code>enabledOnUserRole</code> property.</p>
180      */

181     public String JavaDoc getEnabledOnUserRole() {
182         if (enabledOnUserRole != null) {
183             return enabledOnUserRole;
184         }
185         ValueBinding vb = getValueBinding("enabledOnUserRole");
186         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
187     }
188
189     /**
190      * <p>Set the value of the <code>renderedOnUserRole</code> property.</p>
191      */

192     public void setRenderedOnUserRole(String JavaDoc renderedOnUserRole) {
193         this.renderedOnUserRole = renderedOnUserRole;
194     }
195
196     /**
197      * <p>Return the value of the <code>renderedOnUserRole</code> property.</p>
198      */

199     public String JavaDoc getRenderedOnUserRole() {
200         if (renderedOnUserRole != null) {
201             return renderedOnUserRole;
202         }
203         ValueBinding vb = getValueBinding("renderedOnUserRole");
204         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
205     }
206
207     /**
208      * <p>Set the value of the <code>styleClass</code> property.</p>
209      */

210     public void setStyleClass(String JavaDoc styleClass) {
211         this.styleClass = styleClass;
212     }
213
214     /**
215      * <p>Return the value of the <code>styleClass</code> property.</p>
216      */

217     public String JavaDoc getStyleClass() {
218         return Util.getQualifiedStyleClass(this,
219                 styleClass,
220                 CSS_DEFAULT.SELECT_BOOLEAN_CHECKBOX_DEFAULT_STYLE_CLASS,
221                 "styleClass",
222                 isDisabled());
223     }
224
225     /**
226      * <p>Return the value of the <code>rendered</code> property.</p>
227      */

228     public boolean isRendered() {
229         if (!Util.isRenderedOnUserRole(this)) {
230             return false;
231         }
232         return super.isRendered();
233     }
234
235     /**
236      * <p>Return the value of the <code>onclickeffect</code> property.</p>
237      */

238     public Effect getOnclickeffect() {
239         if (onclickeffect != null) {
240             return onclickeffect;
241         }
242         ValueBinding vb = getValueBinding("onclickeffect");
243
244         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
245     }
246
247     /**
248      * <p>Set the value of the <code>onclickeffect</code> property.</p>
249      */

250     public void setOnclickeffect(Effect onclickeffect) {
251         this.onclickeffect = onclickeffect;
252         JavascriptContext
253                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
254     }
255
256     /**
257      * <p>Return the value of the <code>ondblclickeffect</code> property.</p>
258      */

259     public Effect getOndblclickeffect() {
260         if (ondblclickeffect != null) {
261             return ondblclickeffect;
262         }
263         ValueBinding vb = getValueBinding("ondblclickeffect");
264
265         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
266     }
267
268     /**
269      * <p>Set the value of the <code>ondblclickeffect</code> property.</p>
270      */

271     public void setOndblclickeffect(Effect ondblclickeffect) {
272         this.ondblclickeffect = ondblclickeffect;
273         JavascriptContext
274                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
275     }
276
277     /**
278      * <p>Return the value of the <code>onmousedowneffect</code> property.</p>
279      */

280     public Effect getOnmousedowneffect() {
281         if (onmousedowneffect != null) {
282             return onmousedowneffect;
283         }
284         ValueBinding vb = getValueBinding("onmousedowneffect");
285
286         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
287     }
288
289     /**
290      * <p>Set the value of the <code>onmousedowneffect</code> property.</p>
291      */

292     public void setOnmousedowneffect(Effect onmousedowneffect) {
293         this.onmousedowneffect = onmousedowneffect;
294         JavascriptContext
295                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
296     }
297
298     /**
299      * <p>Return the value of the <code>onmouseupeffect</code> property.</p>
300      */

301     public Effect getOnmouseupeffect() {
302         if (onmouseupeffect != null) {
303             return onmouseupeffect;
304         }
305         ValueBinding vb = getValueBinding("onmouseupeffect");
306
307         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
308     }
309
310     /**
311      * <p>Set the value of the <code>onmouseupeffect</code> property.</p>
312      */

313     public void setOnmouseupeffect(Effect onmouseupeffect) {
314         this.onmouseupeffect = onmouseupeffect;
315         JavascriptContext
316                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
317     }
318
319     /**
320      * <p>Return the value of the <code>onmousemoveeffect</code> property.</p>
321      */

322     public Effect getOnmousemoveeffect() {
323         if (onmousemoveeffect != null) {
324             return onmousemoveeffect;
325         }
326         ValueBinding vb = getValueBinding("onmousemoveeffect");
327
328         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
329     }
330
331     /**
332      * <p>Set the value of the <code>onmousemoveeffect</code> property.</p>
333      */

334     public void setOnmousemoveeffect(Effect onmousemoveeffect) {
335         this.onmousemoveeffect = onmousemoveeffect;
336         JavascriptContext
337                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
338     }
339
340     /**
341      * <p>Return the value of the <code>onmouseovereffect</code> property.</p>
342      */

343     public Effect getOnmouseovereffect() {
344         if (onmouseovereffect != null) {
345             return onmouseovereffect;
346         }
347         ValueBinding vb = getValueBinding("onmouseovereffect");
348
349         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
350     }
351
352     /**
353      * <p>Set the value of the <code>onmouseovereffect</code> property.</p>
354      */

355     public void setOnmouseovereffect(Effect onmouseovereffect) {
356         this.onmouseovereffect = onmouseovereffect;
357         JavascriptContext
358                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
359     }
360
361     /**
362      * <p>Return the value of the <code>onmouseouteffect</code> property.</p>
363      */

364     public Effect getOnmouseouteffect() {
365         if (onmouseouteffect != null) {
366             return onmouseouteffect;
367         }
368         ValueBinding vb = getValueBinding("onmouseouteffect");
369
370         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
371     }
372
373     /**
374      * <p>Set the value of the <code>onmouseouteffect</code> property.</p>
375      */

376     public void setOnmouseouteffect(Effect onmouseouteffect) {
377         this.onmouseouteffect = onmouseouteffect;
378         JavascriptContext
379                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
380     }
381
382     /**
383      * <p>Return the value of the <code>onchangeeffect</code> property.</p>
384      */

385     public Effect getOnchangeeffect() {
386         if (onchangeeffect != null) {
387             return onchangeeffect;
388         }
389         ValueBinding vb = getValueBinding("onchangeeffect");
390
391         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
392     }
393
394     /**
395      * <p>Set the value of the <code>onchangeeffect</code> property.</p>
396      */

397     public void setOnchangeeffect(Effect onchangeeffect) {
398         this.onchangeeffect = onchangeeffect;
399         JavascriptContext
400                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
401     }
402
403     /**
404      * <p>Return the value of the <code>onkeypresseffect</code> property.</p>
405      */

406     public Effect getOnkeypresseffect() {
407         if (onkeypresseffect != null) {
408             return onkeypresseffect;
409         }
410         ValueBinding vb = getValueBinding("onkeypresseffect");
411
412         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
413     }
414
415     /**
416      * <p>Set the value of the <code>onkeypresseffect</code> property.</p>
417      */

418     public void setOnkeypresseffect(Effect onkeypresseffect) {
419         this.onkeypresseffect = onkeypresseffect;
420         JavascriptContext
421                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
422     }
423
424     /**
425      * <p>Return the value of the <code>onkeydowneffect</code> property.</p>
426      */

427     public Effect getOnkeydowneffect() {
428         if (onkeydowneffect != null) {
429             return onkeydowneffect;
430         }
431         ValueBinding vb = getValueBinding("onkeydowneffect");
432
433         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
434     }
435
436     /**
437      * <p>Set the value of the <code>onkeydowneffect</code> property.</p>
438      */

439     public void setOnkeydowneffect(Effect onkeydowneffect) {
440         this.onkeydowneffect = onkeydowneffect;
441         JavascriptContext
442                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
443     }
444
445     /**
446      * <p>Return the value of the <code>onkeyupeffect</code> property.</p>
447      */

448     public Effect getOnkeyupeffect() {
449         if (onkeyupeffect != null) {
450             return onkeyupeffect;
451         }
452         ValueBinding vb = getValueBinding("onkeyupeffect");
453
454         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
455     }
456
457     /**
458      * <p>Set the value of the <code>onkeyupeffect</code> property.</p>
459      */

460     public void setOnkeyupeffect(Effect onkeyupeffect) {
461         this.onkeyupeffect = onkeyupeffect;
462         JavascriptContext
463                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
464     }
465
466     /**
467      * <p>Return the value of the <code>disabled</code> property.</p>
468      */

469     public boolean isDisabled() {
470         if (!Util.isEnabledOnUserRole(this)) {
471             return true;
472         } else {
473             return super.isDisabled();
474         }
475     }
476
477     /**
478      * <p>Return the value of the <code>currentStyle</code> property.</p>
479      */

480     public CurrentStyle getCurrentStyle() {
481         return currentStyle;
482     }
483
484     /**
485      * <p>Set the value of the <code>currentStyle</code> property.</p>
486      */

487     public void setCurrentStyle(CurrentStyle currentStyle) {
488         this.currentStyle = currentStyle;
489     }
490
491     private String JavaDoc autocomplete;
492
493     /**
494      * <p>Set the value of the <code>autocomplete</code> property.</p>
495      */

496     public void setAutocomplete(String JavaDoc autocomplete) {
497         this.autocomplete = autocomplete;
498     }
499
500     /**
501      * <p>Return the value of the <code>autocomplete</code> property.</p>
502      */

503     public String JavaDoc getAutocomplete() {
504         if (autocomplete != null) {
505             return autocomplete;
506         }
507         ValueBinding vb = getValueBinding("autocomplete");
508         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
509     }
510
511     /**
512      * <p>Gets the state of the instance as a <code>Serializable</code>
513      * Object.</p>
514      */

515     public Object JavaDoc saveState(FacesContext context) {
516         Object JavaDoc values[] = new Object JavaDoc[23];
517         values[0] = super.saveState(context);
518         values[1] = partialSubmit;
519         values[2] = enabledOnUserRole;
520         values[3] = renderedOnUserRole;
521         values[4] = styleClass;
522         values[5] = effect;
523         values[7] = onclickeffect;
524         values[8] = ondblclickeffect;
525         values[9] = onmousedowneffect;
526         values[10] = onmouseupeffect;
527         values[11] = onmousemoveeffect;
528         values[12] = onmouseovereffect;
529         values[13] = onmouseouteffect;
530         values[14] = onchangeeffect;
531         values[17] = onkeypresseffect;
532         values[18] = onkeydowneffect;
533         values[19] = onkeyupeffect;
534         values[20] = currentStyle;
535         values[21] = visible;
536         values[22] = autocomplete;
537         return ((Object JavaDoc) (values));
538     }
539
540     /**
541      * <p>Perform any processing required to restore the state from the entries
542      * in the state Object.</p>
543      */

544     public void restoreState(FacesContext context, Object JavaDoc state) {
545         Object JavaDoc values[] = (Object JavaDoc[]) state;
546         super.restoreState(context, values[0]);
547         partialSubmit = (Boolean JavaDoc) values[1];
548         enabledOnUserRole = (String JavaDoc) values[2];
549         renderedOnUserRole = (String JavaDoc) values[3];
550         styleClass = (String JavaDoc) values[4];
551         effect = (Effect) values[5];
552         onclickeffect = (Effect) values[7];
553         ondblclickeffect = (Effect) values[8];
554         onmousedowneffect = (Effect) values[9];
555         onmouseupeffect = (Effect) values[10];
556         onmousemoveeffect = (Effect) values[11];
557         onmouseovereffect = (Effect) values[12];
558         onmouseouteffect = (Effect) values[13];
559         onchangeeffect = (Effect) values[14];
560         onkeypresseffect = (Effect) values[17];
561         onkeydowneffect = (Effect) values[18];
562         onkeyupeffect = (Effect) values[19];
563         currentStyle = (CurrentStyle) values[20];
564         visible = (Boolean JavaDoc) values[21];
565         autocomplete = (String JavaDoc) values[22];
566     }
567 }
568
569
570
Popular Tags