Coverage Report - org.apache.tapestry.contrib.table.components.inserted.SimpleTableColumnSortLink
 
Classes in this File Line Coverage Branch Coverage Complexity
SimpleTableColumnSortLink
0%
0/23
0%
0/2
1.25
 
 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.IRequestCycle;
 19  
 import org.apache.tapestry.Tapestry;
 20  
 import org.apache.tapestry.contrib.table.components.Table;
 21  
 import org.apache.tapestry.contrib.table.model.ITableColumn;
 22  
 import org.apache.tapestry.contrib.table.model.ITableModelSource;
 23  
 import org.apache.tapestry.contrib.table.model.ITableRendererListener;
 24  
 import org.apache.tapestry.event.PageDetachListener;
 25  
 import org.apache.tapestry.event.PageEvent;
 26  
 import org.apache.tapestry.util.ComponentAddress;
 27  
 
 28  
 /**
 29  
  * A component that renders a sorting link - to be used with contrib:Table when 
 30  
  * customizing a column's header.
 31  
  *
 32  
  *
 33  
  * @author andyhot
 34  
  */
 35  
 public abstract class SimpleTableColumnSortLink extends BaseComponent
 36  
         implements ITableRendererListener, PageDetachListener
 37  
 {
 38  
     // transient
 39  
     private ITableColumn m_objColumn;
 40  
     private ITableModelSource m_objModelSource;
 41  
 
 42  
     public SimpleTableColumnSortLink()
 43  0
     {
 44  0
         init();
 45  0
     }
 46  
 
 47  
     public abstract Table getTable();
 48  
 
 49  
     /**
 50  
      * @see org.apache.tapestry.event.PageDetachListener#pageDetached(PageEvent)
 51  
      */
 52  
     public void pageDetached(PageEvent arg0)
 53  
     {
 54  0
         init();
 55  0
     }
 56  
 
 57  
     private void init()
 58  
     {
 59  0
         m_objColumn = null;
 60  0
         m_objModelSource = null;
 61  0
     }
 62  
 
 63  
     public void prepareForRender(IRequestCycle cycle)
 64  
     {
 65  0
         if (getTable()==null)
 66  0
             throw Tapestry.createRequiredParameterException(this, "table");
 67  
         
 68  0
         m_objModelSource = getTable();
 69  0
         m_objColumn = getTable().getTableColumn();
 70  0
     }
 71  
 
 72  
     /**
 73  
      * @see org.apache.tapestry.contrib.table.model.ITableRendererListener#initializeRenderer(IRequestCycle,
 74  
      *      ITableModelSource, ITableColumn, Object)
 75  
      */
 76  
     public void initializeRenderer(IRequestCycle objCycle, ITableModelSource objSource,
 77  
                                    ITableColumn objColumn, Object objRow)
 78  
     {
 79  0
         m_objModelSource = objSource;
 80  0
         m_objColumn = objColumn;
 81  0
     }
 82  
 
 83  
     public Object[] getColumnSelectedParameters()
 84  
     {
 85  0
         return new Object[] {
 86  
                 new ComponentAddress(m_objModelSource),
 87  
                 m_objColumn.getColumnName()
 88  
         };
 89  
     }
 90  
 
 91  
     public void columnSelected(IRequestCycle objCycle)
 92  
     {
 93  0
         Object[] arrArgs = objCycle.getListenerParameters();
 94  0
         ComponentAddress objAddr = (ComponentAddress) arrArgs[0];
 95  0
         String strColumnName = (String) arrArgs[1];
 96  
 
 97  0
         ITableModelSource objSource = (ITableModelSource) objAddr.findComponent(objCycle);
 98  
         
 99  0
         objSource.storeTableAction(new TableActionColumnSort(strColumnName));
 100  0
     }
 101  
 }