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