001 // Copyright 2004, 2005 The Apache Software Foundation
002 //
003 // Licensed under the Apache License, Version 2.0 (the "License");
004 // you may not use this file except in compliance with the License.
005 // You may obtain a copy of the License at
006 //
007 // http://www.apache.org/licenses/LICENSE-2.0
008 //
009 // Unless required by applicable law or agreed to in writing, software
010 // distributed under the License is distributed on an "AS IS" BASIS,
011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012 // See the License for the specific language governing permissions and
013 // limitations under the License.
014
015 package org.apache.tapestry.contrib.table.components;
016
017 import java.util.Iterator;
018
019 import org.apache.tapestry.IBinding;
020 import org.apache.tapestry.IRender;
021 import org.apache.tapestry.IRequestCycle;
022 import org.apache.tapestry.contrib.table.model.ITableColumn;
023 import org.apache.tapestry.contrib.table.model.ITableColumnModel;
024
025 /**
026 * A low level Table component that generates the columns in the current row in the table. This
027 * component must be wrapped by {@link org.apache.tapestry.contrib.table.components.TableRows}.
028 * <p>
029 * The component iterates over the columns in the table and automatically renders the column values
030 * for the current table row. The columns are wrapped in 'td' tags by default. <br>
031 * The column values are rendered using the renderer returned by the getValueRenderer() method in
032 * {@link org.apache.tapestry.contrib.table.model.ITableColumn}.
033 * <p>
034 * Please see the Component Reference for details on how to use this component. [ <a
035 * href="../../../../../../../ComponentReference/contrib.TableValues.html">Component Reference </a>]
036 *
037 * @author mindbridge
038 */
039 public abstract class TableValues extends AbstractTableRowComponent
040 {
041 public static final String TABLE_VALUE_CSS_CLASS_SUFFIX = "ColumnValue";
042
043 // Transient
044 private ITableColumn m_objTableColumn;
045
046 /**
047 * Get the list of all table columns to be displayed.
048 *
049 * @return an iterator of all table columns
050 */
051 public Iterator getTableColumnIterator()
052 {
053 ITableColumnModel objColumnModel = getTableModelSource().getTableModel().getColumnModel();
054 return objColumnModel.getColumns();
055 }
056
057 /**
058 * Returns the currently rendered table column. You can call this method to obtain the current
059 * column.
060 *
061 * @return ITableColumn the current table column
062 */
063 public ITableColumn getTableColumn()
064 {
065 return m_objTableColumn;
066 }
067
068 /**
069 * Sets the currently rendered table column. This method is for internal use only.
070 *
071 * @param tableColumn
072 * The current table column
073 */
074 public void setTableColumn(ITableColumn tableColumn)
075 {
076 m_objTableColumn = tableColumn;
077
078 if (isParameterBound("column"))
079 setColumnParameter(tableColumn);
080 }
081
082 /**
083 * Returns the renderer to be used to generate the appearance of the current column.
084 *
085 * @return the value renderer of the current column
086 */
087 public IRender getTableValueRenderer()
088 {
089 Object objRow = getTableRowSource().getTableRow();
090 return getTableColumn().getValueRenderer(
091 getPage().getRequestCycle(),
092 getTableModelSource(),
093 objRow);
094 }
095
096 /**
097 * Returns the CSS class of the generated table cell. It uses the class parameter if it has been
098 * bound, or the default value of "[column name]ColumnValue" otherwise.
099 *
100 * @return the CSS class of the cell
101 */
102 public String getValueClass()
103 {
104 IBinding classBinding = getBinding("class");
105 if (classBinding != null)
106 return classBinding.getObject(String.class).toString();
107
108 return getTableColumn().getColumnName() + TABLE_VALUE_CSS_CLASS_SUFFIX;
109 }
110
111 /** @since 4.0 */
112 protected void cleanupAfterRender(IRequestCycle cycle)
113 {
114 super.cleanupAfterRender(cycle);
115
116 m_objTableColumn = null;
117
118 }
119
120 /** @since 4.0 */
121
122 public abstract void setColumnParameter(ITableColumn column);
123
124 /** @since 4.0 */
125
126 public abstract String getCellClass();
127 }