Coverage Report - org.apache.tapestry.contrib.table.components.inserted.SimpleTableColumnSortLink
 
Classes in this File Line Coverage Branch Coverage Complexity
SimpleTableColumnSortLink
0% 
0% 
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  0
          m_objModelSource = getTable();
 68  0
          m_objColumn = getTable().getTableColumn();         
 69  0
      }
 70  
 
 71  
     /**
 72  
      * @see org.apache.tapestry.contrib.table.model.ITableRendererListener#initializeRenderer(IRequestCycle,
 73  
      *      ITableModelSource, ITableColumn, Object)
 74  
      */
 75  
     public void initializeRenderer(IRequestCycle objCycle,
 76  
             ITableModelSource objSource, ITableColumn objColumn, Object objRow)
 77  
     {
 78  0
         m_objModelSource = objSource;
 79  0
         m_objColumn = objColumn;
 80  0
     }
 81  
 
 82  
     public Object[] getColumnSelectedParameters()
 83  
     {
 84  0
         return new Object[] { new ComponentAddress(m_objModelSource),
 85  
                 m_objColumn.getColumnName() };
 86  
     }
 87  
 
 88  
     public void columnSelected(IRequestCycle objCycle)
 89  
     {
 90  0
         Object[] arrArgs = objCycle.getListenerParameters();
 91  0
         ComponentAddress objAddr = (ComponentAddress) arrArgs[0];
 92  0
         String strColumnName = (String) arrArgs[1];
 93  
 
 94  0
         ITableModelSource objSource = (ITableModelSource) objAddr
 95  
                 .findComponent(objCycle);
 96  0
         objSource.storeTableAction(new TableActionColumnSort(strColumnName));
 97  0
     }
 98  
 
 99  
 }