Coverage Report - org.apache.tapestry.contrib.table.components.TableColumns
 
Classes in this File Line Coverage Branch Coverage Complexity
TableColumns
0%
0/23
0%
0/4
1.3
 
 1  
 // Copyright 2004, 2005 The Apache Software Foundation
 2  
 //
 3  
 // Licensed under the Apache License, Version 2.0 (the "License");
 4  
 // you may not use this file except in compliance with the License.
 5  
 // You may obtain a copy of the License at
 6  
 //
 7  
 //     http://www.apache.org/licenses/LICENSE-2.0
 8  
 //
 9  
 // Unless required by applicable law or agreed to in writing, software
 10  
 // distributed under the License is distributed on an "AS IS" BASIS,
 11  
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12  
 // See the License for the specific language governing permissions and
 13  
 // limitations under the License.
 14  
 
 15  
 package org.apache.tapestry.contrib.table.components;
 16  
 
 17  
 import org.apache.tapestry.IAsset;
 18  
 import org.apache.tapestry.IMarkupWriter;
 19  
 import org.apache.tapestry.IRender;
 20  
 import org.apache.tapestry.IRequestCycle;
 21  
 import org.apache.tapestry.contrib.table.model.ITableColumn;
 22  
 import org.apache.tapestry.contrib.table.model.ITableColumnModel;
 23  
 
 24  
 import java.util.Iterator;
 25  
 
 26  
 /**
 27  
  * A low level Table component that renders the column headers in the table.
 28  
  * This component must be wrapped by
 29  
  * {@link org.apache.tapestry.contrib.table.components.TableView}.
 30  
  * <p>
 31  
  * The component iterates over all column objects in the
 32  
  * {@link org.apache.tapestry.contrib.table.model.ITableColumnModel}and renders
 33  
  * a header for each one of them using the renderer provided by the
 34  
  * getColumnRender() method in
 35  
  * {@link org.apache.tapestry.contrib.table.model.ITableColumn}. The headers
 36  
  * are wrapped in 'th' tags by default.
 37  
  * <p>
 38  
  * Please see the Component Reference for details on how to use this component. [
 39  
  * <a
 40  
  * href="../../../../../../../ComponentReference/contrib.TableColumns.html">Component
 41  
  * Reference </a>]
 42  
  * 
 43  
  * @author mindbridge
 44  
  */
 45  0
 public abstract class TableColumns extends AbstractTableViewComponent
 46  
 {
 47  
 
 48  
     public static final String TABLE_COLUMN_ARROW_UP_ATTRIBUTE = "org.apache.tapestry.contrib.table.components.TableColumns.arrowUp";
 49  
 
 50  
     public static final String TABLE_COLUMN_ARROW_DOWN_ATTRIBUTE = "org.apache.tapestry.contrib.table.components.TableColumns.arrowDown";
 51  
 
 52  
     public static final String TABLE_COLUMN_CSS_CLASS_SUFFIX = "ColumnHeader";
 53  
 
 54  
     // Transient
 55  0
     private ITableColumn m_objTableColumn = null;
 56  
     
 57  
     public abstract IAsset getArrowDownAsset();
 58  
 
 59  
     public abstract IAsset getArrowUpAsset();
 60  
 
 61  
     public abstract void setColumn(ITableColumn column);
 62  
 
 63  
     /**
 64  
      * Returns the currently rendered table column. You can call this method to
 65  
      * obtain the current column.
 66  
      * 
 67  
      * @return ITableColumn the current table column
 68  
      */
 69  
     public ITableColumn getTableColumn()
 70  
     {
 71  0
         return m_objTableColumn;
 72  
     }
 73  
 
 74  
     /**
 75  
      * Sets the currently rendered table column. This method is for internal use
 76  
      * only.
 77  
      * 
 78  
      * @param tableColumn
 79  
      *            The current table column
 80  
      */
 81  
     public void setTableColumn(ITableColumn tableColumn)
 82  
     {
 83  0
         m_objTableColumn = tableColumn;
 84  
 
 85  0
         if (isParameterBound("column"))
 86  0
             setColumn(tableColumn);
 87  0
     }
 88  
 
 89  
     /**
 90  
      * Get the list of all table columns to be displayed.
 91  
      * 
 92  
      * @return an iterator of all table columns
 93  
      */
 94  
     public Iterator getTableColumnIterator()
 95  
     {
 96  0
         ITableColumnModel objColumnModel = getTableModelSource() .getTableModel().getColumnModel();
 97  
         
 98  0
         return objColumnModel.getColumns();
 99  
     }
 100  
 
 101  
     /**
 102  
      * Returns the renderer to be used to generate the header of the current
 103  
      * column.
 104  
      * 
 105  
      * @return the header renderer of the current column
 106  
      */
 107  
     public IRender getTableColumnRenderer()
 108  
     {
 109  0
         return getTableColumn().getColumnRenderer(getPage().getRequestCycle(), getTableModelSource());
 110  
     }
 111  
 
 112  
     public abstract String getColumnClassParameter();
 113  
 
 114  
     /**
 115  
      * Returns the CSS class of the generated table cell. It uses the class
 116  
      * parameter if it has been bound, or the default value of "[column
 117  
      * name]ColumnHeader" otherwise.
 118  
      * 
 119  
      * @return the CSS class of the cell
 120  
      */
 121  
     public String getColumnClass()
 122  
     {
 123  0
         if (isParameterBound("class"))
 124  0
             return getColumnClassParameter();
 125  
 
 126  0
         return getTableColumn().getColumnName() + TABLE_COLUMN_CSS_CLASS_SUFFIX;
 127  
     }
 128  
 
 129  
     /**
 130  
      * @see org.apache.tapestry.BaseComponent#renderComponent(IMarkupWriter,
 131  
      *      IRequestCycle)
 132  
      */
 133  
     protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle)
 134  
     {
 135  0
         Object oldValueUp = cycle.getAttribute(TABLE_COLUMN_ARROW_UP_ATTRIBUTE);
 136  0
         Object oldValueDown = cycle.getAttribute(TABLE_COLUMN_ARROW_DOWN_ATTRIBUTE);
 137  
 
 138  
         try
 139  
         {
 140  0
             cycle.setAttribute(TABLE_COLUMN_ARROW_UP_ATTRIBUTE, getArrowUpAsset());
 141  0
             cycle.setAttribute(TABLE_COLUMN_ARROW_DOWN_ATTRIBUTE, getArrowDownAsset());
 142  
 
 143  0
             super.renderComponent(writer, cycle);
 144  
         }
 145  
         finally
 146  
         {
 147  0
             cycle.setAttribute(TABLE_COLUMN_ARROW_UP_ATTRIBUTE, oldValueUp);
 148  0
             cycle.setAttribute(TABLE_COLUMN_ARROW_DOWN_ATTRIBUTE, oldValueDown);
 149  
 
 150  
             // set the current column to null when the component is not active
 151  0
             m_objTableColumn = null;
 152  0
         }
 153  0
     }
 154  
 
 155  
 }