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