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>About This Tag</h3>
051: *
052: * <p>The TabSet renders a set of Tab children. It keeps track of the currently
053: * selected child Tab as well as applying any specified ActionListener.</p>
054: *
055: * <h3>Configuring the TabSet Tag</h3>
056: *
057: * <p>The TabSet can currently be used in one of two ways: via a component binding to a
058: * TabSet and group of child Tab components (defined in a backing bean); or by specifying the
059: * TabSet and child Tabs directly in your JSP.</p><p>Examples of both are shown in the Examples
060: * section below. It is anticipated that the component binding method will be more
061: * common as this allows a single set of Tabs to be easily shared among many pages. In
062: * either case, the initial selection for the TabSet component can be specified using the
063: * "selected" property. Note that if an ActionListener is applied to the TabSet
064: * component, it adds the specified ActionListener to each of its child Tab components action
065: * listener lists.</p>
066: *
067: * <h3>Facets</h3>
068: *
069: * <p>None at this time</p>
070: *
071: * <h3>Client Side Javascript Functions</h3>
072: *
073: * <p>None at this time</p>
074: *
075: * <h3>Examples</h3>
076: *
077: * <p><strong>Example 1: Define the TabSet via a component binding</strong><br>
078: * One way a TabSet component can be specified is via a JSF component binding to an instance
079: * defined in a backing bean. The contents of the JSP in this case will simply be something
080: * like:</p>
081: *
082: * <p><code><ui:tabSet binding="#{TabSetBean.sportsTabSet}" /></code></p>
083: *
084: * <p>The code in the corresponding backing bean instance would look something like:</p>
085: *
086: * <p><code>import java.util.List;<br>
087: * import java.lang.Class;<br>
088: * import javax.faces.FactoryFinder;<br>
089: * import javax.faces.el.MethodBinding;<br>
090: * import javax.faces.event.ActionEvent;<br>
091: * import javax.faces.application.Application;<br>
092: * import javax.faces.application.ApplicationFactory;<br>
093: * import com.sun.rave.web.ui.component.Tab;<br>
094: * import com.sun.rave.web.ui.component.TabSet;</p>
095: *
096: * <p>public class TabSetBean {<br>
097: * private TabSet sportsTabSet = null;<br>
098: * <br>
099: * // Creates a new instance of TabSetBean //<br>
100: * public TabSetBean() {<br>
101: * sportsTabSet = new TabSet();<br>
102: * List kids = sportsTabSet.getChildren();<br>
103: * <br>
104: * Tab level1Tab = new Tab("Baseball");<br>
105: * level1Tab.setId("Baseball");<br>
106: * Tab level2Tab = addTab(level1Tab,
107: * "National"); <br>
108: * addTab(level2Tab, "Mets");<br>
109: * addTab(level2Tab, "Pirates");<br>
110: * addTab(level2Tab, "Cubs");<br>
111: * <br>
112: * level2Tab = addTab(level1Tab,
113: * "American"); <br>
114: * addTab(level2Tab, "Yankees");<br>
115: * addTab(level2Tab, "Tigers");<br>
116: * addTab(level2Tab, "Mariners");<br>
117: * <br>
118: * level2Tab = addTab(level1Tab, "AAA");<br>
119: * addTab(level2Tab, "Spinners");<br>
120: * addTab(level2Tab, "Renegades");<br>
121: * addTab(level2Tab, "Clippers"); <br>
122: * <br>
123: * kids.add(level1Tab);<br>
124: * <br>
125: * level1Tab = new Tab("Football");<br>
126: * level1Tab.setId("Football");<br>
127: * level2Tab = addTab(level1Tab, "NFC");
128: * <br>
129: * addTab(level2Tab, "Giants");<br>
130: * addTab(level2Tab, "Bears");<br>
131: * addTab(level2Tab, "Falcons");<br>
132: * <br>
133: * level2Tab = addTab(level1Tab, "AFC");
134: * <br>
135: * addTab(level2Tab, "Jets");<br>
136: * addTab(level2Tab, "Patriots");<br>
137: * addTab(level2Tab, "Colts");<br>
138: * <br>
139: * level2Tab = addTab(level1Tab,
140: * "College");<br>
141: * addTab(level2Tab, "Wolverines");<br>
142: * addTab(level2Tab, "Hurricanes");<br>
143: * addTab(level2Tab, "Buckeyes");<br>
144: * <br>
145: * kids.add(level1Tab);<br>
146: * <br>
147: * Class[] args = new Class[] { ActionEvent.class
148: * };<br>
149: * MethodBinding binding =
150: * createBinding("#{TabSetBean.tabClicked}", args);<br>
151: * <br>
152: * sportsTabSet.setActionListener(binding); <br>
153: * <br>
154: * sportsTabSet.setSelected("Jets");<br>
155: * <br>
156: * }<br>
157: * <br>
158: * private MethodBinding createBinding(String expr, Class[] args) { <br>
159: * ApplicationFactory factory =
160: * (ApplicationFactory)<br>
161: * FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);<br>
162: * Application app = factory.getApplication();<br>
163: * <br>
164: * return app.createMethodBinding(expr, args);<br>
165: * }<br>
166: * <br>
167: * private Tab addTab(Tab parent, String newTabLabel) {<br>
168: * Tab tab = new Tab(newTabLabel);<br>
169: * tab.setId(newTabLabel); <br>
170: * parent.getChildren().add(tab);<br>
171: * return tab;<br>
172: * } </p>
173: *
174: * <p> public void tabClicked(ActionEvent event) {<br>
175: * String clickedTabId = event.getComponent().getId():<br>
176: * String selectedTabId = sportsTabSet.getSelected();<br>
177: * // ... do sometehing based upon the clicked or
178: * selected tab id ...<br>
179: * }<br>
180: * <br>
181: * public TabSet getSportsTabSet() {<br>
182: * return sportsTabSet;<br>
183: * }<br>
184: * <br>
185: * public void setSportsTabSet(TabSet tabs) {<br>
186: * sportsTabSet = tabs;<br>
187: * }<br>
188: * }</code></p>
189: *
190: * <p><strong>Example 2: Define the TabSet in your JSP</strong><br>
191: * A tabSet can also be defined directly in your JSP. The following example defines a set of tabs with
192: * three level one tabs (labelled "One", "Two" and "Three"). Each
193: * level one tab also has two level two tab childeren (labelled "XxxA" and
194: * "XxxB" where X is the top level tab number. The initially selected Tab for this
195: * TabSet will be "TwoA".</p>
196: *
197: * <p><code><ui:tabSet selected="TwoA"><br>
198: * <ui:tab id="One" text="One"><br>
199: * <ui:tab id="OneA" text="One
200: * A" /><br>
201: * <ui:tab id="OneB" text="One
202: * B" /><br>
203: * </ui:tab><br>
204: * <ui:tab id="Two" text="Two"><br>
205: * <ui:tab id="TwoA" text="Two
206: * A" /><br>
207: * <ui:tab id="TwoB" text="Two
208: * B" /><br>
209: * </ui:tab><br>
210: * <ui:tab id="Three" text="Three"><br>
211: * <ui:tab id="ThreeA"
212: * text="Three A" /><br>
213: * <ui:tab id="ThreeB"
214: * text="Three B" /><br>
215: * </ui:tab> <br>
216: * </ui:tabSet></code></p>
217: * <p>Auto-generated component class.
218: * Do <strong>NOT</strong> modify; all changes
219: * <strong>will</strong> be lost!</p>
220: */
221:
222: public abstract class TabSetBase extends
223: javax.faces.component.UINamingContainer {
224:
225: /**
226: * <p>Construct a new <code>TabSetBase</code>.</p>
227: */
228: public TabSetBase() {
229: super ();
230: setRendererType("com.sun.rave.web.ui.TabSet");
231: }
232:
233: /**
234: * <p>Return the identifier of the component family to which this
235: * component belongs. This identifier, in conjunction with the value
236: * of the <code>rendererType</code> property, may be used to select
237: * the appropriate {@link Renderer} for this component instance.</p>
238: */
239: public String getFamily() {
240: return "com.sun.rave.web.ui.TabSet";
241: }
242:
243: // actionListener
244: private javax.faces.el.MethodBinding actionListener = null;
245:
246: /**
247: * <p>Use the actionListener attribute to cause the hyperlink to fire an
248: * event. The value must be an EL expression and it must evaluate to the
249: * name of a public method that takes an ActionEvent parameter and returns
250: * void.</p>
251: */
252: public javax.faces.el.MethodBinding getActionListener() {
253: if (this .actionListener != null) {
254: return this .actionListener;
255: }
256: ValueBinding _vb = getValueBinding("actionListener");
257: if (_vb != null) {
258: return (javax.faces.el.MethodBinding) _vb
259: .getValue(getFacesContext());
260: }
261: return null;
262: }
263:
264: /**
265: * <p>Use the actionListener attribute to cause the hyperlink to fire an
266: * event. The value must be an EL expression and it must evaluate to the
267: * name of a public method that takes an ActionEvent parameter and returns
268: * void.</p>
269: * @see #getActionListener()
270: */
271: public void setActionListener(
272: javax.faces.el.MethodBinding actionListener) {
273: this .actionListener = actionListener;
274: }
275:
276: // lite
277: private boolean lite = false;
278: private boolean lite_set = false;
279:
280: /**
281: * <p>Render a style of tabs that isn't so visually "heavy". This property
282: * must be used in conjunction with the "mini" property set to true
283: * in order to work.</p>
284: */
285: public boolean isLite() {
286: if (this .lite_set) {
287: return this .lite;
288: }
289: ValueBinding _vb = getValueBinding("lite");
290: if (_vb != null) {
291: Object _result = _vb.getValue(getFacesContext());
292: if (_result == null) {
293: return false;
294: } else {
295: return ((Boolean) _result).booleanValue();
296: }
297: }
298: return false;
299: }
300:
301: /**
302: * <p>Render a style of tabs that isn't so visually "heavy". This property
303: * must be used in conjunction with the "mini" property set to true
304: * in order to work.</p>
305: * @see #isLite()
306: */
307: public void setLite(boolean lite) {
308: this .lite = lite;
309: this .lite_set = true;
310: }
311:
312: // mini
313: private boolean mini = false;
314: private boolean mini_set = false;
315:
316: /**
317: * <p>Specify "true" if this TabSet should have the mini style</p>
318: */
319: public boolean isMini() {
320: if (this .mini_set) {
321: return this .mini;
322: }
323: ValueBinding _vb = getValueBinding("mini");
324: if (_vb != null) {
325: Object _result = _vb.getValue(getFacesContext());
326: if (_result == null) {
327: return false;
328: } else {
329: return ((Boolean) _result).booleanValue();
330: }
331: }
332: return false;
333: }
334:
335: /**
336: * <p>Specify "true" if this TabSet should have the mini style</p>
337: * @see #isMini()
338: */
339: public void setMini(boolean mini) {
340: this .mini = mini;
341: this .mini_set = true;
342: }
343:
344: // selected
345: private String selected = null;
346:
347: /**
348: * <p>The id of the selected tab</p>
349: */
350: public String getSelected() {
351: if (this .selected != null) {
352: return this .selected;
353: }
354: ValueBinding _vb = getValueBinding("selected");
355: if (_vb != null) {
356: return (String) _vb.getValue(getFacesContext());
357: }
358: return null;
359: }
360:
361: /**
362: * <p>The id of the selected tab</p>
363: * @see #getSelected()
364: */
365: public void setSelected(String selected) {
366: this .selected = selected;
367: }
368:
369: // style
370: private String style = null;
371:
372: /**
373: * <p>CSS style(s) to be applied when this component is rendered.</p>
374: */
375: public String getStyle() {
376: if (this .style != null) {
377: return this .style;
378: }
379: ValueBinding _vb = getValueBinding("style");
380: if (_vb != null) {
381: return (String) _vb.getValue(getFacesContext());
382: }
383: return null;
384: }
385:
386: /**
387: * <p>CSS style(s) to be applied when this component is rendered.</p>
388: * @see #getStyle()
389: */
390: public void setStyle(String style) {
391: this .style = style;
392: }
393:
394: // styleClass
395: private String styleClass = null;
396:
397: /**
398: * <p>CSS style class(es) to be applied when this component is rendered.</p>
399: */
400: public String getStyleClass() {
401: if (this .styleClass != null) {
402: return this .styleClass;
403: }
404: ValueBinding _vb = getValueBinding("styleClass");
405: if (_vb != null) {
406: return (String) _vb.getValue(getFacesContext());
407: }
408: return null;
409: }
410:
411: /**
412: * <p>CSS style class(es) to be applied when this component is rendered.</p>
413: * @see #getStyleClass()
414: */
415: public void setStyleClass(String styleClass) {
416: this .styleClass = styleClass;
417: }
418:
419: // visible
420: private boolean visible = false;
421: private boolean visible_set = false;
422:
423: /**
424: * <p>Use the visible attribute to indicate whether the component should be
425: * viewable by the user in the rendered HTML page. If set to false, the
426: * HTML code for the component is present in the page, but the component
427: * is hidden with style attributes. By default, visible is set to true, so
428: * HTML for the component HTML is included and visible to the user. If the
429: * component is not visible, it can still be processed on subsequent form
430: * submissions because the HTML is present.</p>
431: */
432: public boolean isVisible() {
433: if (this .visible_set) {
434: return this .visible;
435: }
436: ValueBinding _vb = getValueBinding("visible");
437: if (_vb != null) {
438: Object _result = _vb.getValue(getFacesContext());
439: if (_result == null) {
440: return false;
441: } else {
442: return ((Boolean) _result).booleanValue();
443: }
444: }
445: return true;
446: }
447:
448: /**
449: * <p>Use the visible attribute to indicate whether the component should be
450: * viewable by the user in the rendered HTML page. If set to false, the
451: * HTML code for the component is present in the page, but the component
452: * is hidden with style attributes. By default, visible is set to true, so
453: * HTML for the component HTML is included and visible to the user. If the
454: * component is not visible, it can still be processed on subsequent form
455: * submissions because the HTML is present.</p>
456: * @see #isVisible()
457: */
458: public void setVisible(boolean visible) {
459: this .visible = visible;
460: this .visible_set = true;
461: }
462:
463: /**
464: * <p>Restore the state of this component.</p>
465: */
466: public void restoreState(FacesContext _context, Object _state) {
467: Object _values[] = (Object[]) _state;
468: super .restoreState(_context, _values[0]);
469: this .actionListener = (javax.faces.el.MethodBinding) restoreAttachedState(
470: _context, _values[1]);
471: this .lite = ((Boolean) _values[2]).booleanValue();
472: this .lite_set = ((Boolean) _values[3]).booleanValue();
473: this .mini = ((Boolean) _values[4]).booleanValue();
474: this .mini_set = ((Boolean) _values[5]).booleanValue();
475: this .selected = (String) _values[6];
476: this .style = (String) _values[7];
477: this .styleClass = (String) _values[8];
478: this .visible = ((Boolean) _values[9]).booleanValue();
479: this .visible_set = ((Boolean) _values[10]).booleanValue();
480: }
481:
482: /**
483: * <p>Save the state of this component.</p>
484: */
485: public Object saveState(FacesContext _context) {
486: Object _values[] = new Object[11];
487: _values[0] = super .saveState(_context);
488: _values[1] = saveAttachedState(_context, actionListener);
489: _values[2] = this .lite ? Boolean.TRUE : Boolean.FALSE;
490: _values[3] = this .lite_set ? Boolean.TRUE : Boolean.FALSE;
491: _values[4] = this .mini ? Boolean.TRUE : Boolean.FALSE;
492: _values[5] = this .mini_set ? Boolean.TRUE : Boolean.FALSE;
493: _values[6] = this .selected;
494: _values[7] = this .style;
495: _values[8] = this .styleClass;
496: _values[9] = this .visible ? Boolean.TRUE : Boolean.FALSE;
497: _values[10] = this.visible_set ? Boolean.TRUE : Boolean.FALSE;
498: return _values;
499: }
500:
501: }
|