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