KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > icesoft > faces > component > ext > HtmlOutputLink


1 /*
2  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3  *
4  * "The contents of this file are subject to the Mozilla Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License at
7  * http://www.mozilla.org/MPL/
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
11  * License for the specific language governing rights and limitations under
12  * the License.
13  *
14  * The Original Code is ICEfaces 1.5 open source software code, released
15  * November 5, 2006. The Initial Developer of the Original Code is ICEsoft
16  * Technologies Canada, Corp. Portions created by ICEsoft are Copyright (C)
17  * 2004-2006 ICEsoft Technologies Canada, Corp. All Rights Reserved.
18  *
19  * Contributor(s): _____________________.
20  *
21  * Alternatively, the contents of this file may be used under the terms of
22  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"
23  * License), in which case the provisions of the LGPL License are
24  * applicable instead of those above. If you wish to allow use of your
25  * version of this file only under the terms of the LGPL License and not to
26  * allow others to use your version of this file under the MPL, indicate
27  * your decision by deleting the provisions above and replace them with
28  * the notice and other provisions required by the LGPL License. If you do
29  * not delete the provisions above, a recipient may use your version of
30  * this file under either the MPL or the LGPL License."
31  *
32  */

33
34 package com.icesoft.faces.component.ext;
35
36 import com.icesoft.faces.component.CSS_DEFAULT;
37 import com.icesoft.faces.component.ext.taglib.Util;
38 import com.icesoft.faces.context.effects.CurrentStyle;
39 import com.icesoft.faces.context.effects.Effect;
40 import com.icesoft.faces.context.effects.JavascriptContext;
41
42 import javax.faces.context.FacesContext;
43 import javax.faces.el.ValueBinding;
44
45 /**
46  * This is an extension of javax.faces.component.html.HtmlOutputLink, which
47  * provides some additional behavior to this component such as: <ul> <li>default
48  * classes for enabled and disabled state</li> <li>changes the component's
49  * enabled and rendered state based on the authentication</li> <li>adds effects
50  * to the component</li> <ul>
51  */

52 public class HtmlOutputLink extends javax.faces.component.html.HtmlOutputLink {
53     public static final String JavaDoc COMPONENT_TYPE =
54             "com.icesoft.faces.HtmlOutputLink";
55     public static final String JavaDoc RENDERER_TYPE = "com.icesoft.faces.Link";
56     private static final boolean DEFAULT_VISIBLE = true;
57     private String JavaDoc renderedOnUserRole = null;
58     private String JavaDoc enabledOnUserRole = null;
59     private Boolean JavaDoc disabled = null;
60     private Effect effect;
61     private Boolean JavaDoc visible = null;
62     private String JavaDoc styleClass = null;
63     private CurrentStyle currentStyle;
64
65
66     private Effect onclickeffect;
67     private Effect ondblclickeffect;
68     private Effect onmousedowneffect;
69     private Effect onmouseupeffect;
70     private Effect onmousemoveeffect;
71     private Effect onmouseovereffect;
72     private Effect onmouseouteffect;
73     private Effect onkeypresseffect;
74     private Effect onkeydowneffect;
75     private Effect onkeyupeffect;
76
77     public HtmlOutputLink() {
78         super();
79         setRendererType(RENDERER_TYPE);
80     }
81
82     public void setValueBinding(String JavaDoc s, ValueBinding vb) {
83         if (s != null && s.indexOf("effect") != -1) {
84             // If this is an effect attribute make sure Ice Extras is included
85
JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
86                                          getFacesContext());
87         }
88         super.setValueBinding(s, vb);
89     }
90
91     /**
92      * <p>Set the value of the <code>visible</code> property.</p>
93      */

94     public void setVisible(boolean visible) {
95         this.visible = Boolean.valueOf(visible);
96
97     }
98
99     /**
100      * <p>Return the value of the <code>visible</code> property.</p>
101      */

