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.util.Iterator;
044: import javax.faces.component.UIComponent;
045: import javax.faces.component.NamingContainer;
046: import javax.faces.context.FacesContext;
047:
048: import com.sun.rave.web.ui.event.TabActionListener;
049:
050: /**
051: * Defines a Tab component. Each Tab is intended to be specified as a child
052: * of a Tabs component.
053: *
054: * @author Sean Comerford
055: */
056: public class Tab extends TabBase implements NamingContainer {
057:
058: /** Default constructor */
059: public Tab() {
060: super ();
061:
062: this .addActionListener(new TabActionListener());
063: }
064:
065: /** Construct a tab with the given label */
066: public Tab(String label) {
067: this ();
068: setText(label);
069: }
070:
071: /**
072: * This method returns true if this Tab has any Tab children or false if it
073: * has no children or no children that are Tab instances.
074: *
075: * @return Whether or not any of this Tab's children are Tab components.
076: */
077: public boolean hasTabChildren() {
078: if (getChildCount() > 0) {
079: Iterator i = getChildren().iterator();
080:
081: while (i.hasNext()) {
082: UIComponent kid = (UIComponent) i.next();
083:
084: if (kid instanceof Tab) {
085: return true;
086: }
087: }
088: }
089:
090: return false;
091: }
092:
093: /**
094: * Holds value of property extraStyles.
095: */
096: private String extraStyles;
097:
098: /**
099: * Getter for property extraStyles. This is a private (but publically
100: * exposed method) used internally by the component library
101: * Do not modify it's value
102: * @return Value of property extraStyles.
103: */
104: public String getExtraStyles() {
105:
106: return this .extraStyles;
107: }
108:
109: /**
110: * Setter for property extraStyles. This is a private (but publically
111: * exposed method) used internally by the component library
112: * Do not modify it's value * @param extraStyles New value of property \
113: * extraStyles.
114: */
115: public void setExtraStyles(String extraStyles) {
116:
117: this .extraStyles = extraStyles;
118: }
119:
120: // <RAVE>
121: public void processDecodes(FacesContext context) {
122: Iterator iter = this .getChildren().iterator();
123: boolean isSelected = this .getId()
124: .equals(getSelectedTabId(this ));
125: while (iter.hasNext()) {
126: Object child = iter.next();
127: if (child instanceof Tab) {
128: ((Tab) child).processDecodes(context);
129: } else if ((child instanceof UIComponent) && isSelected) {
130: ((UIComponent) child).processDecodes(context);
131: }
132: }
133: try {
134: decode(context);
135: } catch (RuntimeException e) {
136: context.renderResponse();
137: throw e;
138: }
139: }
140:
141: String getSelectedTabId(Tab tab) {
142: while (tab.getParent() instanceof Tab) {
143: tab = (Tab) tab.getParent();
144: }
145: TabSet tabSet = (TabSet) tab.getParent();
146: return tabSet.getSelected();
147: }
148: // </RAVE>
149:
150: }
|