KickJava   Java API By Example, From Geeks To Geeks.

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


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  * This is an extension of javax.faces.component.html.HtmlSelectManyCheckbox,
49  * which provides some additional behavior to this component such as: <ul>
50  * <li>default classes for enabled and disabled state</li> <li>provides partial
51  * submit mechanism</li> <li>changes the component's enabled and rendered state
52  * based on the authentication</li> <li>adds effects to the component</li> <ul>
53  */

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

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

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

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

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

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

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

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

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

180     public String JavaDoc getEnabledOnUserRole() {
181         if (enabledOnUserRole != null) {
182             return enabledOnUserRole;
183         }
184         ValueBinding vb = getValueBinding("enabledOnUserRole");
185         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
186     }
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_MANY_CHECKBOX_DEFAULT_STYLE_CLASS,
221                 "styleClass",
222                 isDisabled());
223                                              
224     }
225
226     /**
227      * <p>Return the value of the <code>disabled</code> property.</p>
228      */

229     public boolean isDisabled() {
230         if (!Util.isEnabledOnUserRole(this)) {
231             return true;
232         } else {
233             return super.isDisabled();
234         }
235     }
236
237     /**
238      * <p>Return the value of the <code>rendered</code> property.</p>
239      */

240     public boolean isRendered() {
241         if (!Util.isRenderedOnUserRole(this)) {
242             return false;
243         }
244         return super.isRendered();
245     }
246
247     /**
248      * <p>Return the value of the <code>onclickeffect</code> property.</p>
249      */

250     public Effect getOnclickeffect() {
251         if (onclickeffect != null) {
252             return onclickeffect;
253         }
254         ValueBinding vb = getValueBinding("onclickeffect");
255
256         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
257     }
258
259     /**
260      * <p>Set the value of the <code>onclickeffect</code> property.</p>
261      */

262     public void setOnclickeffect(Effect onclickeffect) {
263         this.onclickeffect = onclickeffect;
264         JavascriptContext
265                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
266     }
267
268     /**
269      * <p>Return the value of the <code>ondblclickeffect</code> property.</p>
270      */

271     public Effect getOndblclickeffect() {
272         if (ondblclickeffect != null) {
273             return ondblclickeffect;
274         }
275         ValueBinding vb = getValueBinding("ondblclickeffect");
276
277         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
278     }
279
280     /**
281      * <p>Set the value of the <code>ondblclickeffect</code> property.</p>
282      */

283     public void setOndblclickeffect(Effect ondblclickeffect) {
284         this.ondblclickeffect = ondblclickeffect;
285         JavascriptContext
286                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
287     }
288
289     /**
290      * <p>Return the value of the <code>onmousedowneffect</code> property.</p>
291      */

292     public Effect getOnmousedowneffect() {
293         if (onmousedowneffect != null) {
294             return onmousedowneffect;
295         }
296         ValueBinding vb = getValueBinding("onmousedowneffect");
297
298         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
299     }
300
301     /**
302      * <p>Set the value of the <code>onmousedowneffect</code> property.</p>
303      */

304     public void setOnmousedowneffect(Effect onmousedowneffect) {
305         this.onmousedowneffect = onmousedowneffect;
306         JavascriptContext
307                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
308     }
309
310     /**
311      * <p>Return the value of the <code>onmouseupeffect</code> property.</p>
312      */

313     public Effect getOnmouseupeffect() {
314         if (onmouseupeffect != null) {
315             return onmouseupeffect;
316         }
317         ValueBinding vb = getValueBinding("onmouseupeffect");
318
319         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
320     }
321
322     /**
323      * <p>Set the value of the <code>onmouseupeffect</code> property.</p>
324      */

325     public void setOnmouseupeffect(Effect onmouseupeffect) {
326         this.onmouseupeffect = onmouseupeffect;
327         JavascriptContext
328                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
329     }
330
331     /**
332      * <p>Return the value of the <code>onmousemoveeffect</code> property.</p>
333      */

334     public Effect getOnmousemoveeffect() {
335         if (onmousemoveeffect != null) {
336             return onmousemoveeffect;
337         }
338         ValueBinding vb = getValueBinding("onmousemoveeffect");
339
340         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
341     }
342
343     /**
344      * <p>Set the value of the <code>onmousemoveeffect</code> property.</p>
345      */

