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