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:
045: import java.util.ArrayList;
046: import java.util.Iterator;
047: import java.util.List;
048:
049: import javax.faces.context.FacesContext;
050: import javax.faces.component.UIComponent;
051:
052: /**
053: *
054: * @author Ken Paulsen
055: */
056: public class PropertySheetSection extends PropertySheetSectionBase {
057:
058: public PropertySheetSection() {
059: super ();
060: }
061:
062: /**
063: * <p> This method calculates the number of visible child
064: * {@link PropertySheetSection} or {@link Property}
065: * <code>UIComponent</code>s. A {@link PropertySheetSection}
066: * or {@link Property} can be made not visible by setting their
067: * rendered property to false.</p>
068: *
069: * @return The number of visible {@link PropertySheetSection} children.
070: */
071: public int getSectionChildrenCount() {
072: // Set the output value
073: return getVisibleSectionChildren().size();
074: }
075:
076: /**
077: * <p> This method creates a <code>List</code> of visible (rendered=true)
078: * child {@link PropertySheetSection} or {@link Property}
079: * components.</p>
080: *
081: * @return <code>List</code> of child {@link PropertySheetSection} or
082: * {@link Property} <code>UIComponent</code> objects.
083: */
084: public List getVisibleSectionChildren() {
085: int numChildren = getChildCount();
086:
087: // See if we've already figured this out
088: if ((_visibleChildren != null) && (_childCount == numChildren)) {
089: return _visibleChildren;
090: }
091: _childCount = numChildren;
092:
093: // Make sure we have children
094: if (numChildren == 0) {
095: // Avoid creating child UIComponent List by checking for 0 sections
096: _visibleChildren = new ArrayList(0);
097: return _visibleChildren;
098: }
099:
100: // Add the visible sections to the result List
101: UIComponent child = null;
102: _visibleChildren = new ArrayList();
103: Iterator it = getChildren().iterator();
104: while (it.hasNext()) {
105: child = (UIComponent) it.next();
106: if (((child instanceof Property) || (child instanceof PropertySheetSection))
107: && child.isRendered()) {
108: _visibleChildren.add(child);
109: }
110: }
111:
112: // Return the List
113: return _visibleChildren;
114: }
115:
116: /**
117: * <p> Used to cache the visible children.</p>
118: */
119: private transient List _visibleChildren = null;
120: private transient int _childCount = -1;
121:
122: // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
123: // UIComponent methods
124: // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
125:
126: /**
127: * If the rendered property is true, render the begining of the current
128: * state of this UIComponent to the response contained in the specified
129: * FacesContext.
130: *
131: * If a Renderer is associated with this UIComponent, the actual encoding
132: * will be delegated to Renderer.encodeBegin(FacesContext, UIComponent).
133: *
134: * @param context FacesContext for the current request.
135: *
136: * @exception IOException if an input/output error occurs while rendering.
137: * @exception NullPointerException if FacesContext is null.
138: */
139: public void encodeBegin(FacesContext context) throws IOException {
140: // Clear cached variables -- bugtraq #6270214.
141: _visibleChildren = null;
142: _childCount = -1;
143: super.encodeBegin(context);
144: }
145: }
|