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