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