346     public void setOnmousemoveeffect(Effect onmousemoveeffect) {
347         this.onmousemoveeffect = onmousemoveeffect;
348         JavascriptContext
349                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
350     }
351
352     /**
353      * <p>Return the value of the <code>onmouseovereffect</code> property.</p>
354      */

355     public Effect getOnmouseovereffect() {
356         if (onmouseovereffect != null) {
357             return onmouseovereffect;
358         }
359         ValueBinding vb = getValueBinding("onmouseovereffect");
360
361         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
362     }
363
364     /**
365      * <p>Set the value of the <code>onmouseovereffect</code> property.</p>
366      */

367     public void setOnmouseovereffect(Effect onmouseovereffect) {
368         this.onmouseovereffect = onmouseovereffect;
369         JavascriptContext
370                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
371     }
372
373     /**
374      * <p>Return the value of the <code>onmouseouteffect</code> property.</p>
375      */

376     public Effect getOnmouseouteffect() {
377         if (onmouseouteffect != null) {
378             return onmouseouteffect;
379         }
380         ValueBinding vb = getValueBinding("onmouseouteffect");
381
382         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
383     }
384
385     /**
386      * <p>Set the value of the <code>onmouseouteffect</code> property.</p>
387      */

388     public void setOnmouseouteffect(Effect onmouseouteffect) {
389         this.onmouseouteffect = onmouseouteffect;
390         JavascriptContext
391                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
392     }
393
394     /**
395      * <p>Return the value of the <code>onchangeeffect</code> property.</p>
396      */

397     public Effect getOnchangeeffect() {
398         if (onchangeeffect != null) {
399             return onchangeeffect;
400         }
401         ValueBinding vb = getValueBinding("onchangeeffect");
402
403         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
404     }
405
406     /**
407      * <p>Set the value of the <code>onchangeeffect</code> property.</p>
408      */

409     public void setOnchangeeffect(Effect onchangeeffect) {
410         this.onchangeeffect = onchangeeffect;
411         JavascriptContext
412                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
413     }
414
415
416     /**
417      * <p>Return the value of the <code>onkeypresseffect</code> property.</p>
418      */

419     public Effect getOnkeypresseffect() {
420         if (onkeypresseffect != null) {
421             return onkeypresseffect;
422         }
423         ValueBinding vb = getValueBinding("onkeypresseffect");
424
425         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
426     }
427
428     /**
429      * <p>Set the value of the <code>onkeypresseffect</code> property.</p>
430      */

431     public void setOnkeypresseffect(Effect onkeypresseffect) {
432         this.onkeypresseffect = onkeypresseffect;
433         JavascriptContext
434                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
435     }
436
437     /**
438      * <p>Return the value of the <code>onkeydowneffect</code> property.</p>
439      */

440     public Effect getOnkeydowneffect() {
441         if (onkeydowneffect != null) {
442             return onkeydowneffect;
443         }
444         ValueBinding vb = getValueBinding("onkeydowneffect");
445
446         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
447     }
448
449     /**
450      * <p>Set the value of the <code>onkeydowneffect</code> property.</p>
451      */

452     public void setOnkeydowneffect(Effect onkeydowneffect) {
453         this.onkeydowneffect = onkeydowneffect;
454         JavascriptContext
455                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
456     }
457
458     /**
459      * <p>Return the value of the <code>onkeyupeffect</code> property.</p>
460      */

461     public Effect getOnkeyupeffect() {
462         if (onkeyupeffect != null) {
463             return onkeyupeffect;
464         }
465         ValueBinding vb = getValueBinding("onkeyupeffect");
466
467         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
468     }
469
470     /**
471      * <p>Set the value of the <code>onkeyupeffect</code> property.</p>
472      */

473     public void setOnkeyupeffect(Effect onkeyupeffect) {
474         this.onkeyupeffect = onkeyupeffect;
475         JavascriptContext
476                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
477     }
478
479     /**
480      * <p>Return the value of the <code>currentStyle</code> property.</p>
481      */

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

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

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

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

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

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