001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package com.sun.rave.web.ui.component;
042:
043: import java.io.IOException;
044: import javax.faces.component.UIComponent;
045: import javax.faces.context.FacesContext;
046: import javax.faces.el.MethodBinding;
047: import javax.faces.el.ValueBinding;
048:
049: /**
050: * <p>Use the <code>ui:label</code>
051: * tag to display a label for a component. To specify which component
052: * the label belongs to you can do one of the following:</p>
053: * <ul>
054: * <li>Place the component to be labeled in the body of
055: * <code>ui:label</code>; or </li>
056: * <li>Set the value of the <code>for</code> attribute of <code
057: * >ui:label</code> to the id of the component to be labeled.</li>
058: * </ul>
059: * <p>If the tags are adjacent on the page, it is simpler to place the
060: * component in the body of the <code>ui:label</code> tag. </p>
061: *
062: * <p>Note that many components in this library have <code>label</code>
063: * and <code>labelLevel</code> attributes (and sometimes
064: * <code>labelOnTop</code>) which can be used instead of <code
065: * >ui:label</code>. The main reason
066: * to use <code>ui:label</code> is to specify the
067: * appearance of the label beyond what these attributes permit.
068: * </p>
069: *
070: * <h3>HTML Elements and Layout</h3>
071: *
072: * <p>
073: * The <code>ui:label</code> tag results in a HTML <code><label></code>
074: * or <code><span></code> element. A <code><span></code>
075: * element is rendered if no labeled component is found. </p>
076: *
077: * <p> If the tag has a body, the body must consist of tags for
078: * JavaServer Faces components only. The components become children
079: * of the <code>Label</code> component, and are rendered after the
080: * <code><label></code> element.</p>
081: *
082: * <p>If the tag has a body but no <code>for</code> attribute, a
083: * <code><label></code> element is rendered. Its
084: * <code>for</code> attribute is set to the element ID of the first
085: * child component that is an <code>EditableValueHolder. </code>
086: *
087: * <h3>Theme Identifiers</h3>
088: *
089: * <p>The Label renderer relies on the following theme classes:</p>
090: *
091: * <pre>
092: * LblLev1Txt
093: * LblLev2Txt
094: * LblLev3Txt
095: * LblRqdDiv
096: * </pre>
097: *
098: * <h3>Client Side Javascript Functions</h3>
099: *
100: * <p>None.</p>
101: *
102: * <h3>Example</h3>
103: *
104: * <h4>Example 1: <code>ui:label</code> with <code>for</code> attribute</h4>
105: *
106: * <pre>
107: * <ui:label id="label1" text="Label 1:" for="field1" labelLevel="2"/>
108: * <ui:field id="field1" text="#{Bean.value}" type="text" trim="true"/>
109: * </pre>
110: *
111: * <h4>Example 2: <code>ui:label</code> with labeled component in tag body</h4>
112: *
113: * <pre>
114: * <ui:label id="label2" text="Label 2:" labelLevel="2"/>
115: * <ui:field id="field2" text="#{Bean.value}" type="text"
116: * trim="true"/>
117: * </ui:label>
118: * </pre>
119: *
120: * <h4>Example 3: Using the label attribute instead of <code>ui:label</code></h4>
121: *
122: * <pre>
123: * <ui:field id="field3" text="#{Bean.value}" type="text"
124: * trim="true" label="Label 3:" labelLevel="2"/>
125: * </pre>
126: * <p>Auto-generated component class.
127: * Do <strong>NOT</strong> modify; all changes
128: * <strong>will</strong> be lost!</p>
129: */
130:
131: public abstract class LabelBase extends javax.faces.component.UIOutput {
132:
133: /**
134: * <p>Construct a new <code>LabelBase</code>.</p>
135: */
136: public LabelBase() {
137: super ();
138: setRendererType("com.sun.rave.web.ui.Label");
139: }
140:
141: /**
142: * <p>Return the identifier of the component family to which this
143: * component belongs. This identifier, in conjunction with the value
144: * of the <code>rendererType</code> property, may be used to select
145: * the appropriate {@link Renderer} for this component instance.</p>
146: */
147: public String getFamily() {
148: return "com.sun.rave.web.ui.Label";
149: }
150:
151: /**
152: * <p>Return the <code>ValueBinding</code> stored for the
153: * specified name (if any), respecting any property aliases.</p>
154: *
155: * @param name Name of value binding to retrieve
156: */
157: public ValueBinding getValueBinding(String name) {
158: if (name.equals("text")) {
159: return super .getValueBinding("value");
160: }
161: return super .getValueBinding(name);
162: }
163:
164: /**
165: * <p>Set the <code>ValueBinding</code> stored for the
166: * specified name (if any), respecting any property
167: * aliases.</p>
168: *
169: * @param name Name of value binding to set
170: * @param binding ValueBinding to set, or null to remove
171: */
172: public void setValueBinding(String name, ValueBinding binding) {
173: if (name.equals("text")) {
174: super .setValueBinding("value", binding);
175: return;
176: }
177: super .setValueBinding(name, binding);
178: }
179:
180: // for
181: private String _for = null;
182:
183: /**
184: * <p>Use this attribute to specify the labeled component. The
185: * attribute is only relevant if the component to be labeled is not
186: * a child of the <code>ui:label</code> tag. The value of the
187: * attribute should be the id of the component relative to the
188: * label, not the DOM ID of the rendered HTML element.</p>
189: */
190: public String getFor() {
191: return this ._for;
192: }
193:
194: /**
195: * <p>Use this attribute to specify the labeled component. The
196: * attribute is only relevant if the component to be labeled is not
197: * a child of the <code>ui:label</code> tag. The value of the
198: * attribute should be the id of the component relative to the
199: * label, not the DOM ID of the rendered HTML element.</p>
200: * @see #getFor()
201: */
202: public void setFor(String _for) {
203: this ._for = _for;
204: }
205:
206: // hideIndicators
207: private boolean hideIndicators = false;
208: private boolean hideIndicators_set = false;
209:
210: /**
211: * <p>Use the hideIndicators attribute to prevent display of the
212: * required and invalid icons with the label. When the required
213: * attribute on the component to be labeled is set to true, the
214: * required icon is displayed next to the label. If the user
215: * submits the page with an invalid value for the component, the
216: * invalid icon is displayed. This attribute is useful when the
217: * component has more than one label, and only one label should
218: * show the icons.</p>
219: */
220: public boolean isHideIndicators() {
221: if (this .hideIndicators_set) {
222: return this .hideIndicators;
223: }
224: ValueBinding _vb = getValueBinding("hideIndicators");
225: if (_vb != null) {
226: Object _result = _vb.getValue(getFacesContext());
227: if (_result == null) {
228: return false;
229: } else {
230: return ((Boolean) _result).booleanValue();
231: }
232: }
233: return false;
234: }
235:
236: /**
237: * <p>Use the hideIndicators attribute to prevent display of the
238: * required and invalid icons with the label. When the required
239: * attribute on the component to be labeled is set to true, the
240: * required icon is displayed next to the label. If the user
241: * submits the page with an invalid value for the component, the
242: * invalid icon is displayed. This attribute is useful when the
243: * component has more than one label, and only one label should
244: * show the icons.</p>
245: * @see #isHideIndicators()
246: */
247: public void setHideIndicators(boolean hideIndicators) {
248: this .hideIndicators = hideIndicators;
249: this .hideIndicators_set = true;
250: }
251:
252: // labelLevel
253: private int labelLevel = Integer.MIN_VALUE;
254: private boolean labelLevel_set = false;
255:
256: /**
257: * <p>Style level for this label, where lower values typically specify
258: * progressively larger font sizes, and/or bolder font weights.
259: * Valid values are 1, 2, and 3. The default label level is 2. Any label
260: * level outside this range will result in no label level being added.</p>
261: */
262: public int getLabelLevel() {
263: if (this .labelLevel_set) {
264: return this .labelLevel;
265: }
266: ValueBinding _vb = getValueBinding("labelLevel");
267: if (_vb != null) {
268: Object _result = _vb.getValue(getFacesContext());
269: if (_result == null) {
270: return Integer.MIN_VALUE;
271: } else {
272: return ((Integer) _result).intValue();
273: }
274: }
275: return 2;
276: }
277:
278: /**
279: * <p>Style level for this label, where lower values typically specify
280: * progressively larger font sizes, and/or bolder font weights.
281: * Valid values are 1, 2, and 3. The default label level is 2. Any label
282: * level outside this range will result in no label level being added.</p>
283: * @see #getLabelLevel()
284: */
285: public void setLabelLevel(int labelLevel) {
286: this .labelLevel = labelLevel;
287: this .labelLevel_set = true;
288: }
289:
290: // onClick
291: private String onClick = null;
292:
293: /**
294: * <p>Scripting code executed when a mouse click
295: * occurs over this component.</p>
296: */
297: public String getOnClick() {
298: if (this .onClick != null) {
299: return this .onClick;
300: }
301: ValueBinding _vb = getValueBinding("onClick");
302: if (_vb != null) {
303: return (String) _vb.getValue(getFacesContext());
304: }
305: return null;
306: }
307:
308: /**
309: * <p>Scripting code executed when a mouse click
310: * occurs over this component.</p>
311: * @see #getOnClick()
312: */
313: public void setOnClick(String onClick) {
314: this .onClick = onClick;
315: }
316:
317: // onMouseDown
318: private String onMouseDown = null;
319:
320: /**
321: * <p>Scripting code executed when the user presses a mouse button while the
322: * mouse pointer is on the component.</p>
323: */
324: public String getOnMouseDown() {
325: if (this .onMouseDown != null) {
326: return this .onMouseDown;
327: }
328: ValueBinding _vb = getValueBinding("onMouseDown");
329: if (_vb != null) {
330: return (String) _vb.getValue(getFacesContext());
331: }
332: return null;
333: }
334:
335: /**
336: * <p>Scripting code executed when the user presses a mouse button while the
337: * mouse pointer is on the component.</p>
338: * @see #getOnMouseDown()
339: */
340: public void setOnMouseDown(String onMouseDown) {
341: this .onMouseDown = onMouseDown;
342: }
343:
344: // onMouseMove
345: private String onMouseMove = null;
346:
347: /**
348: * <p>Scripting code executed when the user moves the mouse pointer while
349: * over the component.</p>
350: */
351: public String getOnMouseMove() {
352: if (this .onMouseMove != null) {
353: return this .onMouseMove;
354: }
355: ValueBinding _vb = getValueBinding("onMouseMove");
356: if (_vb != null) {
357: return (String) _vb.getValue(getFacesContext());
358: }
359: return null;
360: }
361:
362: /**
363: * <p>Scripting code executed when the user moves the mouse pointer while
364: * over the component.</p>
365: * @see #getOnMouseMove()
366: */
367: public void setOnMouseMove(String onMouseMove) {
368: this .onMouseMove = onMouseMove;
369: }
370:
371: // onMouseOut
372: private String onMouseOut = null;
373:
374: /**
375: * <p>Scripting code executed when a mouse out movement
376: * occurs over this component.</p>
377: */
378: public String getOnMouseOut() {
379: if (this .onMouseOut != null) {
380: return this .onMouseOut;
381: }
382: ValueBinding _vb = getValueBinding("onMouseOut");
383: if (_vb != null) {
384: return (String) _vb.getValue(getFacesContext());
385: }
386: return null;
387: }
388:
389: /**
390: * <p>Scripting code executed when a mouse out movement
391: * occurs over this component.</p>
392: * @see #getOnMouseOut()
393: */
394: public void setOnMouseOut(String onMouseOut) {
395: this .onMouseOut = onMouseOut;
396: }
397:
398: // onMouseOver
399: private String onMouseOver = null;
400:
401: /**
402: * <p>Scripting code executed when the user moves the mouse pointer into
403: * the boundary of this component.</p>
404: */
405: public String getOnMouseOver() {
406: if (this .onMouseOver != null) {
407: return this .onMouseOver;
408: }
409: ValueBinding _vb = getValueBinding("onMouseOver");
410: if (_vb != null) {
411: return (String) _vb.getValue(getFacesContext());
412: }
413: return null;
414: }
415:
416: /**
417: * <p>Scripting code executed when the user moves the mouse pointer into
418: * the boundary of this component.</p>
419: * @see #getOnMouseOver()
420: */
421: public void setOnMouseOver(String onMouseOver) {
422: this .onMouseOver = onMouseOver;
423: }
424:
425: // onMouseUp
426: private String onMouseUp = null;
427:
428: /**
429: * <p>Scripting code executed when the user releases a mouse button while
430: * the mouse pointer is on the component.</p>
431: */
432: public String getOnMouseUp() {
433: if (this .onMouseUp != null) {
434: return this .onMouseUp;
435: }
436: ValueBinding _vb = getValueBinding("onMouseUp");
437: if (_vb != null) {
438: return (String) _vb.getValue(getFacesContext());
439: }
440: return null;
441: }
442:
443: /**
444: * <p>Scripting code executed when the user releases a mouse button while
445: * the mouse pointer is on the component.</p>
446: * @see #getOnMouseUp()
447: */
448: public void setOnMouseUp(String onMouseUp) {
449: this .onMouseUp = onMouseUp;
450: }
451:
452: // requiredIndicator
453: private boolean requiredIndicator = false;
454: private boolean requiredIndicator_set = false;
455:
456: /**
457: * <p>Flag indicating that the labeled component should be marked as
458: * required. It is only relevant if the labeled component is not
459: * a child of the label tag. Set this flag to ensure that the
460: * required icon shows up the first time the page is rendered.</p>
461: */
462: public boolean isRequiredIndicator() {
463: if (this .requiredIndicator_set) {
464: return this .requiredIndicator;
465: }
466: ValueBinding _vb = getValueBinding("requiredIndicator");
467: if (_vb != null) {
468: Object _result = _vb.getValue(getFacesContext());
469: if (_result == null) {
470: return false;
471: } else {
472: return ((Boolean) _result).booleanValue();
473: }
474: }
475: return false;
476: }
477:
478: /**
479: * <p>Flag indicating that the labeled component should be marked as
480: * required. It is only relevant if the labeled component is not
481: * a child of the label tag. Set this flag to ensure that the
482: * required icon shows up the first time the page is rendered.</p>
483: * @see #isRequiredIndicator()
484: */
485: public void setRequiredIndicator(boolean requiredIndicator) {
486: this .requiredIndicator = requiredIndicator;
487: this .requiredIndicator_set = true;
488: }
489:
490: // style
491: private String style = null;
492:
493: /**
494: * <p>CSS style(s) to be applied when this component is rendered.</p>
495: */
496: public String getStyle() {
497: if (this .style != null) {
498: return this .style;
499: }
500: ValueBinding _vb = getValueBinding("style");
501: if (_vb != null) {
502: return (String) _vb.getValue(getFacesContext());
503: }
504: return null;
505: }
506:
507: /**
508: * <p>CSS style(s) to be applied when this component is rendered.</p>
509: * @see #getStyle()
510: */
511: public void setStyle(String style) {
512: this .style = style;
513: }
514:
515: // styleClass
516: private String styleClass = null;
517:
518: /**
519: * <p>CSS style class(es) to be applied when this component is rendered.</p>
520: */
521: public String getStyleClass() {
522: if (this .styleClass != null) {
523: return this .styleClass;
524: }
525: ValueBinding _vb = getValueBinding("styleClass");
526: if (_vb != null) {
527: return (String) _vb.getValue(getFacesContext());
528: }
529: return null;
530: }
531:
532: /**
533: * <p>CSS style class(es) to be applied when this component is rendered.</p>
534: * @see #getStyleClass()
535: */
536: public void setStyleClass(String styleClass) {
537: this .styleClass = styleClass;
538: }
539:
540: // text
541: /**
542: * <p>The label text to be displayed for this label. This attribute
543: * can be set to a literal string, to a value binding expression
544: * that corresponds to a property of a managed bean, or to a value
545: * binding expression that corresponds to a message from a resource
546: * bundle declared using <code>f:loadBundle</code>.</p>
547: */
548: public Object getText() {
549: return getValue();
550: }
551:
552: /**
553: * <p>The label text to be displayed for this label. This attribute
554: * can be set to a literal string, to a value binding expression
555: * that corresponds to a property of a managed bean, or to a value
556: * binding expression that corresponds to a message from a resource
557: * bundle declared using <code>f:loadBundle</code>.</p>
558: * @see #getText()
559: */
560: public void setText(Object text) {
561: setValue(text);
562: }
563:
564: // toolTip
565: private String toolTip = null;
566:
567: /**
568: * <p>Display the text as a tooltip for this component</p>
569: */
570: public String getToolTip() {
571: if (this .toolTip != null) {
572: return this .toolTip;
573: }
574: ValueBinding _vb = getValueBinding("toolTip");
575: if (_vb != null) {
576: return (String) _vb.getValue(getFacesContext());
577: }
578: return null;
579: }
580:
581: /**
582: * <p>Display the text as a tooltip for this component</p>
583: * @see #getToolTip()
584: */
585: public void setToolTip(String toolTip) {
586: this .toolTip = toolTip;
587: }
588:
589: // visible
590: private boolean visible = false;
591: private boolean visible_set = false;
592:
593: /**
594: * <p>Use the visible attribute to indicate whether the component should be
595: * viewable by the user in the rendered HTML page. If set to false, the
596: * HTML code for the component is present in the page, but the component
597: * is hidden with style attributes. By default, visible is set to true, so
598: * HTML for the component HTML is included and visible to the user. If the
599: * component is not visible, it can still be processed on subsequent form
600: * submissions because the HTML is present.</p>
601: */
602: public boolean isVisible() {
603: if (this .visible_set) {
604: return this .visible;
605: }
606: ValueBinding _vb = getValueBinding("visible");
607: if (_vb != null) {
608: Object _result = _vb.getValue(getFacesContext());
609: if (_result == null) {
610: return false;
611: } else {
612: return ((Boolean) _result).booleanValue();
613: }
614: }
615: return true;
616: }
617:
618: /**
619: * <p>Use the visible attribute to indicate whether the component should be
620: * viewable by the user in the rendered HTML page. If set to false, the
621: * HTML code for the component is present in the page, but the component
622: * is hidden with style attributes. By default, visible is set to true, so
623: * HTML for the component HTML is included and visible to the user. If the
624: * component is not visible, it can still be processed on subsequent form
625: * submissions because the HTML is present.</p>
626: * @see #isVisible()
627: */
628: public void setVisible(boolean visible) {
629: this .visible = visible;
630: this .visible_set = true;
631: }
632:
633: /**
634: * <p>Restore the state of this component.</p>
635: */
636: public void restoreState(FacesContext _context, Object _state) {
637: Object _values[] = (Object[]) _state;
638: super .restoreState(_context, _values[0]);
639: this ._for = (String) _values[1];
640: this .hideIndicators = ((Boolean) _values[2]).booleanValue();
641: this .hideIndicators_set = ((Boolean) _values[3]).booleanValue();
642: this .labelLevel = ((Integer) _values[4]).intValue();
643: this .labelLevel_set = ((Boolean) _values[5]).booleanValue();
644: this .onClick = (String) _values[6];
645: this .onMouseDown = (String) _values[7];
646: this .onMouseMove = (String) _values[8];
647: this .onMouseOut = (String) _values[9];
648: this .onMouseOver = (String) _values[10];
649: this .onMouseUp = (String) _values[11];
650: this .requiredIndicator = ((Boolean) _values[12]).booleanValue();
651: this .requiredIndicator_set = ((Boolean) _values[13])
652: .booleanValue();
653: this .style = (String) _values[14];
654: this .styleClass = (String) _values[15];
655: this .toolTip = (String) _values[16];
656: this .visible = ((Boolean) _values[17]).booleanValue();
657: this .visible_set = ((Boolean) _values[18]).booleanValue();
658: }
659:
660: /**
661: * <p>Save the state of this component.</p>
662: */
663: public Object saveState(FacesContext _context) {
664: Object _values[] = new Object[19];
665: _values[0] = super .saveState(_context);
666: _values[1] = this ._for;
667: _values[2] = this .hideIndicators ? Boolean.TRUE : Boolean.FALSE;
668: _values[3] = this .hideIndicators_set ? Boolean.TRUE
669: : Boolean.FALSE;
670: _values[4] = new Integer(this .labelLevel);
671: _values[5] = this .labelLevel_set ? Boolean.TRUE : Boolean.FALSE;
672: _values[6] = this .onClick;
673: _values[7] = this .onMouseDown;
674: _values[8] = this .onMouseMove;
675: _values[9] = this .onMouseOut;
676: _values[10] = this .onMouseOver;
677: _values[11] = this .onMouseUp;
678: _values[12] = this .requiredIndicator ? Boolean.TRUE
679: : Boolean.FALSE;
680: _values[13] = this .requiredIndicator_set ? Boolean.TRUE
681: : Boolean.FALSE;
682: _values[14] = this .style;
683: _values[15] = this .styleClass;
684: _values[16] = this .toolTip;
685: _values[17] = this .visible ? Boolean.TRUE : Boolean.FALSE;
686: _values[18] = this.visible_set ? Boolean.TRUE : Boolean.FALSE;
687: return _values;
688: }
689:
690: }
|