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