Coverage Report - org.apache.tapestry.contrib.table.components.inserted.SimpleTableColumnComponent
 
Classes in this File Line Coverage Branch Coverage Complexity
SimpleTableColumnComponent
0%
0/37
0%
0/8
1.455
 
 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  
 import org.apache.tapestry.event.PageDetachListener;
 24  
 import org.apache.tapestry.event.PageEvent;
 25  
 import org.apache.tapestry.util.ComponentAddress;
 26  
 
 27  
 /**
 28  
  * A component that renders the default column header. If the current column is
 29  
  * sortable, it renders the header as a link. Clicking on the link causes the
 30  
  * table to be sorted on that column. Clicking on the link again causes the
 31  
  * sorting order to be reversed.
 32  
  *
 33  
  * @author mindbridge
 34  
  */
 35  
 public abstract class SimpleTableColumnComponent extends BaseComponent
 36  
         implements ITableRendererListener, PageDetachListener
 37  
 {
 38  
 
 39  
     // transient
 40  
     private ITableColumn m_objColumn;
 41  
     private ITableModelSource m_objModelSource;
 42  
 
 43  
     public SimpleTableColumnComponent()
 44  0
     {
 45  0
         init();
 46  0
     }
 47  
 
 48  
     /**
 49  
      * @see org.apache.tapestry.event.PageDetachListener#pageDetached(PageEvent)
 50  
      */
 51  
     public void pageDetached(PageEvent arg0)
 52  
     {
 53  0
         init();
 54  0
     }
 55  
 
 56  
     private void init()
 57  
     {
 58  0
         m_objColumn = null;
 59  0
         m_objModelSource = null;
 60  0
     }
 61  
 
 62  
     /**
 63  
      * @see org.apache.tapestry.contrib.table.model.ITableRendererListener#initializeRenderer(IRequestCycle,
 64  
      *      ITableModelSource, ITableColumn, Object)
 65  
      */
 66  
     public void initializeRenderer(IRequestCycle objCycle, ITableModelSource objSource,
 67  
                                    ITableColumn objColumn, Object objRow)
 68  
     {
 69  0
         m_objModelSource = objSource;
 70  0
         m_objColumn = objColumn;
 71  0
     }
 72  
 
 73  
     public ITableModel getTableModel()
 74  
     {
 75  0
         return m_objModelSource.getTableModel();
 76  
     }
 77  
 
 78  
     public boolean getColumnSorted()
 79  
     {
 80  0
         return m_objColumn.getSortable();
 81  
     }
 82  
 
 83  
     public String getDisplayName()
 84  
     {
 85  0
         if (m_objColumn instanceof SimpleTableColumn)
 86  
         {
 87  0
             SimpleTableColumn objSimpleColumn = (SimpleTableColumn) m_objColumn;
 88  
 
 89  0
             return objSimpleColumn.getDisplayName();
 90  
         }
 91  
         
 92  0
         return m_objColumn.getColumnName();
 93  
     }
 94  
 
 95  
     public boolean getIsSorted()
 96  
     {
 97  0
         ITableSortingState objSortingState = getTableModel().getSortingState();
 98  0
         String strSortColumn = objSortingState.getSortColumn();
 99  
         
 100  0
         return m_objColumn.getColumnName().equals(strSortColumn);
 101  
     }
 102  
 
 103  
     public IAsset getSortImage()
 104  
     {
 105  
         IAsset objImageAsset;
 106  
 
 107  0
         IRequestCycle objCycle = getPage().getRequestCycle();
 108  0
         ITableSortingState objSortingState = getTableModel().getSortingState();
 109  
         
 110  0
         if (objSortingState.getSortOrder() == ITableSortingState.SORT_ASCENDING)
 111  
         {
 112  0
             objImageAsset = (IAsset) objCycle.getAttribute(TableColumns.TABLE_COLUMN_ARROW_UP_ATTRIBUTE);
 113  
             
 114  0
             if (objImageAsset == null)
 115  0
                 objImageAsset = getAsset("sortUp");
 116  
         }
 117  
         else
 118  
         {
 119  0
             objImageAsset = (IAsset) objCycle.getAttribute(TableColumns.TABLE_COLUMN_ARROW_DOWN_ATTRIBUTE);
 120  
 
 121  0
             if (objImageAsset == null)
 122  0
                 objImageAsset = getAsset("sortDown");
 123  
         }
 124  
 
 125  0
         return objImageAsset;
 126  
     }
 127  
 
 128  
     public Object[] getColumnSelectedParameters()
 129  
     {
 130  0
         return new Object[] {
 131  
                 new ComponentAddress(m_objModelSource),
 132  
                 m_objColumn.getColumnName()
 133  
         };
 134  
     }
 135  
 
 136  
     public void columnSelected(IRequestCycle objCycle)
 137  
     {
 138  0
         Object[] arrArgs = objCycle.getListenerParameters();
 139  0
         ComponentAddress objAddr = (ComponentAddress) arrArgs[0];
 140  0
         String strColumnName = (String) arrArgs[1];
 141  
 
 142  0
         ITableModelSource objSource = (ITableModelSource) objAddr
 143  
                 .findComponent(objCycle);
 144  0
         objSource.storeTableAction(new TableActionColumnSort(strColumnName));
 145  0
     }
 146  
 
 147  
 }