102     public boolean getVisible() {
103         if (visible != null) {
104             return visible.booleanValue();
105         }
106         ValueBinding vb = getValueBinding("visible");
107         Boolean JavaDoc boolVal =
108                 vb != null ? (Boolean JavaDoc) vb.getValue(getFacesContext()) : null;
109         return boolVal != null ? boolVal.booleanValue() : 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
117                 .includeLib(JavascriptContext.ICE_EXTRAS, 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()) : null;
130     }
131
132     /**
133      * <p>Set the value of the <code>renderedOnUserRole</code> property.</p>
134      */

135     public void setRenderedOnUserRole(String JavaDoc renderedOnUserRole) {
136         this.renderedOnUserRole = renderedOnUserRole;
137     }
138
139     /**
140      * <p>Return the value of the <code>renderedOnUserRole</code> property.</p>
141      */

142     public String JavaDoc getRenderedOnUserRole() {
143         if (renderedOnUserRole != null) {
144             return renderedOnUserRole;
145         }
146         ValueBinding vb = getValueBinding("renderedOnUserRole");
147         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
148     }
149
150     /**
151      * <p>Set the value of the <code>enabledOnUserRole</code> property.</p>
152      */

153     public void setEnabledOnUserRole(String JavaDoc enabledOnUserRole) {
154         this.enabledOnUserRole = enabledOnUserRole;
155     }
156
157     /**
158      * <p>Return the value of the <code>enabledOnUserRole</code> property.</p>
159      */

160     public String JavaDoc getEnabledOnUserRole() {
161         if (enabledOnUserRole != null) {
162             return enabledOnUserRole;
163         }
164         ValueBinding vb = getValueBinding("enabledOnUserRole");
165         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
166     }
167
168     /**
169      * <p>Set the value of the <code>styleClass</code> property.</p>
170      */

171     public void setStyleClass(String JavaDoc styleClass) {
172         this.styleClass = styleClass;
173     }
174
175     /**
176      * <p>Return the value of the <code>styleClass</code> property.</p>
177      */

178     public String JavaDoc getStyleClass() {
179         return Util.getQualifiedStyleClass(this,
180                 styleClass,
181                 CSS_DEFAULT.OUTPUT_LINK_DEFAULT_STYLE_CLASS,
182                 "styleClass",
183                 isDisabled());
184     }
185
186     /**
187      * <p>Return the value of the <code>rendered</code> property.</p>
188      */

189     public boolean isRendered() {
190         if (!Util.isRenderedOnUserRole(this)) {
191             return false;
192         }
193         return super.isRendered();
194     }
195
196     /**
197      * <p>Return the value of the <code>onclickeffect</code> property.</p>
198      */

199     public Effect getOnclickeffect() {
200         if (onclickeffect != null) {
201             return onclickeffect;
202         }
203         ValueBinding vb = getValueBinding("onclickeffect");
204
205         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
206     }
207
208     /**
209      * <p>Set the value of the <code>onclickeffect</code> property.</p>
210      */

211     public void setOnclickeffect(Effect onclickeffect) {
212         JavascriptContext
213                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
214         this.onclickeffect = onclickeffect;
215     }
216
217     /**
218      * <p>Set the value of the <code>disabled</code> property.</p>
219      */

220     public void setDisabled(boolean disabled) {
221         this.disabled = new Boolean JavaDoc(disabled);
222         ValueBinding vb = getValueBinding("disabled");
223         if (vb != null) {
224             vb.setValue(getFacesContext(), this.disabled);
225             this.disabled = null;
226         }
227     }
228
229     /**
230      * <p>Return the value of the <code>disabled</code> property.</p>
231      */

232     public boolean isDisabled() {
233         if (!Util.isEnabledOnUserRole(this)) {
234             return true;
235         }
236         if (disabled != null) {
237             return disabled.booleanValue();
238         }
239         ValueBinding vb = getValueBinding("disabled");
240         Boolean JavaDoc v =
241                 vb != null ? (Boolean JavaDoc) vb.getValue(getFacesContext()) : null;
242         return v != null ? v.booleanValue() : false;
243     }
244
245     /**
246      * <p>Return the value of the <code>ondblclickeffect</code> property.</p>
247      */

