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