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.HtmlSelectManyCheckbox,
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 HtmlSelectManyCheckbox extends
055: javax.faces.component.html.HtmlSelectManyCheckbox implements
056: IceExtended {
057:
058: public static final String COMPONENT_TYPE = "com.icesoft.faces.HtmlSelectManyCheckbox";
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 HtmlSelectManyCheckbox() {
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.getQualifiedStyleClass(this , styleClass,
220: CSS_DEFAULT.SELECT_MANY_CHECKBOX_DEFAULT_STYLE_CLASS,
221: "styleClass", isDisabled());
222:
223: }
224:
225: /**
226: * <p>Return the value of the <code>disabled</code> property.</p>
227: */
228: public boolean isDisabled() {
229: if (!Util.isEnabledOnUserRole(this )) {
230: return true;
231: } else {
232: return super .isDisabled();
233: }
234: }
235:
236: /**
237: * <p>Return the value of the <code>rendered</code> property.</p>
238: */
239: public boolean isRendered() {
240: if (!Util.isRenderedOnUserRole(this )) {
241: return false;
242: }
243: return super .isRendered();
244: }
245:
246: /**
247: * <p>Return the value of the <code>onclickeffect</code> property.</p>
248: */
249: public Effect getOnclickeffect() {
250: if (onclickeffect != null) {
251: return onclickeffect;
252: }
253: ValueBinding vb = getValueBinding("onclickeffect");
254:
255: return vb != null ? (Effect) vb.getValue(getFacesContext())
256: : 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.includeLib(JavascriptContext.ICE_EXTRAS,
265: 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())
278: : null;
279: }
280:
281: /**
282: * <p>Set the value of the <code>ondblclickeffect</code> property.</p>
283: */
284: public void setOndblclickeffect(Effect ondblclickeffect) {
285: this .ondblclickeffect = ondblclickeffect;
286: JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
287: getFacesContext());
288: }
289:
290: /**
291: * <p>Return the value of the <code>onmousedowneffect</code> property.</p>
292: */
293: public Effect getOnmousedowneffect() {
294: if (onmousedowneffect != null) {
295: return onmousedowneffect;
296: }
297: ValueBinding vb = getValueBinding("onmousedowneffect");
298:
299: return vb != null ? (Effect) vb.getValue(getFacesContext())
300: : null;
301: }
302:
303: /**
304: * <p>Set the value of the <code>onmousedowneffect</code> property.</p>
305: */
306: public void setOnmousedowneffect(Effect onmousedowneffect) {
307: this .onmousedowneffect = onmousedowneffect;
308: JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
309: getFacesContext());
310: }
311:
312: /**
313: * <p>Return the value of the <code>onmouseupeffect</code> property.</p>
314: */
315: public Effect getOnmouseupeffect() {
316: if (onmouseupeffect != null) {
317: return onmouseupeffect;
318: }
319: ValueBinding vb = getValueBinding("onmouseupeffect");
320:
321: return vb != null ? (Effect) vb.getValue(getFacesContext())
322: : null;
323: }
324:
325: /**
326: * <p>Set the value of the <code>onmouseupeffect</code> property.</p>
327: */
328: public void setOnmouseupeffect(Effect onmouseupeffect) {
329: this .onmouseupeffect = onmouseupeffect;
330: JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
331: getFacesContext());
332: }
333:
334: /**
335: * <p>Return the value of the <code>onmousemoveeffect</code> property.</p>
336: */
337: public Effect getOnmousemoveeffect() {
338: if (onmousemoveeffect != null) {
339: return onmousemoveeffect;
340: }
341: ValueBinding vb = getValueBinding("onmousemoveeffect");
342:
343: return vb != null ? (Effect) vb.getValue(getFacesContext())
344: : null;
345: }
346:
347: /**
348: * <p>Set the value of the <code>onmousemoveeffect</code> property.</p>
349: */
350: public void setOnmousemoveeffect(Effect onmousemoveeffect) {
351: this .onmousemoveeffect = onmousemoveeffect;
352: JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
353: getFacesContext());
354: }
355:
356: /**
357: * <p>Return the value of the <code>onmouseovereffect</code> property.</p>
358: */
359: public Effect getOnmouseovereffect() {
360: if (onmouseovereffect != null) {
361: return onmouseovereffect;
362: }
363: ValueBinding vb = getValueBinding("onmouseovereffect");
364:
365: return vb != null ? (Effect) vb.getValue(getFacesContext())
366: : null;
367: }
368:
369: /**
370: * <p>Set the value of the <code>onmouseovereffect</code> property.</p>
371: */
372: public void setOnmouseovereffect(Effect onmouseovereffect) {
373: this .onmouseovereffect = onmouseovereffect;
374: JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
375: getFacesContext());
376: }
377:
378: /**
379: * <p>Return the value of the <code>onmouseouteffect</code> property.</p>
380: */
381: public Effect getOnmouseouteffect() {
382: if (onmouseouteffect != null) {
383: return onmouseouteffect;
384: }
385: ValueBinding vb = getValueBinding("onmouseouteffect");
386:
387: return vb != null ? (Effect) vb.getValue(getFacesContext())
388: : null;
389: }
390:
391: /**
392: * <p>Set the value of the <code>onmouseouteffect</code> property.</p>
393: */
394: public void setOnmouseouteffect(Effect onmouseouteffect) {
395: this .onmouseouteffect = onmouseouteffect;
396: JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
397: getFacesContext());
398: }
399:
400: /**
401: * <p>Return the value of the <code>onchangeeffect</code> property.</p>
402: */
403: public Effect getOnchangeeffect() {
404: if (onchangeeffect != null) {
405: return onchangeeffect;
406: }
407: ValueBinding vb = getValueBinding("onchangeeffect");
408:
409: return vb != null ? (Effect) vb.getValue(getFacesContext())
410: : null;
411: }
412:
413: /**
414: * <p>Set the value of the <code>onchangeeffect</code> property.</p>
415: */
416: public void setOnchangeeffect(Effect onchangeeffect) {
417: this .onchangeeffect = onchangeeffect;
418: JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
419: getFacesContext());
420: }
421:
422: /**
423: * <p>Return the value of the <code>onkeypresseffect</code> property.</p>
424: */
425: public Effect getOnkeypresseffect() {
426: if (onkeypresseffect != null) {
427: return onkeypresseffect;
428: }
429: ValueBinding vb = getValueBinding("onkeypresseffect");
430:
431: return vb != null ? (Effect) vb.getValue(getFacesContext())
432: : null;
433: }
434:
435: /**
436: * <p>Set the value of the <code>onkeypresseffect</code> property.</p>
437: */
438: public void setOnkeypresseffect(Effect onkeypresseffect) {
439: this .onkeypresseffect = onkeypresseffect;
440: JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
441: getFacesContext());
442: }
443:
444: /**
445: * <p>Return the value of the <code>onkeydowneffect</code> property.</p>
446: */
447: public Effect getOnkeydowneffect() {
448: if (onkeydowneffect != null) {
449: return onkeydowneffect;
450: }
451: ValueBinding vb = getValueBinding("onkeydowneffect");
452:
453: return vb != null ? (Effect) vb.getValue(getFacesContext())
454: : null;
455: }
456:
457: /**
458: * <p>Set the value of the <code>onkeydowneffect</code> property.</p>
459: */
460: public void setOnkeydowneffect(Effect onkeydowneffect) {
461: this .onkeydowneffect = onkeydowneffect;
462: JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
463: getFacesContext());
464: }
465:
466: /**
467: * <p>Return the value of the <code>onkeyupeffect</code> property.</p>
468: */
469: public Effect getOnkeyupeffect() {
470: if (onkeyupeffect != null) {
471: return onkeyupeffect;
472: }
473: ValueBinding vb = getValueBinding("onkeyupeffect");
474:
475: return vb != null ? (Effect) vb.getValue(getFacesContext())
476: : null;
477: }
478:
479: /**
480: * <p>Set the value of the <code>onkeyupeffect</code> property.</p>
481: */
482: public void setOnkeyupeffect(Effect onkeyupeffect) {
483: this .onkeyupeffect = onkeyupeffect;
484: JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
485: getFacesContext());
486: }
487:
488: /**
489: * <p>Return the value of the <code>currentStyle</code> property.</p>
490: */
491: public CurrentStyle getCurrentStyle() {
492: return currentStyle;
493: }
494:
495: /**
496: * <p>Set the value of the <code>currentStyle</code> property.</p>
497: */
498: public void setCurrentStyle(CurrentStyle currentStyle) {
499: this .currentStyle = currentStyle;
500: }
501:
502: private String autocomplete;
503:
504: /**
505: * <p>Set the value of the <code>autocomplete</code> property.</p>
506: */
507: public void setAutocomplete(String autocomplete) {
508: this .autocomplete = autocomplete;
509: }
510:
511: /**
512: * <p>Return the value of the <code>autocomplete</code> property.</p>
513: */
514: public String getAutocomplete() {
515: if (autocomplete != null) {
516: return autocomplete;
517: }
518: ValueBinding vb = getValueBinding("autocomplete");
519: return vb != null ? (String) vb.getValue(getFacesContext())
520: : null;
521: }
522:
523: /**
524: * <p>Gets the state of the instance as a <code>Serializable</code>
525: * Object.</p>
526: */
527: public Object saveState(FacesContext context) {
528: Object values[] = new Object[23];
529: values[0] = super .saveState(context);
530: values[1] = partialSubmit;
531: values[2] = enabledOnUserRole;
532: values[3] = renderedOnUserRole;
533: values[4] = styleClass;
534: values[5] = effect;
535: values[7] = onclickeffect;
536: values[8] = ondblclickeffect;
537: values[9] = onmousedowneffect;
538: values[10] = onmouseupeffect;
539: values[11] = onmousemoveeffect;
540: values[12] = onmouseovereffect;
541: values[13] = onmouseouteffect;
542: values[14] = onchangeeffect;
543: values[17] = onkeypresseffect;
544: values[18] = onkeydowneffect;
545: values[19] = onkeyupeffect;
546: values[20] = currentStyle;
547: values[21] = visible;
548: values[22] = autocomplete;
549: return ((Object) (values));
550: }
551:
552: /**
553: * <p>Perform any processing required to restore the state from the entries
554: * in the state Object.</p>
555: */
556: public void restoreState(FacesContext context, Object state) {
557: Object values[] = (Object[]) state;
558: super .restoreState(context, values[0]);
559: partialSubmit = (Boolean) values[1];
560: enabledOnUserRole = (String) values[2];
561: renderedOnUserRole = (String) values[3];
562: styleClass = (String) values[4];
563: effect = (Effect) values[5];
564: onclickeffect = (Effect) values[7];
565: ondblclickeffect = (Effect) values[8];
566: onmousedowneffect = (Effect) values[9];
567: onmouseupeffect = (Effect) values[10];
568: onmousemoveeffect = (Effect) values[11];
569: onmouseovereffect = (Effect) values[12];
570: onmouseouteffect = (Effect) values[13];
571: onchangeeffect = (Effect) values[14];
572: onkeypresseffect = (Effect) values[17];
573: onkeydowneffect = (Effect) values[18];
574: onkeyupeffect = (Effect) values[19];
575: currentStyle = (CurrentStyle) values[20];
576: visible = (Boolean) values[21];
577: autocomplete = (String) values[22];
578: }
579: }
|