248     public Effect getOndblclickeffect() {
249         if (ondblclickeffect != null) {
250             return ondblclickeffect;
251         }
252         ValueBinding vb = getValueBinding("ondblclickeffect");
253
254         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
255     }
256
257     /**
258      * <p>Set the value of the <code>ondblclickeffect</code> property.</p>
259      */

260     public void setOndblclickeffect(Effect ondblclickeffect) {
261         JavascriptContext
262                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
263         this.ondblclickeffect = ondblclickeffect;
264     }
265
266     /**
267      * <p>Return the value of the <code>onmousedowneffect</code> property.</p>
268      */

269     public Effect getOnmousedowneffect() {
270         if (onmousedowneffect != null) {
271             return onmousedowneffect;
272         }
273         ValueBinding vb = getValueBinding("onmousedowneffect");
274
275         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
276     }
277
278     /**
279      * <p>Set the value of the <code>onmousedowneffect</code> property.</p>
280      */

281     public void setOnmousedowneffect(Effect onmousedowneffect) {
282         JavascriptContext
283                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
284         this.onmousedowneffect = onmousedowneffect;
285     }
286
287     /**
288      * <p>Return the value of the <code>onmouseupeffect</code> property.</p>
289      */

290     public Effect getOnmouseupeffect() {
291         if (onmouseupeffect != null) {
292             return onmouseupeffect;
293         }
294         ValueBinding vb = getValueBinding("onmouseupeffect");
295
296         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
297     }
298
299     /**
300      * <p>Set the value of the <code>onmouseupeffect</code> property.</p>
301      */

302     public void setOnmouseupeffect(Effect onmouseupeffect) {
303         JavascriptContext
304                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
305         this.onmouseupeffect = onmouseupeffect;
306     }
307
308     /**
309      * <p>Return the value of the <code>onmousemoveeffect</code> property.</p>
310      */

311     public Effect getOnmousemoveeffect() {
312         if (onmousemoveeffect != null) {
313             return onmousemoveeffect;
314         }
315         ValueBinding vb = getValueBinding("onmousemoveeffect");
316
317         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
318     }
319
320     /**
321      * <p>Set the value of the <code>onmousemoveeffect</code> property.</p>
322      */

323     public void setOnmousemoveeffect(Effect onmousemoveeffect) {
324         JavascriptContext
325                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
326         this.onmousemoveeffect = onmousemoveeffect;
327     }
328
329     /**
330      * <p>Return the value of the <code>onmouseovereffect</code> property.</p>
331      */

332     public Effect getOnmouseovereffect() {
333         if (onmouseovereffect != null) {
334             return onmouseovereffect;
335         }
336         ValueBinding vb = getValueBinding("onmouseovereffect");
337
338         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
339     }
340
341     /**
342      * <p>Set the value of the <code>onmouseovereffect</code> property.</p>
343      */

344     public void setOnmouseovereffect(Effect onmouseovereffect) {
345         JavascriptContext
346                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
347         this.onmouseovereffect = onmouseovereffect;
348     }
349
350     /**
351      * <p>Return the value of the <code>onmouseouteffect</code> property.</p>
352      */

353     public Effect getOnmouseouteffect() {
354         if (onmouseouteffect != null) {
355             return onmouseouteffect;
356         }
357         ValueBinding vb = getValueBinding("onmouseouteffect");
358
359         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
360     }
361
362     /**
363      * <p>Set the value of the <code>onmouseouteffect</code> property.</p>
364      */

365     public void setOnmouseouteffect(Effect onmouseouteffect) {
366         JavascriptContext
367                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
368         this.onmouseouteffect = onmouseouteffect;
369     }
370
371
372     /**
373      * <p>Return the value of the <code>onkeypresseffect</code> property.</p>
374      */

375     public Effect getOnkeypresseffect() {
376         if (onkeypresseffect != null) {
377             return onkeypresseffect;
378         }
379         ValueBinding vb = getValueBinding("onkeypresseffect");
380
381         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
382     }
383
384     /**
385      * <p>Set the value of the <code>onkeypresseffect</code> property.</p>
386      */

