Clover coverage report - Code Coverage for tapestry-contrib release 4.0-alpha-3
Coverage timestamp: Mon May 16 2005 09:12:41 EDT
file stats: LOC: 164   Methods: 11
NCLOC: 112   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
SimpleTableColumnComponent.java 0% 0% 0% 0%
coverage
 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.inserted;
 16   
 
 17   
 import org.apache.tapestry.BaseComponent;
 18   
 import org.apache.tapestry.IAsset;
 19   
 import org.apache.tapestry.IRequestCycle;
 20   
 import org.apache.tapestry.contrib.table.components.TableColumns;
 21   
 import org.apache.tapestry.contrib.table.model.ITableColumn;
 22   
 import org.apache.tapestry.contrib.table.model.ITableModel;
 23   
 import org.apache.tapestry.contrib.table.model.ITableModelSource;
 24   
 import org.apache.tapestry.contrib.table.model.ITableRendererListener;
 25   
 import org.apache.tapestry.contrib.table.model.ITableSortingState;
 26   
 import org.apache.tapestry.contrib.table.model.simple.SimpleTableColumn;
 27   
 import org.apache.tapestry.event.PageDetachListener;
 28   
 import org.apache.tapestry.event.PageEvent;
 29   
 import org.apache.tapestry.util.ComponentAddress;
 30   
 
 31   
 /**
 32   
  * A component that renders the default column header.
 33   
  * 
 34   
  * If the current column is sortable, it renders the header as a link.
 35   
  * Clicking on the link causes the table to be sorted on that column.
 36   
  * Clicking on the link again causes the sorting order to be reversed.
 37   
  * 
 38   
  * @author mindbridge
 39   
  */
 40   
 public abstract class SimpleTableColumnComponent
 41   
     extends BaseComponent
 42   
     implements ITableRendererListener, PageDetachListener
 43   
 {
 44   
     // transient
 45   
     private ITableColumn m_objColumn;
 46   
     private ITableModelSource m_objModelSource;
 47   
 
 48  0
     public SimpleTableColumnComponent()
 49   
     {
 50  0
         init();
 51   
     }
 52   
 
 53   
     /**
 54   
      * @see org.apache.tapestry.event.PageDetachListener#pageDetached(PageEvent)
 55   
      */
 56  0
     public void pageDetached(PageEvent arg0)
 57   
     {
 58  0
         init();
 59   
     }
 60   
 
 61  0
     private void init()
 62   
     {
 63  0
         m_objColumn = null;
 64  0
         m_objModelSource = null;
 65   
     }
 66   
 
 67   
 
 68   
     /**
 69   
      * @see org.apache.tapestry.contrib.table.model.ITableRendererListener#initializeRenderer(IRequestCycle, ITableModelSource, ITableColumn, Object)
 70   
      */
 71  0
     public void initializeRenderer(
 72   
         IRequestCycle objCycle,
 73   
         ITableModelSource objSource,
 74   
         ITableColumn objColumn,
 75   
         Object objRow)
 76   
     {
 77  0
         m_objModelSource = objSource;
 78  0
         m_objColumn = objColumn;
 79   
     }
 80   
 
 81  0
     public ITableModel getTableModel()
 82   
     {
 83  0
         return m_objModelSource.getTableModel();
 84   
     }
 85   
 
 86  0
     public boolean getColumnSorted()
 87   
     {
 88  0
         return m_objColumn.getSortable();
 89   
     }
 90   
 
 91  0
     public String getDisplayName()
 92   
     {
 93  0
         if (m_objColumn instanceof SimpleTableColumn) {
 94  0
             SimpleTableColumn objSimpleColumn = (SimpleTableColumn) m_objColumn;
 95  0
             return objSimpleColumn.getDisplayName();
 96   
         }
 97  0
         return m_objColumn.getColumnName();
 98   
     }
 99   
 
 100  0
     public boolean getIsSorted()
 101   
     {
 102  0
         ITableSortingState objSortingState = getTableModel().getSortingState();
 103  0
         String strSortColumn = objSortingState.getSortColumn();
 104  0
         return m_objColumn.getColumnName().equals(strSortColumn);
 105   
     }
 106   
 
 107  0
     public IAsset getSortImage()
 108   
     {
 109  0
         IAsset objImageAsset;
 110   
 
 111  0
         IRequestCycle objCycle = getPage().getRequestCycle();
 112  0
         ITableSortingState objSortingState = getTableModel().getSortingState();
 113  0
         if (objSortingState.getSortOrder()
 114   
             == ITableSortingState.SORT_ASCENDING)
 115   
         {
 116  0
             objImageAsset =
 117   
                 (IAsset) objCycle.getAttribute(
 118   
                     TableColumns.TABLE_COLUMN_ARROW_UP_ATTRIBUTE);
 119  0
             if (objImageAsset == null)
 120  0
                 objImageAsset = getAsset("sortUp");
 121   
         }
 122   
         else
 123   
         {
 124  0
             objImageAsset =
 125   
                 (IAsset) objCycle.getAttribute(
 126   
                     TableColumns.TABLE_COLUMN_ARROW_DOWN_ATTRIBUTE);
 127  0
             if (objImageAsset == null)
 128  0
                 objImageAsset = getAsset("sortDown");
 129   
         }
 130   
 
 131  0
         return objImageAsset;
 132   
     }
 133   
 
 134  0
     public Object[] getColumnSelectedParameters()
 135   
     {
 136  0
         return new Object[] {
 137   
             new ComponentAddress(m_objModelSource),
 138   
             m_objColumn.getColumnName()};
 139   
     }
 140   
 
 141  0
     public void columnSelected(IRequestCycle objCycle)
 142   
     {
 143  0
         Object[] arrArgs = objCycle.getListenerParameters();
 144  0
         ComponentAddress objAddr = (ComponentAddress) arrArgs[0];
 145  0
         String strColumnName = (String) arrArgs[1];
 146   
 
 147  0
         ITableModelSource objSource =
 148   
             (ITableModelSource) objAddr.findComponent(objCycle);
 149  0
         ITableModel objModel = objSource.getTableModel();
 150   
 
 151  0
         ITableSortingState objState = objModel.getSortingState();
 152  0
         if (strColumnName.equals(objState.getSortColumn()))
 153  0
             objState.setSortColumn(strColumnName, !objState.getSortOrder());
 154   
         else
 155  0
             objState.setSortColumn(
 156   
                 strColumnName,
 157   
                 ITableSortingState.SORT_ASCENDING);
 158   
 
 159   
         // ensure that the change is saved
 160  0
         objSource.fireObservedStateChange();
 161   
     }
 162   
 
 163   
 }
 164