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 com.sun.data.provider.SortCriteria;
044: import com.sun.rave.web.ui.theme.Theme;
045: import com.sun.rave.web.ui.util.LogUtil;
046: import com.sun.rave.web.ui.util.ThemeUtilities;
047:
048: import java.io.IOException;
049:
050: import javax.faces.context.FacesContext;
051: import javax.faces.component.UIComponent;
052: import javax.faces.component.NamingContainer;
053:
054: /**
055: * Component that represents a table footer.
056: * <p>
057: * Note: Column headers and footers are rendered by TableRowGroupRenderer. Table
058: * column footers are rendered by TableRenderer.
059: * </p><p>
060: * Note: To see the messages logged by this class, set the following global
061: * defaults in your JDK's "jre/lib/logging.properties" file.
062: * </p><p><pre>
063: * java.util.logging.ConsoleHandler.level = FINE
064: * com.sun.rave.web.ui.component.TableFooter.level = FINE
065: * </pre></p>
066: */
067: public class TableFooter extends TableFooterBase implements
068: NamingContainer {
069: // The Table ancestor enclosing this component.
070: private Table table = null;
071:
072: // The TableColumn ancestor enclosing this component.
073: private TableColumn tableColumn = null;
074:
075: // The TableRowGroup ancestor enclosing this component.
076: private TableRowGroup tableRowGroup = null;
077:
078: // Sort level for this component.
079: private int sortLevel = -1;
080:
081: /** Default constructor */
082: public TableFooter() {
083: super ();
084: }
085:
086: // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
087: // Child methods
088: // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
089:
090: /**
091: * Helper method to get sort level for this component.
092: *
093: * @return The sort level or 0 if sort does not apply.
094: */
095: public int getSortLevel() {
096: if (sortLevel == -1) {
097: TableColumn col = getTableColumnAncestor();
098: TableRowGroup group = getTableRowGroupAncestor();
099: if (col != null && group != null) {
100: sortLevel = group.getSortLevel(col.getSortCriteria());
101: } else {
102: log("getSortLevel", //NOI18N
103: "Cannot obtain sort level, TableColumn or TableRowGroup is null"); //NOI18N
104: }
105: }
106: return sortLevel;
107: }
108:
109: /**
110: * Get the closest Table ancestor that encloses this component.
111: *
112: * @return The Table ancestor.
113: */
114: public Table getTableAncestor() {
115: if (table == null) {
116: UIComponent component = this ;
117: while (component != null) {
118: component = component.getParent();
119: if (component instanceof Table) {
120: table = (Table) component;
121: break;
122: }
123: }
124: }
125: return table;
126: }
127:
128: /**
129: * Get the closest TableColumn ancestor that encloses this component.
130: *
131: * @return The TableColumn ancestor.
132: */
133: public TableColumn getTableColumnAncestor() {
134: if (tableColumn == null) {
135: UIComponent component = this ;
136: while (component != null) {
137: component = component.getParent();
138: if (component instanceof TableColumn) {
139: tableColumn = (TableColumn) component;
140: break;
141: }
142: }
143: }
144: return tableColumn;
145: }
146:
147: /**
148: * Get the closest TableRowGroup ancestor that encloses this component.
149: *
150: * @return The TableRowGroup ancestor.
151: */
152: public TableRowGroup getTableRowGroupAncestor() {
153: if (tableRowGroup == null) {
154: UIComponent component = this ;
155: while (component != null) {
156: component = component.getParent();
157: if (component instanceof TableRowGroup) {
158: tableRowGroup = (TableRowGroup) component;
159: break;
160: }
161: }
162: }
163: return tableRowGroup;
164: }
165:
166: // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
167: // UIComponent methods
168: // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
169:
170: /**
171: * If the rendered property is true, render the begining of the current
172: * state of this UIComponent to the response contained in the specified
173: * FacesContext.
174: *
175: * If a Renderer is associated with this UIComponent, the actual encoding
176: * will be delegated to Renderer.encodeBegin(FacesContext, UIComponent).
177: *
178: * @param context FacesContext for the current request.
179: *
180: * @exception IOException if an input/output error occurs while rendering.
181: * @exception NullPointerException if FacesContext is null.
182: */
183: public void encodeBegin(FacesContext context) throws IOException {
184: // Clear cached variables -- bugtraq #6300020.
185: table = null;
186: tableColumn = null;
187: tableRowGroup = null;
188: sortLevel = -1;
189: super .encodeBegin(context);
190: }
191:
192: // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
193: // Private methods
194: // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
195:
196: /**
197: * Helper method to get Theme objects.
198: *
199: * @return The current theme.
200: */
201: private Theme getTheme() {
202: return ThemeUtilities.getTheme(getFacesContext());
203: }
204:
205: /**
206: * Log fine messages.
207: */
208: private void log(String method, String message) {
209: // Get class.
210: Class clazz = this .getClass();
211: if (LogUtil.fineEnabled(clazz)) {
212: // Log method name and message.
213: LogUtil.fine(clazz, clazz.getName() + "." + method + ": "
214: + message); //NOI18N
215: }
216: }
217: }
|