387     public void setOnkeypresseffect(Effect onkeypresseffect) {
388         JavascriptContext
389                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
390         this.onkeypresseffect = onkeypresseffect;
391     }
392
393     /**
394      * <p>Return the value of the <code>onkeydowneffect</code> property.</p>
395      */

396     public Effect getOnkeydowneffect() {
397         if (onkeydowneffect != null) {
398             return onkeydowneffect;
399         }
400         ValueBinding vb = getValueBinding("onkeydowneffect");
401
402         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
403     }
404
405     /**
406      * <p>Set the value of the <code>onkeydowneffect</code> property.</p>
407      */

408     public void setOnkeydowneffect(Effect onkeydowneffect) {
409         JavascriptContext
410                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
411         this.onkeydowneffect = onkeydowneffect;
412     }
413
414     /**
415      * <p>Return the value of the <code>onkeyupeffect</code> property.</p>
416      */

417     public Effect getOnkeyupeffect() {
418         if (onkeyupeffect != null) {
419             return onkeyupeffect;
420         }
421         ValueBinding vb = getValueBinding("onkeyupeffect");
422
423         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
424     }
425
426     /**
427      * <p>Set the value of the <code>onkeyupeffect</code> property.</p>
428      */

429     public void setOnkeyupeffect(Effect onkeyupeffect) {
430         JavascriptContext
431                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
432         this.onkeyupeffect = onkeyupeffect;
433     }
434
435     /**
436      * <p>Return the value of the <code>currentStyle</code> property.</p>
437      */

438     public CurrentStyle getCurrentStyle() {
439         return currentStyle;
440     }
441
442     /**
443      * <p>Set the value of the <code>currentStyle</code> property.</p>
444      */

445     public void setCurrentStyle(CurrentStyle currentStyle) {
446         this.currentStyle = currentStyle;
447     }
448
449
450     /**
451      * <p>Gets the state of the instance as a <code>Serializable</code>
452      * Object.</p>
453      */

454     public Object JavaDoc saveState(FacesContext context) {
455         Object JavaDoc values[] = new Object JavaDoc[21];
456         values[0] = super.saveState(context);
457         values[1] = renderedOnUserRole;
458         values[2] = effect;
459         values[3] = onclickeffect;
460         values[4] = ondblclickeffect;
461         values[5] = onmousedowneffect;
462         values[6] = onmouseupeffect;
463         values[7] = onmousemoveeffect;
464         values[8] = onmouseovereffect;
465         values[9] = onmouseouteffect;
466         values[13] = onkeypresseffect;
467         values[14] = onkeydowneffect;
468         values[15] = onkeyupeffect;
469         values[16] = enabledOnUserRole;
470         values[17] = disabled;
471         values[18] = currentStyle;
472         values[19] = visible;
473         values[20] = styleClass;
474         return ((Object JavaDoc) (values));
475     }
476
477     /**
478      * <p>Perform any processing required to restore the state from the entries
479      * in the state Object.</p>
480      */

481     public void restoreState(FacesContext context, Object JavaDoc state) {
482         Object JavaDoc values[] = (Object JavaDoc[]) state;
483         super.restoreState(context, values[0]);
484         renderedOnUserRole = (String JavaDoc) values[1];
485         effect = (Effect) values[2];
486         onclickeffect = (Effect) values[3];
487         ondblclickeffect = (Effect) values[4];
488         onmousedowneffect = (Effect) values[5];
489         onmouseupeffect = (Effect) values[6];
490         onmousemoveeffect = (Effect) values[7];
491         onmouseovereffect = (Effect) values[8];
492         onmouseouteffect = (Effect) values[9];
493         onkeypresseffect = (Effect) values[13];
494         onkeydowneffect = (Effect) values[14];
495         onkeyupeffect = (Effect) values[15];
496         enabledOnUserRole = (String JavaDoc) values[16];
497         disabled = (Boolean JavaDoc) values[17];
498         currentStyle = (CurrentStyle) values[18];
499         visible = (Boolean JavaDoc) values[19];
500         styleClass = (String JavaDoc) values[20];
501     }
502 }
503
Popular Tags