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.IceExtended;
038: import com.icesoft.faces.component.ext.taglib.Util;
039: import com.icesoft.faces.context.BridgeFacesContext;
040: import com.icesoft.faces.context.effects.CurrentStyle;
041: import com.icesoft.faces.context.effects.Effect;
042: import com.icesoft.faces.context.effects.JavascriptContext;
043:
044: import javax.faces.context.FacesContext;
045: import javax.faces.el.ValueBinding;
046:
047: /**
048: * This is an extension of javax.faces.component.html.HtmlSelectBooleanCheckbox,
049: * which provides some additional behavior to this component such as: <ul>
050: * <li>default classes for enabled and disabled state</li> <li>provides partial
051: * submit mechanism</li> <li>changes the component's enabled and rendered state
052: * based on the authentication</li> <li>adds effects to the component</li> <ul>
053: */
054: public class HtmlSelectBooleanCheckbox extends
055: javax.faces.component.html.HtmlSelectBooleanCheckbox implements
056: IceExtended {
057:
058: public static final String COMPONENT_TYPE = "com.icesoft.faces.HtmlSelectBooleanCheckbox";
059: public static final String RENDERER_TYPE = "com.icesoft.faces.Checkbox";
060: private static final boolean DEFAULT_VISIBLE = true;
061: private String styleClass = null;
062: private Boolean partialSubmit = null;
063: private String enabledOnUserRole = null;
064: private String renderedOnUserRole = null;
065: private Effect effect;
066: private Boolean visible = null;
067:
068: private CurrentStyle currentStyle;
069:
070: private Effect onclickeffect;
071: private Effect ondblclickeffect;
072: private Effect onmousedowneffect;
073: private Effect onmouseupeffect;
074: private Effect onmousemoveeffect;
075: private Effect onmouseovereffect;
076: private Effect onmouseouteffect;
077: private Effect onchangeeffect;
078: private Effect onkeypresseffect;
079: private Effect onkeydowneffect;
080: private Effect onkeyupeffect;
081:
082: public HtmlSelectBooleanCheckbox() {
083: super ();
084: setRendererType(RENDERER_TYPE);
085: }
086:
087: /**
088: * This method is used to communicate a focus request from the application
089: * to the client browser.
090: */
091: public void requestFocus() {
092: ((BridgeFacesContext) FacesContext.getCurrentInstance())
093: .setFocusId("null");
094: JavascriptContext.focus(FacesContext.getCurrentInstance(), this
095: .getClientId(FacesContext.getCurrentInstance()));
096: }
097:
098: public void setValueBinding(String s, ValueBinding vb) {
099: if (s != null && s.indexOf("effect") != -1) {
100: // If this is an effect attribute make sure Ice Extras is included
101: JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
102: getFacesContext());
103: }
104: super .setValueBinding(s, vb);
105: }
106:
107: /**
108: * <p>Set the value of the <code>visible</code> property.</p>
109: */
110: public void setVisible(boolean visible) {
111: this .visible = Boolean.valueOf(visible);
112: }
113:
114: /**
115: * <p>Return the value of the <code>visible</code> property.</p>
116: */
117: public boolean getVisible() {
118: if (visible != null) {
119: return visible.booleanValue();
120: }
121: ValueBinding vb = getValueBinding("visible");
122: Boolean boolVal = vb != null ? (Boolean) vb
123: .getValue(getFacesContext()) : null;
124: return boolVal != null ? boolVal.booleanValue()
125: : DEFAULT_VISIBLE;
126: }
127:
128: /**
129: * <p>Set the value of the <code>effect</code> property.</p>
130: */
131: public void setEffect(Effect effect) {
132: this .effect = effect;
133: JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
134: getFacesContext());
135: }
136:
137: /**
138: * <p>Return the value of the <code>effect</code> property.</p>
139: */
140: public Effect getEffect() {
141: if (effect != null) {
142: return effect;
143: }
144: ValueBinding vb = getValueBinding("effect");
145: return vb != null ? (Effect) vb.getValue(getFacesContext())
146: : 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 boolVal = vb != null ? (Boolean) vb
165: .getValue(getFacesContext()) : null;
166: return boolVal != null ? boolVal.booleanValue() : Util
167: .isParentPartialSubmit(this );
168: }
169:
170: /**
171: * <p>Set the value of the <code>enabledOnUserRole</code> property.</p>
172: */
173: public void setEnabledOnUserRole(String enabledOnUserRole) {
174: this .enabledOnUserRole = enabledOnUserRole;
175: }
176:
177: /**
178: * <p>Return the value of the <code>enabledOnUserRole</code> property.</p>
179: */
180: public String getEnabledOnUserRole() {
181: if (enabledOnUserRole != null) {
182: return enabledOnUserRole;
183: }
184: ValueBinding vb = getValueBinding("enabledOnUserRole");
185: return vb != null ? (String) vb.getValue(getFacesContext())
186: : null;
187: }
188:
189: /**
190: * <p>Set the value of the <code>renderedOnUserRole</code> property.</p>
191: */
192: public void setRenderedOnUserRole(String renderedOnUserRole) {
193: this .renderedOnUserRole = renderedOnUserRole;
194: }
195:
196: /**
197: * <p>Return the value of the <code>renderedOnUserRole</code> property.</p>
198: */
199: public String getRenderedOnUserRole() {
200: if (renderedOnUserRole != null) {
201: return renderedOnUserRole;
202: }
203: ValueBinding vb = getValueBinding("renderedOnUserRole");
204: return vb != null ? (String) vb.getValue(getFacesContext())
205: : null;
206: }
207:
208: /**
209: * <p>Set the value of the <code>styleClass</code> property.</p>
210: */
211: public void setStyleClass(String styleClass) {
212: this .styleClass = styleClass;
213: }
214:
215: /**
216: * <p>Return the value of the <code>styleClass</code> property.</p>
217: */
218: public String getStyleClass() {
219: return Util
220: .getQualifiedStyleClass(
221: this ,
222: styleClass,
223: CSS_DEFAULT.SELECT_BOOLEAN_CHECKBOX_DEFAULT_STYLE_CLASS,
224: "styleClass", isDisabled());
225: }
226:
227: /**
228: * <p>Return the value of the <code>rendered</code> property.</p>
229: */
230: public boolean isRendered() {
231: if (!Util.isRenderedOnUserRole(this )) {
232: return false;
233: }
234: return super .isRendered();
235: }
236:
237: /**
238: * <p>Return the value of the <code>onclickeffect</code> property.</p>
239: */
240: public Effect getOnclickeffect() {
241: if (onclickeffect != null) {
242: return onclickeffect;
243: }
244: ValueBinding vb = getValueBinding("onclickeffect");
245:
246: return vb != null ? (Effect) vb.getValue(getFacesContext())
247: : null;
248: }
249:
250: /**
251: * <p>Set the value of the <code>onclickeffect</code> property.</p>
252: */
253: public void setOnclickeffect(Effect onclickeffect) {
254: this .onclickeffect = onclickeffect;
255: JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
256: getFacesContext());
257: }
258:
259: /**
260: * <p>Return the value of the <code>ondblclickeffect</code> property.</p>
261: */
262: public Effect getOndblclickeffect() {
263: if (ondblclickeffect != null) {
264: return ondblclickeffect;
265: }
266: ValueBinding vb = getValueBinding("ondblclickeffect");
267:
268: return vb != null ? (Effect) vb.getValue(getFacesContext())
269: : null;
270: }
271:
272: /**
273: * <p>Set the value of the <code>ondblclickeffect</code> property.</p>
274: */
275: public void setOndblclickeffect(Effect ondblclickeffect) {
276: this .ondblclickeffect = ondblclickeffect;
277: JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
278: getFacesContext());
279: }
280:
281: /**
282: * <p>Return the value of the <code>onmousedowneffect</code> property.</p>
283: */
284: public Effect getOnmousedowneffect() {
285: if (onmousedowneffect != null) {
286: return onmousedowneffect;
287: }
288: ValueBinding vb = getValueBinding("onmousedowneffect");
289:
290: return vb != null ? (Effect) vb.getValue(getFacesContext())
291: : null;
292: }
293:
294: /**
295: * <p>Set the value of the <code>onmousedowneffect</code> property.</p>
296: */
297: public void setOnmousedowneffect(Effect onmousedowneffect) {
298: this .onmousedowneffect = onmousedowneffect;
299: JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
300: getFacesContext());
301: }
302:
303: /**
304: * <p>Return the value of the <code>onmouseupeffect</code> property.</p>
305: */
306: public Effect getOnmouseupeffect() {
307: if (onmouseupeffect != null) {
308: return onmouseupeffect;
309: }
310: ValueBinding vb = getValueBinding("onmouseupeffect");
311:
312: return vb != null ? (Effect) vb.getValue(getFacesContext())
313: : null;
314: }
315:
316: /**
317: * <p>Set the value of the <code>onmouseupeffect</code> property.</p>
318: */
319: public void setOnmouseupeffect(Effect onmouseupeffect) {
320: this .onmouseupeffect = onmouseupeffect;
321: JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
322: getFacesContext());
323: }
324:
325: /**
326: * <p>Return the value of the <code>onmousemoveeffect</code> property.</p>
327: */
328: public Effect getOnmousemoveeffect() {
329: if (onmousemoveeffect != null) {
330: return onmousemoveeffect;
331: }
332: ValueBinding vb = getValueBinding("onmousemoveeffect");
333:
334: return vb != null ? (Effect) vb.getValue(getFacesContext())
335: : null;
336: }
337:
338: /**
339: * <p>Set the value of the <code>onmousemoveeffect</code> property.</p>
340: */
341: public void setOnmousemoveeffect(Effect onmousemoveeffect) {
342: this .onmousemoveeffect = onmousemoveeffect;
343: JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
344: getFacesContext());
345: }
346:
347: /**
348: * <p>Return the value of the <code>onmouseovereffect</code> property.</p>
349: */
350: public Effect getOnmouseovereffect() {
351: if (onmouseovereffect != null) {
352: return onmouseovereffect;
353: }
354: ValueBinding vb = getValueBinding("onmouseovereffect");
355:
356: return vb != null ? (Effect) vb.getValue(getFacesContext())
357: : null;
358: }
359:
360: /**
361: * <p>Set the value of the <code>onmouseovereffect</code> property.</p>
362: */
363: public void setOnmouseovereffect(Effect onmouseovereffect) {
364: this .onmouseovereffect = onmouseovereffect;
365: JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
366: getFacesContext());
367: }
368:
369: /**
370: * <p>Return the value of the <code>onmouseouteffect</code> property.</p>
371: */
372: public Effect getOnmouseouteffect() {
373: if (onmouseouteffect != null) {
374: return onmouseouteffect;
375: }
376: ValueBinding vb = getValueBinding("onmouseouteffect");
377:
378: return vb != null ? (Effect) vb.getValue(getFacesContext())
379: : null;
380: }
381:
382: /**
383: * <p>Set the value of the <code>onmouseouteffect</code> property.</p>
384: */
385: public void setOnmouseouteffect(Effect onmouseouteffect) {
386: this .onmouseouteffect = onmouseouteffect;
387: JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
388: getFacesContext());
389: }
390:
391: /**
392: * <p>Return the value of the <code>onchangeeffect</code> property.</p>
393: */
394: public Effect getOnchangeeffect() {
395: if (onchangeeffect != null) {
396: return onchangeeffect;
397: }
398: ValueBinding vb = getValueBinding("onchangeeffect");
399:
400: return vb != null ? (Effect) vb.getValue(getFacesContext())
401: : null;
402: }
403:
404: /**
405: * <p>Set the value of the <code>onchangeeffect</code> property.</p>
406: */
407: public void setOnchangeeffect(Effect onchangeeffect) {
408: this .onchangeeffect = onchangeeffect;
409: JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
410: getFacesContext());
411: }
412:
413: /**
414: * <p>Return the value of the <code>onkeypresseffect</code> property.</p>
415: */
416: public Effect getOnkeypresseffect() {
417: if (onkeypresseffect != null) {
418: return onkeypresseffect;
419: }
420: ValueBinding vb = getValueBinding("onkeypresseffect");
421:
422: return vb != null ? (Effect) vb.getValue(getFacesContext())
423: : null;
424: }
425:
426: /**
427: * <p>Set the value of the <code>onkeypresseffect</code> property.</p>
428: */
429: public void setOnkeypresseffect(Effect onkeypresseffect) {
430: this .onkeypresseffect = onkeypresseffect;
431: JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
432: getFacesContext());
433: }
434:
435: /**
436: * <p>Return the value of the <code>onkeydowneffect</code> property.</p>
437: */
438: public Effect getOnkeydowneffect() {
439: if (onkeydowneffect != null) {
440: return onkeydowneffect;
441: }
442: ValueBinding vb = getValueBinding("onkeydowneffect");
443:
444: return vb != null ? (Effect) vb.getValue(getFacesContext())
445: : null;
446: }
447:
448: /**
449: * <p>Set the value of the <code>onkeydowneffect</code> property.</p>
450: */
451: public void setOnkeydowneffect(Effect onkeydowneffect) {
452: this .onkeydowneffect = onkeydowneffect;
453: JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
454: getFacesContext());
455: }
456:
457: /**
458: * <p>Return the value of the <code>onkeyupeffect</code> property.</p>
459: */
460: public Effect getOnkeyupeffect() {
461: if (onkeyupeffect != null) {
462: return onkeyupeffect;
463: }
464: ValueBinding vb = getValueBinding("onkeyupeffect");
465:
466: return vb != null ? (Effect) vb.getValue(getFacesContext())
467: : 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.includeLib(JavascriptContext.ICE_EXTRAS,
476: getFacesContext());
477: }
478:
479: /**
480: * <p>Return the value of the <code>disabled</code> property.</p>
481: */
482: public boolean isDisabled() {
483: if (!Util.isEnabledOnUserRole(this )) {
484: return true;
485: } else {
486: return super .isDisabled();
487: }
488: }
489:
490: /**
491: * <p>Return the value of the <code>currentStyle</code> property.</p>
492: */
493: public CurrentStyle getCurrentStyle() {
494: return currentStyle;
495: }
496:
497: /**
498: * <p>Set the value of the <code>currentStyle</code> property.</p>
499: */
500: public void setCurrentStyle(CurrentStyle currentStyle) {
501: this .currentStyle = currentStyle;
502: }
503:
504: private String autocomplete;
505:
506: /**
507: * <p>Set the value of the <code>autocomplete</code> property.</p>
508: */
509: public void setAutocomplete(String autocomplete) {
510: this .autocomplete = autocomplete;
511: }
512:
513: /**
514: * <p>Return the value of the <code>autocomplete</code> property.</p>
515: */
516: public String getAutocomplete() {
517: if (autocomplete != null) {
518: return autocomplete;
519: }
520: ValueBinding vb = getValueBinding("autocomplete");
521: return vb != null ? (String) vb.getValue(getFacesContext())
522: : null;
523: }
524:
525: /**
526: * <p>Gets the state of the instance as a <code>Serializable</code>
527: * Object.</p>
528: */
529: public Object saveState(FacesContext context) {
530: Object values[] = new Object[23];
531: values[0] = super .saveState(context);
532: values[1] = partialSubmit;
533: values[2] = enabledOnUserRole;
534: values[3] = renderedOnUserRole;
535: values[4] = styleClass;
536: values[5] = effect;
537: values[7] = onclickeffect;
538: values[8] = ondblclickeffect;
539: values[9] = onmousedowneffect;
540: values[10] = onmouseupeffect;
541: values[11] = onmousemoveeffect;
542: values[12] = onmouseovereffect;
543: values[13] = onmouseouteffect;
544: values[14] = onchangeeffect;
545: values[17] = onkeypresseffect;
546: values[18] = onkeydowneffect;
547: values[19] = onkeyupeffect;
548: values[20] = currentStyle;
549: values[21] = visible;
550: values[22] = autocomplete;
551: return ((Object) (values));
552: }
553:
554: /**
555: * <p>Perform any processing required to restore the state from the entries
556: * in the state Object.</p>
557: */
558: public void restoreState(FacesContext context, Object state) {
559: Object values[] = (Object[]) state;
560: super .restoreState(context, values[0]);
561: partialSubmit = (Boolean) values[1];
562: enabledOnUserRole = (String) values[2];
563: renderedOnUserRole = (String) values[3];
564: styleClass = (String) values[4];
565: effect = (Effect) values[5];
566: onclickeffect = (Effect) values[7];
567: ondblclickeffect = (Effect) values[8];
568: onmousedowneffect = (Effect) values[9];
569: onmouseupeffect = (Effect) values[10];
570: onmousemoveeffect = (Effect) values[11];
571: onmouseovereffect = (Effect) values[12];
572: onmouseouteffect = (Effect) values[13];
573: onchangeeffect = (Effect) values[14];
574: onkeypresseffect = (Effect) values[17];
575: onkeydowneffect = (Effect) values[18];
576: onkeyupeffect = (Effect) values[19];
577: currentStyle = (CurrentStyle) values[20];
578: visible = (Boolean) values[21];
579: autocomplete = (String) values[22];
580: }
581: }
|