Coverage Report - org.apache.tapestry.contrib.table.components.TableRows
 
Classes in this File Line Coverage Branch Coverage Complexity
TableRows
0%
0/25
0%
0/6
1.5
 
 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.IBinding;
 20  
 import org.apache.tapestry.IMarkupWriter;
 21  
 import org.apache.tapestry.IRequestCycle;
 22  
 import org.apache.tapestry.contrib.table.model.IFullTableModel;
 23  
 import org.apache.tapestry.contrib.table.model.ITableModel;
 24  
 import org.apache.tapestry.contrib.table.model.ITableRowSource;
 25  
 
 26  
 /**
 27  
  * A low level Table component that generates the rows of the current page in
 28  
  * the table. This component must be wrapped by
 29  
  * {@link org.apache.tapestry.contrib.table.components.TableView}.
 30  
  * <p>
 31  
  * The component iterates over the rows of the current page in the table. The
 32  
  * rows are wrapped in 'tr' tags by default. You can define columns manually
 33  
  * within, or you can use
 34  
  * {@link org.apache.tapestry.contrib.table.components.TableValues} to generate
 35  
  * the columns automatically.
 36  
  * <p>
 37  
  * Please see the Component Reference for details on how to use this component. [<a
 38  
  * href="../../../../../../../ComponentReference/contrib.TableRows.html">Component
 39  
  * Reference</a>]
 40  
  * 
 41  
  * @author mindbridge
 42  
  */
 43  0
 public abstract class TableRows extends AbstractTableViewComponent implements
 44  
         ITableRowSource
 45  
 {
 46  
 
 47  
     // Transient
 48  0
     private Object m_objTableRow = null;
 49  
     private int m_nTableIndex;
 50  
     
 51  
     // Parameters
 52  
     public abstract Object getFullSourceParameter();
 53  
 
 54  
     /**
 55  
      * Returns the currently rendered table row. You can call this method to
 56  
      * obtain the current row.
 57  
      * 
 58  
      * @return Object the current table row
 59  
      */
 60  
     public Object getTableRow()
 61  
     {
 62  0
         return m_objTableRow;
 63  
     }
 64  
 
 65  
     /**
 66  
      * Sets the currently rendered table row. This method is for internal use
 67  
      * only.
 68  
      * 
 69  
      * @param tableRow
 70  
      *            The current table row
 71  
      */
 72  
     public void setTableRow(Object tableRow)
 73  
     {
 74  0
         m_objTableRow = tableRow;
 75  
 
 76  0
         IBinding objRowBinding = getBinding("row");
 77  0
         if (objRowBinding != null) objRowBinding.setObject(tableRow);
 78  0
     }
 79  
 
 80  
     /**
 81  
      * Returns the index of the currently rendered table row. You can call this
 82  
      * method to obtain the index of the current row.
 83  
      * 
 84  
      * @return int the current table index
 85  
      */
 86  
     public int getTableIndex()
 87  
     {
 88  0
         return m_nTableIndex;
 89  
     }
 90  
 
 91  
     /**
 92  
      * Sets the index of the currently rendered table row. This method is for
 93  
      * internal use only.
 94  
      * 
 95  
      * @param tableIndex
 96  
      *            The index of the current table row
 97  
      */
 98  
     public void setTableIndex(int tableIndex)
 99  
     {
 100  0
         m_nTableIndex = tableIndex;
 101  
 
 102  0
         IBinding objIndexBinding = getBinding("index");
 103  0
         if (objIndexBinding != null)
 104  0
             objIndexBinding.setObject(new Integer(tableIndex));
 105  0
     }
 106  
 
 107  
     /**
 108  
      * Get the list of all table rows to be displayed on this page.
 109  
      * 
 110  
      * @return an iterator of all table rows
 111  
      */
 112  
     public Iterator getTableRowsIterator()
 113  
     {
 114  0
         ITableModel objTableModel = getTableModelSource().getTableModel();
 115  0
         return objTableModel.getCurrentPageRows();
 116  
     }
 117  
 
 118  
     public Object getFullSource()
 119  
     {
 120  0
         ITableModel objTableModel = getTableModelSource().getTableModel();
 121  0
         if (objTableModel instanceof IFullTableModel)
 122  0
             return ((IFullTableModel) objTableModel).getRows();
 123  0
         return getFullSourceParameter();
 124  
     }
 125  
 
 126  
     /**
 127  
      * @see org.apache.tapestry.BaseComponent#renderComponent(IMarkupWriter,
 128  
      *      IRequestCycle)
 129  
      */
 130  
     protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle)
 131  
     {
 132  0
         Object objOldValue = cycle
 133  
                 .getAttribute(ITableRowSource.TABLE_ROW_SOURCE_ATTRIBUTE);
 134  0
         cycle.setAttribute(ITableRowSource.TABLE_ROW_SOURCE_ATTRIBUTE, this);
 135  
 
 136  0
         super.renderComponent(writer, cycle);
 137  
 
 138  0
         cycle.setAttribute(ITableRowSource.TABLE_ROW_SOURCE_ATTRIBUTE,
 139  
                 objOldValue);
 140  
 
 141  
         // set the current row to null when the component is not active
 142  0
         m_objTableRow = null;
 143  0
     }
 144  
 
 145  
 }