Coverage Report - org.apache.tapestry.contrib.table.components.TableColumns
 
Classes in this File Line Coverage Branch Coverage Complexity
TableColumns
0% 
0% 
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 java.util.Iterator;
 18  
 
 19  
 import org.apache.tapestry.IAsset;
 20  
 import org.apache.tapestry.IMarkupWriter;
 21  
 import org.apache.tapestry.IRender;
 22  
 import org.apache.tapestry.IRequestCycle;
 23  
 import org.apache.tapestry.contrib.table.model.ITableColumn;
 24  
 import org.apache.tapestry.contrib.table.model.ITableColumnModel;
 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")) setColumn(tableColumn);
 86  0
     }
 87  
 
 88  
     /**
 89  
      * Get the list of all table columns to be displayed.
 90  
      * 
 91  
      * @return an iterator of all table columns
 92  
      */
 93  
     public Iterator getTableColumnIterator()
 94  
     {
 95  0
         ITableColumnModel objColumnModel = getTableModelSource()
 96  
                 .getTableModel().getColumnModel();
 97  0
         return objColumnModel.getColumns();
 98  
     }
 99  
 
 100  
     /**
 101  
      * Returns the renderer to be used to generate the header of the current
 102  
      * column.
 103  
      * 
 104  
      * @return the header renderer of the current column
 105  
      */
 106  
     public IRender getTableColumnRenderer()
 107  
     {
 108  0
         return getTableColumn().getColumnRenderer(getPage().getRequestCycle(),
 109  
                 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")) return getColumnClassParameter();
 124  
 
 125  0
         return getTableColumn().getColumnName() + TABLE_COLUMN_CSS_CLASS_SUFFIX;
 126  
     }
 127  
 
 128  
     /**
 129  
      * @see org.apache.tapestry.BaseComponent#renderComponent(IMarkupWriter,
 130  
      *      IRequestCycle)
 131  
      */
 132  
     protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle)
 133  
     {
 134  0
         Object oldValueUp = cycle.getAttribute(TABLE_COLUMN_ARROW_UP_ATTRIBUTE);
 135  0
         Object oldValueDown = cycle
 136  
                 .getAttribute(TABLE_COLUMN_ARROW_DOWN_ATTRIBUTE);
 137  
 
 138  
         try
 139  
         {
 140  0
             cycle.setAttribute(TABLE_COLUMN_ARROW_UP_ATTRIBUTE,
 141  
                     getArrowUpAsset());
 142  0
             cycle.setAttribute(TABLE_COLUMN_ARROW_DOWN_ATTRIBUTE,
 143  
                     getArrowDownAsset());
 144  
 
 145  0
             super.renderComponent(writer, cycle);
 146  
         }
 147  
         finally
 148  
         {
 149  0
             cycle.setAttribute(TABLE_COLUMN_ARROW_UP_ATTRIBUTE, oldValueUp);
 150  0
             cycle.setAttribute(TABLE_COLUMN_ARROW_DOWN_ATTRIBUTE, oldValueDown);
 151  
 
 152  
             // set the current column to null when the component is not active
 153  0
             m_objTableColumn = null;
 154  0
         }
 155  0
     }
 156  
 
 157  
 }