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: 137   Methods: 7
NCLOC: 89   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
SimpleTableColumnFormComponent.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   
 
 28   
 /**
 29   
  * A component that renders the default column header in a form.
 30   
  * 
 31   
  * If the current column is sortable, it renders the header as a link.
 32   
  * Clicking on the link causes the table to be sorted on that column.
 33   
  * Clicking on the link again causes the sorting order to be reversed.
 34   
  * 
 35   
  * This component renders links that cause the form to be submitted. 
 36   
  * This ensures that the updated data in the other form fields is preserved. 
 37   
  * 
 38   
  * @author mindbridge
 39   
  */
 40   
 public abstract class SimpleTableColumnFormComponent
 41   
     extends BaseComponent
 42   
     implements ITableRendererListener
 43   
 {
 44   
 
 45   
     public abstract ITableColumn getTableColumn();
 46   
     public abstract void setTableColumn(ITableColumn objColumn);
 47   
 
 48   
     public abstract ITableModelSource getTableModelSource();
 49   
     public abstract void setTableModelSource(ITableModelSource objSource);
 50   
 
 51   
     public abstract String getSelectedColumnName();
 52   
 
 53   
     /**
 54   
      * @see org.apache.tapestry.contrib.table.model.ITableRendererListener#initializeRenderer(IRequestCycle, ITableModelSource, ITableColumn, Object)
 55   
      */
 56  0
     public void initializeRenderer(
 57   
         IRequestCycle objCycle,
 58   
         ITableModelSource objSource,
 59   
         ITableColumn objColumn,
 60   
         Object objRow)
 61   
     {
 62  0
         setTableModelSource(objSource);
 63  0
         setTableColumn(objColumn);
 64   
     }
 65   
 
 66  0
     public ITableModel getTableModel()
 67   
     {
 68  0
         return getTableModelSource().getTableModel();
 69   
     }
 70   
 
 71  0
     public boolean getColumnSorted()
 72   
     {
 73  0
         return getTableColumn().getSortable();
 74   
     }
 75   
 
 76  0
     public String getDisplayName()
 77   
     {
 78  0
         ITableColumn objColumn = getTableColumn();
 79   
         
 80  0
         if (objColumn instanceof SimpleTableColumn) {
 81  0
             SimpleTableColumn objSimpleColumn = (SimpleTableColumn) objColumn;
 82  0
             return objSimpleColumn.getDisplayName();
 83   
         }
 84  0
         return objColumn.getColumnName();
 85   
     }
 86   
 
 87  0
     public boolean getIsSorted()
 88   
     {
 89  0
         ITableSortingState objSortingState = getTableModel().getSortingState();
 90  0
         String strSortColumn = objSortingState.getSortColumn();
 91  0
         return getTableColumn().getColumnName().equals(strSortColumn);
 92   
     }
 93   
 
 94  0
     public IAsset getSortImage()
 95   
     {
 96  0
         IAsset objImageAsset;
 97   
 
 98  0
         IRequestCycle objCycle = getPage().getRequestCycle();
 99  0
         ITableSortingState objSortingState = getTableModel().getSortingState();
 100  0
         if (objSortingState.getSortOrder()
 101   
             == ITableSortingState.SORT_ASCENDING)
 102   
         {
 103  0
             objImageAsset =
 104   
                 (IAsset) objCycle.getAttribute(
 105   
                     TableColumns.TABLE_COLUMN_ARROW_UP_ATTRIBUTE);
 106  0
             if (objImageAsset == null)
 107  0
                 objImageAsset = getAsset("sortUp");
 108   
         }
 109   
         else
 110   
         {
 111  0
             objImageAsset =
 112   
                 (IAsset) objCycle.getAttribute(
 113   
                     TableColumns.TABLE_COLUMN_ARROW_DOWN_ATTRIBUTE);
 114  0
             if (objImageAsset == null)
 115  0
                 objImageAsset = getAsset("sortDown");
 116   
         }
 117   
 
 118  0
         return objImageAsset;
 119   
     }
 120   
 
 121  0
     public void columnSelected(IRequestCycle objCycle)
 122   
     {
 123  0
         String strColumnName = getSelectedColumnName();
 124  0
         ITableSortingState objState = getTableModel().getSortingState();
 125  0
         if (strColumnName.equals(objState.getSortColumn()))
 126  0
             objState.setSortColumn(strColumnName, !objState.getSortOrder());
 127   
         else
 128  0
             objState.setSortColumn(
 129   
                 strColumnName,
 130   
                 ITableSortingState.SORT_ASCENDING);
 131   
 
 132   
         // ensure that the change is saved
 133  0
         getTableModelSource().fireObservedStateChange();
 134   
     }
 135   
 
 136   
 }
 137