Clover coverage report - Code Coverage for tapestry-contrib release 4.0.1
Coverage timestamp: Fri Mar 31 2006 09:15:40 EST
file stats: LOC: 194   Methods: 17
NCLOC: 123   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
TablePages.java 0% 0% 0% 0%
coverage
 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;
 16   
 17    import org.apache.tapestry.IRequestCycle;
 18    import org.apache.tapestry.contrib.table.model.ITableModelSource;
 19    import org.apache.tapestry.util.ComponentAddress;
 20   
 21    /**
 22    * A low level Table component that renders the pages in the table.
 23    * This component must be wrapped by {@link org.apache.tapestry.contrib.table.components.TableView}.
 24    * <p>
 25    * The component generates a list of pages in the Table centered around the
 26    * current one and allows you to navigate to other pages.
 27    * <p>
 28    * Please see the Component Reference for details on how to use this component.
 29    *
 30    * [<a href="../../../../../../../ComponentReference/contrib.TablePages.html">Component Reference</a>]
 31    *
 32    * @author mindbridge
 33    *
 34    */
 35    public abstract class TablePages extends AbstractTableViewComponent
 36    {
 37    // Bindings
 38    public abstract int getPagesDisplayed();
 39   
 40    // Transient
 41    private int m_nDisplayPage;
 42   
 43    /**
 44    * Returns the displayPage.
 45    * @return int
 46    */
 47  0 public int getDisplayPage()
 48    {
 49  0 return m_nDisplayPage;
 50    }
 51   
 52    /**
 53    * Sets the displayPage.
 54    * @param displayPage The displayPage to set
 55    */
 56  0 public void setDisplayPage(int displayPage)
 57    {
 58  0 m_nDisplayPage = displayPage;
 59    }
 60   
 61  0 public int getCurrentPage()
 62    {
 63  0 return getTableModelSource().getTableModel().getPagingState().getCurrentPage() + 1;
 64    }
 65   
 66  0 public int getPageCount()
 67    {
 68  0 return getTableModelSource().getTableModel().getPageCount();
 69    }
 70   
 71  0 public boolean getCondBack()
 72    {
 73  0 return getCurrentPage() > 1;
 74    }
 75   
 76  0 public boolean getCondFwd()
 77    {
 78  0 return getCurrentPage() < getPageCount();
 79    }
 80   
 81  0 public boolean getCondCurrent()
 82    {
 83  0 return getDisplayPage() == getCurrentPage();
 84    }
 85   
 86  0 public int getStartPage()
 87    {
 88  0 int nCurrent = getCurrentPage();
 89  0 int nPagesDisplayed = getPagesDisplayed();
 90   
 91  0 int nRightMargin = nPagesDisplayed / 2;
 92  0 int nStop = nCurrent + nRightMargin;
 93  0 int nLastPage = getPageCount();
 94   
 95  0 int nLeftAddon = 0;
 96  0 if (nStop > nLastPage)
 97  0 nLeftAddon = nStop - nLastPage;
 98   
 99  0 int nLeftMargin = (nPagesDisplayed - 1) / 2 + nLeftAddon;
 100  0 int nStart = nCurrent - nLeftMargin;
 101  0 int nFirstPage = 1;
 102  0 if (nStart < nFirstPage)
 103  0 nStart = nFirstPage;
 104  0 return nStart;
 105    }
 106   
 107  0 public int getStopPage()
 108    {
 109  0 int nCurrent = getCurrentPage();
 110  0 int nPagesDisplayed = getPagesDisplayed();
 111   
 112  0 int nLeftMargin = (nPagesDisplayed - 1) / 2;
 113  0 int nStart = nCurrent - nLeftMargin;
 114  0 int nFirstPage = 1;
 115   
 116  0 int nRightAddon = 0;
 117  0 if (nStart < nFirstPage)
 118  0 nRightAddon = nFirstPage - nStart;
 119   
 120  0 int nRightMargin = nPagesDisplayed / 2 + nRightAddon;
 121  0 int nStop = nCurrent + nRightMargin;
 122  0 int nLastPage = getPageCount();
 123  0 if (nStop > nLastPage)
 124  0 nStop = nLastPage;
 125  0 return nStop;
 126    }
 127   
 128  0 public Integer[] getPageList()
 129    {
 130  0 int nStart = getStartPage();
 131  0 int nStop = getStopPage();
 132   
 133  0 Integer[] arrPages = new Integer[nStop - nStart + 1];
 134  0 for (int i = nStart; i <= nStop; i++)
 135  0 arrPages[i - nStart] = new Integer(i);
 136   
 137  0 return arrPages;
 138    }
 139   
 140  0 public Object[] getFirstPageContext()
 141    {
 142  0 ComponentAddress objAddress = new ComponentAddress(getTableModelSource());
 143  0 return new Object[] { objAddress, new Integer(1)};
 144    }
 145   
 146  0 public Object[] getLastPageContext()
 147    {
 148  0 ComponentAddress objAddress = new ComponentAddress(getTableModelSource());
 149  0 return new Object[] { objAddress, new Integer(getPageCount())};
 150    }
 151   
 152  0 public Object[] getBackPageContext()
 153    {
 154  0 ComponentAddress objAddress = new ComponentAddress(getTableModelSource());
 155  0 return new Object[] { objAddress, new Integer(getCurrentPage() - 1)};
 156    }
 157   
 158  0 public Object[] getFwdPageContext()
 159    {
 160  0 ComponentAddress objAddress = new ComponentAddress(getTableModelSource());
 161  0 return new Object[] { objAddress, new Integer(getCurrentPage() + 1)};
 162    }
 163   
 164  0 public Object[] getDisplayPageContext()
 165    {
 166  0 ComponentAddress objAddress = new ComponentAddress(getTableModelSource());
 167  0 return new Object[] { objAddress, new Integer(m_nDisplayPage)};
 168    }
 169   
 170  0 public void changePage(IRequestCycle objCycle)
 171    {
 172  0 Object[] arrParameters = objCycle.getListenerParameters();
 173  0 if (arrParameters.length != 2
 174    && !(arrParameters[0] instanceof ComponentAddress)
 175    && !(arrParameters[1] instanceof Integer))
 176    {
 177    // error
 178  0 return;
 179    }
 180   
 181  0 ComponentAddress objAddress = (ComponentAddress) arrParameters[0];
 182  0 ITableModelSource objSource = (ITableModelSource) objAddress.findComponent(objCycle);
 183  0 setCurrentPage(objSource, ((Integer) arrParameters[1]).intValue());
 184   
 185    // ensure that the change is saved
 186  0 objSource.fireObservedStateChange();
 187    }
 188   
 189  0 public void setCurrentPage(ITableModelSource objSource, int nPage)
 190    {
 191  0 objSource.getTableModel().getPagingState().setCurrentPage(nPage - 1);
 192    }
 193   
 194    }