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: * <h3>HTML Elements and Layout</h3>
051: *
052: * <p> The <code>Property</code> component was written to be used within the
053: * <code>PropertySheetSection</code> component, which is in turn used within
054: * the context of a <code>PropertySheet</code> component. The
055: * <code>Property</code> component allows you to encapsulate a logic
056: * "property" and help you lay it out on the page. A "property" has a number
057: * of configuration options, including: the property content; an optional
058: * label; the ability to stretch the property to include the label area (in
059: * addition to the content area of the "property"; the ability to mark a
060: * property required; and the ability to associate help text with the property
061: * to inform your end user how to interact with the property.</p>
062: *
063: * <p> Help text can be provided for each property by supplying the
064: * <code>helpText</code> attribute. This attribute may be a literal String
065: * or a <code>ValueBinding</code> expression. The help text will appear
066: * below the content of the "property". Optionally, the helpText may also
067: * be provided as a facet named "helpText". This allows advanced users to
068: * have more control over the types of content provided in the helpText
069: * area.</p>
070: *
071: * <p> The label may be provided via the <code>label</code> attribute. The label
072: * will be rendered to the left of the content area of the "property". The
073: * label area will not exist if the <code>overlapLabel</code> attribute is set
074: * to true. Optionally advanced users may provide a label facet named
075: * "label". This allows developers to have more control over the content of
076: * the label area.</p>
077: *
078: * <p> The <code>labelAlign</code> attribute can use used to specify "left" or
079: * "right" alignment of the label table cell.</p>
080: *
081: * <p> Setting the <code>noWrap</code> attribute to true specifies that the label
082: * should not be wraped to a new line.</p>
083: *
084: * <p> The <code>overlapLabel</code> attribute causes the content of the property
085: * to be stretched into the label area as well as the content area. This may
086: * be useful for titles which should span the entire width, or other cases
087: * where you need the whole width of the <code>PropertySheet</code>.</p>
088: *
089: * <h3>Client Side Javascript Functions</h3>
090: *
091: * <p> None.</p>
092: *
093: * <h3>Examples</h3>
094: *
095: * <h4>Example 1</h4>
096: *
097: * <p>The label is specified via the label attribute. The components of
098: * the content area are specified as children of the
099: * <code>ui:property</code> tag. </p>
100: *
101: * <pre>
102: * <ui:property id="prop1" label="Log file name: ">
103: * <ui:textField id="logfile" required="true"/>
104: * <h:message id="logfile_error" for="logfile" showDetail="true"/>
105: * </ui:property>
106: * </pre>
107: *
108: * <h4>Example 2</h4>
109: *
110: * <p>The components of the content area are specified as children of the
111: * <code>ui:property</code> tag. The label is specified via a label
112: * facet, to label the dropDown in the content area. </p>
113: *
114: * <pre>
115: * <ui:property id="prop2">
116: * <f:facet name="label">
117: * <ui:label id="prop2label"
118: * text="Select update frequency"
119: * for="unit"/>
120: * </f:facet>
121: * <ui:textField id="frequency"
122: * text="#{Logger.frequency.number}"
123: * label="Every "/>
124: * <ui:dropDown id="unit"
125: * selected="#{Logger.frequency.unit}"
126: * items="#{Logger.frequency.units}"
127: * required="true"/>
128: * <h:message id="msg1"_msg4b" for="frequency" showDetail="true"/>
129: * <h:message id="msg2" for="unit" showDetail="true"/>
130: * </ui:property>
131: * </pre>
132: *
133: * <h4>Example 3</h4>
134: *
135: * <p>The components of the content area are specified inside a
136: * PanelGroup child component. </p>
137: * <pre>
138: * <ui:property id="prop3" label="Admin Server URI">
139: * <ui:panelGroup id="pg">
140: * <ui:textField id="uri" text="#{Server.uri}" required="true"/>
141: * <h:message id="msg3" for="uri" showDetail="true"/>
142: * </ui:panelGroup>
143: * </ui:property>
144: * </pre>
145: *
146: *
147: * <h4>Example 4</h4>
148: *
149: *
150: * <p>The components of the content area are specified inside a
151: * PanelGroup inside a facet.</p>
152: *
153: * <pre>
154: * <ui:property id="prop3" label="Admin Server URI">
155: * <f:facet name="content">
156: * <ui:panelGroup id="pg">
157: * <ui:textField id="uri" text="#{Server.uri}" required="true"/>
158: * <h:message id="msg3" for="uri" showDetail="true"/>
159: * </ui:panelGroup>
160: * </f:facet>
161: * </ui:property>
162: *
163: * </pre>
164: * <p>Auto-generated component class.
165: * Do <strong>NOT</strong> modify; all changes
166: * <strong>will</strong> be lost!</p>
167: */
168:
169: public abstract class PropertyBase extends
170: javax.faces.component.UIComponentBase {
171:
172: /**
173: * <p>Construct a new <code>PropertyBase</code>.</p>
174: */
175: public PropertyBase() {
176: super ();
177: setRendererType("com.sun.rave.web.ui.Property");
178: }
179:
180: /**
181: * <p>Return the identifier of the component family to which this
182: * component belongs. This identifier, in conjunction with the value
183: * of the <code>rendererType</code> property, may be used to select
184: * the appropriate {@link Renderer} for this component instance.</p>
185: */
186: public String getFamily() {
187: return "com.sun.rave.web.ui.Property";
188: }
189:
190: // disabled
191: private boolean disabled = false;
192: private boolean disabled_set = false;
193:
194: /**
195: * <p>Flag indicating that the user is not permitted to activate this
196: * component, and that the component's value will not be submitted with the
197: * form.</p>
198: */
199: public boolean isDisabled() {
200: if (this .disabled_set) {
201: return this .disabled;
202: }
203: ValueBinding _vb = getValueBinding("disabled");
204: if (_vb != null) {
205: Object _result = _vb.getValue(getFacesContext());
206: if (_result == null) {
207: return false;
208: } else {
209: return ((Boolean) _result).booleanValue();
210: }
211: }
212: return false;
213: }
214:
215: /**
216: * <p>Flag indicating that the user is not permitted to activate this
217: * component, and that the component's value will not be submitted with the
218: * form.</p>
219: * @see #isDisabled()
220: */
221: public void setDisabled(boolean disabled) {
222: this .disabled = disabled;
223: this .disabled_set = true;
224: }
225:
226: // helpText
227: private String helpText = null;
228:
229: /**
230: * <p>The help text will appear below the content of the "property".
231: * Optionally, the helpText may also be provided as a facet named
232: * "helpText". This allows advanced users to have more control over
233: * the types of content provided in the helpText area.</p>
234: */
235: public String getHelpText() {
236: if (this .helpText != null) {
237: return this .helpText;
238: }
239: ValueBinding _vb = getValueBinding("helpText");
240: if (_vb != null) {
241: return (String) _vb.getValue(getFacesContext());
242: }
243: return null;
244: }
245:
246: /**
247: * <p>The help text will appear below the content of the "property".
248: * Optionally, the helpText may also be provided as a facet named
249: * "helpText". This allows advanced users to have more control over
250: * the types of content provided in the helpText area.</p>
251: * @see #getHelpText()
252: */
253: public void setHelpText(String helpText) {
254: this .helpText = helpText;
255: }
256:
257: // label
258: private String label = null;
259:
260: /**
261: * <p>Use this attribute to specify the text of the label of this
262: * property. The <code>for</code> attribute of the label will be
263: * the first input element in the content area of this component.
264: * To label a different component, use the label facet instead.</p>
265: */
266: public String getLabel() {
267: if (this .label != null) {
268: return this .label;
269: }
270: ValueBinding _vb = getValueBinding("label");
271: if (_vb != null) {
272: return (String) _vb.getValue(getFacesContext());
273: }
274: return null;
275: }
276:
277: /**
278: * <p>Use this attribute to specify the text of the label of this
279: * property. The <code>for</code> attribute of the label will be
280: * the first input element in the content area of this component.
281: * To label a different component, use the label facet instead.</p>
282: * @see #getLabel()
283: */
284: public void setLabel(String label) {
285: this .label = label;
286: }
287:
288: // labelAlign
289: private String labelAlign = null;
290:
291: /**
292: * <p>Specifies the label alignment for the label of this component. The
293: * label itself may be added via the label property or the label facet.
294: * The value will typically be "left" or "right".</p>
295: */
296: public String getLabelAlign() {
297: if (this .labelAlign != null) {
298: return this .labelAlign;
299: }
300: ValueBinding _vb = getValueBinding("labelAlign");
301: if (_vb != null) {
302: return (String) _vb.getValue(getFacesContext());
303: }
304: return null;
305: }
306:
307: /**
308: * <p>Specifies the label alignment for the label of this component. The
309: * label itself may be added via the label property or the label facet.
310: * The value will typically be "left" or "right".</p>
311: * @see #getLabelAlign()
312: */
313: public void setLabelAlign(String labelAlign) {
314: this .labelAlign = labelAlign;
315: }
316:
317: // noWrap
318: private boolean noWrap = false;
319: private boolean noWrap_set = false;
320:
321: /**
322: * <p>Specifies if the label component should not wrap. The label itself
323: * may be added via the label property or the label facet.</p>
324: */
325: public boolean isNoWrap() {
326: if (this .noWrap_set) {
327: return this .noWrap;
328: }
329: ValueBinding _vb = getValueBinding("noWrap");
330: if (_vb != null) {
331: Object _result = _vb.getValue(getFacesContext());
332: if (_result == null) {
333: return false;
334: } else {
335: return ((Boolean) _result).booleanValue();
336: }
337: }
338: return false;
339: }
340:
341: /**
342: * <p>Specifies if the label component should not wrap. The label itself
343: * may be added via the label property or the label facet.</p>
344: * @see #isNoWrap()
345: */
346: public void setNoWrap(boolean noWrap) {
347: this .noWrap = noWrap;
348: this .noWrap_set = true;
349: }
350:
351: // overlapLabel
352: private boolean overlapLabel = false;
353: private boolean overlapLabel_set = false;
354:
355: /**
356: * <p>This indicates whether the property should overlap into the label
357: * area or not. Default: false -- do not extend into the label area.</p>
358: */
359: public boolean isOverlapLabel() {
360: if (this .overlapLabel_set) {
361: return this .overlapLabel;
362: }
363: ValueBinding _vb = getValueBinding("overlapLabel");
364: if (_vb != null) {
365: Object _result = _vb.getValue(getFacesContext());
366: if (_result == null) {
367: return false;
368: } else {
369: return ((Boolean) _result).booleanValue();
370: }
371: }
372: return false;
373: }
374:
375: /**
376: * <p>This indicates whether the property should overlap into the label
377: * area or not. Default: false -- do not extend into the label area.</p>
378: * @see #isOverlapLabel()
379: */
380: public void setOverlapLabel(boolean overlapLabel) {
381: this .overlapLabel = overlapLabel;
382: this .overlapLabel_set = true;
383: }
384:
385: // style
386: private String style = null;
387:
388: /**
389: * <p>CSS style(s) to be applied when this component is rendered.</p>
390: */
391: public String getStyle() {
392: if (this .style != null) {
393: return this .style;
394: }
395: ValueBinding _vb = getValueBinding("style");
396: if (_vb != null) {
397: return (String) _vb.getValue(getFacesContext());
398: }
399: return null;
400: }
401:
402: /**
403: * <p>CSS style(s) to be applied when this component is rendered.</p>
404: * @see #getStyle()
405: */
406: public void setStyle(String style) {
407: this .style = style;
408: }
409:
410: // styleClass
411: private String styleClass = null;
412:
413: /**
414: * <p>CSS style class(es) to be applied when this component is rendered.</p>
415: */
416: public String getStyleClass() {
417: if (this .styleClass != null) {
418: return this .styleClass;
419: }
420: ValueBinding _vb = getValueBinding("styleClass");
421: if (_vb != null) {
422: return (String) _vb.getValue(getFacesContext());
423: }
424: return null;
425: }
426:
427: /**
428: * <p>CSS style class(es) to be applied when this component is rendered.</p>
429: * @see #getStyleClass()
430: */
431: public void setStyleClass(String styleClass) {
432: this .styleClass = styleClass;
433: }
434:
435: // visible
436: private boolean visible = false;
437: private boolean visible_set = false;
438:
439: /**
440: * <p>Use the visible attribute to indicate whether the component should be
441: * viewable by the user in the rendered HTML page. If set to false, the
442: * HTML code for the component is present in the page, but the component
443: * is hidden with style attributes. By default, visible is set to true, so
444: * HTML for the component HTML is included and visible to the user. If the
445: * component is not visible, it can still be processed on subsequent form
446: * submissions because the HTML is present.</p>
447: */
448: public boolean isVisible() {
449: if (this .visible_set) {
450: return this .visible;
451: }
452: ValueBinding _vb = getValueBinding("visible");
453: if (_vb != null) {
454: Object _result = _vb.getValue(getFacesContext());
455: if (_result == null) {
456: return false;
457: } else {
458: return ((Boolean) _result).booleanValue();
459: }
460: }
461: return true;
462: }
463:
464: /**
465: * <p>Use the visible attribute to indicate whether the component should be
466: * viewable by the user in the rendered HTML page. If set to false, the
467: * HTML code for the component is present in the page, but the component
468: * is hidden with style attributes. By default, visible is set to true, so
469: * HTML for the component HTML is included and visible to the user. If the
470: * component is not visible, it can still be processed on subsequent form
471: * submissions because the HTML is present.</p>
472: * @see #isVisible()
473: */
474: public void setVisible(boolean visible) {
475: this .visible = visible;
476: this .visible_set = true;
477: }
478:
479: /**
480: * <p>Restore the state of this component.</p>
481: */
482: public void restoreState(FacesContext _context, Object _state) {
483: Object _values[] = (Object[]) _state;
484: super .restoreState(_context, _values[0]);
485: this .disabled = ((Boolean) _values[1]).booleanValue();
486: this .disabled_set = ((Boolean) _values[2]).booleanValue();
487: this .helpText = (String) _values[3];
488: this .label = (String) _values[4];
489: this .labelAlign = (String) _values[5];
490: this .noWrap = ((Boolean) _values[6]).booleanValue();
491: this .noWrap_set = ((Boolean) _values[7]).booleanValue();
492: this .overlapLabel = ((Boolean) _values[8]).booleanValue();
493: this .overlapLabel_set = ((Boolean) _values[9]).booleanValue();
494: this .style = (String) _values[10];
495: this .styleClass = (String) _values[11];
496: this .visible = ((Boolean) _values[12]).booleanValue();
497: this .visible_set = ((Boolean) _values[13]).booleanValue();
498: }
499:
500: /**
501: * <p>Save the state of this component.</p>
502: */
503: public Object saveState(FacesContext _context) {
504: Object _values[] = new Object[14];
505: _values[0] = super .saveState(_context);
506: _values[1] = this .disabled ? Boolean.TRUE : Boolean.FALSE;
507: _values[2] = this .disabled_set ? Boolean.TRUE : Boolean.FALSE;
508: _values[3] = this .helpText;
509: _values[4] = this .label;
510: _values[5] = this .labelAlign;
511: _values[6] = this .noWrap ? Boolean.TRUE : Boolean.FALSE;
512: _values[7] = this .noWrap_set ? Boolean.TRUE : Boolean.FALSE;
513: _values[8] = this .overlapLabel ? Boolean.TRUE : Boolean.FALSE;
514: _values[9] = this .overlapLabel_set ? Boolean.TRUE
515: : Boolean.FALSE;
516: _values[10] = this .style;
517: _values[11] = this .styleClass;
518: _values[12] = this .visible ? Boolean.TRUE : Boolean.FALSE;
519: _values[13] = this.visible_set ? Boolean.TRUE : Boolean.FALSE;
520: return _values;
521: }
522:
523: }
|