Coverage Report - org.apache.tapestry.contrib.table.components.inserted.SimpleTableColumnSortImage
 
Classes in this File Line Coverage Branch Coverage Complexity
SimpleTableColumnSortImage
0%
0/28
0%
0/8
1.556
 
 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.Tapestry;
 21  
 import org.apache.tapestry.contrib.table.components.Table;
 22  
 import org.apache.tapestry.contrib.table.components.TableColumns;
 23  
 import org.apache.tapestry.contrib.table.model.ITableColumn;
 24  
 import org.apache.tapestry.contrib.table.model.ITableModel;
 25  
 import org.apache.tapestry.contrib.table.model.ITableModelSource;
 26  
 import org.apache.tapestry.contrib.table.model.ITableRendererListener;
 27  
 import org.apache.tapestry.contrib.table.model.ITableSortingState;
 28  
 import org.apache.tapestry.event.PageDetachListener;
 29  
 import org.apache.tapestry.event.PageEvent;
 30  
 
 31  
 /**
 32  
  * A component that renders the proper sort image for the current column - to be 
 33  
  * used with contrib:Table when customizing a column's header.
 34  
  * 
 35  
  * @author Andreas Andreou
 36  
  */
 37  
 public abstract class SimpleTableColumnSortImage extends BaseComponent
 38  
         implements PageDetachListener, ITableRendererListener
 39  
 {
 40  
     // transient
 41  
     private ITableModelSource m_objModelSource;
 42  
     private ITableColumn m_objColumn;
 43  
     
 44  
     public SimpleTableColumnSortImage()
 45  0
     {
 46  0
         init();
 47  0
     }
 48  
 
 49  
     public abstract Table getTable();
 50  
     
 51  
     /**
 52  
      * @see org.apache.tapestry.event.PageDetachListener#pageDetached(PageEvent)
 53  
      */
 54  
     public void pageDetached(PageEvent arg0)
 55  
     {
 56  0
         init();
 57  0
     }
 58  
 
 59  
     private void init()
 60  
     {
 61  0
         m_objModelSource = null;
 62  0
         m_objColumn = null;
 63  0
     }
 64  
 
 65  
     /**
 66  
      * @see org.apache.tapestry.contrib.table.model.ITableRendererListener#initializeRenderer(IRequestCycle,
 67  
      *      ITableModelSource, ITableColumn, Object)
 68  
      */
 69  
     public void initializeRenderer(IRequestCycle objCycle,
 70  
             ITableModelSource objSource, ITableColumn objColumn, Object objRow)
 71  
     {
 72  0
         m_objModelSource = objSource;
 73  0
         m_objColumn = objColumn;
 74  0
     }
 75  
     
 76  
      public void prepareForRender(IRequestCycle cycle)
 77  
      {         
 78  0
          if (getTable()==null)
 79  0
             throw Tapestry.createRequiredParameterException(this, "table");
 80  
          
 81  0
          m_objModelSource = getTable();
 82  0
          m_objColumn = getTable().getTableColumn();
 83  
                   
 84  0
      }
 85  
          
 86  
 
 87  
     public ITableModel getTableModel()
 88  
     {
 89  0
         return m_objModelSource.getTableModel();
 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 boolean getIsSorted()
 115  
     {
 116  0
         ITableSortingState objSortingState = getTableModel().getSortingState();
 117  0
         String strSortColumn = objSortingState.getSortColumn();
 118  0
         return m_objColumn.getColumnName().equals(strSortColumn);
 119  
     }    
 120  
 }