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.util.descriptors;
042:
043: import java.io.IOException;
044: import java.util.ArrayList;
045: import java.util.HashMap;
046: import java.util.Iterator;
047: import java.util.List;
048: import java.util.Map;
049:
050: import javax.faces.context.FacesContext;
051: import javax.faces.context.ResponseWriter;
052: import javax.faces.component.UIColumn;
053: import javax.faces.component.UIComponent;
054: import javax.faces.component.UIData;
055: import javax.faces.component.UIViewRoot;
056: import javax.faces.render.Renderer;
057:
058: /**
059: * <P> This class defines the descriptor for LayoutFacet. A LayoutFacet
060: * descriptor provides information needed to attempt to obtain a Facet
061: * from the UIComponent. If the Facet doesn't exist, it also has the
062: * opportunity to provide a "default" in place of the facet.</P>
063: *
064: * @author Ken Paulsen (ken.paulsen@sun.com)
065: */
066: public class LayoutFacet extends LayoutElementBase implements
067: LayoutElement {
068:
069: /**
070: * Constructor
071: */
072: public LayoutFacet(LayoutElement parent, String id) {
073: super (parent, id);
074: }
075:
076: /**
077: * <p> Returns whether this LayoutFacet should be rendered. When this
078: * component is used to specify an actual facet (i.e. specifies a
079: * <code>UIComponent</code>), it should not be rendred. When it
080: * defines a place holder for a facet, then it should be rendered.</p>
081: *
082: * @return true if {@link #encodeThis(FacesContext, UIComponent)} should
083: * execute
084: */
085: public boolean isRendered() {
086: return _rendered;
087: }
088:
089: /**
090: *
091: */
092: public void setRendered(boolean render) {
093: _rendered = render;
094: }
095:
096: /**
097: * <P>This method looks for the facet on the component. If found, it
098: * renders it and returns false (so children will not be rendered). If
099: * not found, it returns true so that children will be rendered.
100: * Children of a LayoutFacet represent the default value for the
101: * Facet.</P>
102: *
103: * @param context The FacesContext
104: * @param parent The parent UIComponent
105: *
106: * @return true if children are to be rendered, false otherwise.
107: */
108: protected boolean encodeThis(FacesContext context,
109: UIComponent component) throws IOException {
110: // Make sure we are supposed to render facets
111: if (!isRendered()) {
112: return false;
113: }
114:
115: // Look for Facet
116: component = (UIComponent) component.getFacets().get(
117: getId(context, component));
118: if (component != null) {
119: // Found Facet, Display UIComponent
120: encodeChild(context, component);
121:
122: // Return false so the default won't be rendered
123: return false;
124: }
125:
126: // Return true so that the default will be rendered
127: return true;
128: }
129:
130: private boolean _rendered = true;
131: }
|