001 // Copyright 2004, 2005 The Apache Software Foundation 002 // 003 // Licensed under the Apache License, Version 2.0 (the "License"); 004 // you may not use this file except in compliance with the License. 005 // You may obtain a copy of the License at 006 // 007 // http://www.apache.org/licenses/LICENSE-2.0 008 // 009 // Unless required by applicable law or agreed to in writing, software 010 // distributed under the License is distributed on an "AS IS" BASIS, 011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 012 // See the License for the specific language governing permissions and 013 // limitations under the License. 014 015 package org.apache.tapestry.contrib.table.model.common; 016 017 import java.util.Iterator; 018 019 import org.apache.tapestry.contrib.table.model.IBasicTableModel; 020 import org.apache.tapestry.contrib.table.model.ITableColumn; 021 import org.apache.tapestry.contrib.table.model.ITableColumnModel; 022 import org.apache.tapestry.contrib.table.model.simple.SimpleTableState; 023 024 /** 025 * @author mindbridge 026 */ 027 public class BasicTableModelWrap extends AbstractTableModel 028 { 029 private static final long serialVersionUID = 1L; 030 031 private IBasicTableModel m_objBasicTableModel; 032 private ITableColumnModel m_objTableColumnModel; 033 034 public BasicTableModelWrap(IBasicTableModel objBasicTableModel, ITableColumnModel objColumnModel) 035 { 036 this(objBasicTableModel, objColumnModel, new SimpleTableState()); 037 } 038 039 public BasicTableModelWrap(IBasicTableModel objBasicTableModel, ITableColumnModel objColumnModel, SimpleTableState objState) 040 { 041 super(objState); 042 m_objBasicTableModel = objBasicTableModel; 043 m_objTableColumnModel = objColumnModel; 044 } 045 046 /** 047 * @see org.apache.tapestry.contrib.table.model.ITableModel#getColumnModel() 048 */ 049 public ITableColumnModel getColumnModel() 050 { 051 return m_objTableColumnModel; 052 } 053 054 /** 055 * @see org.apache.tapestry.contrib.table.model.common.AbstractTableModel#getRowCount() 056 */ 057 protected int getRowCount() 058 { 059 return m_objBasicTableModel.getRowCount(); 060 } 061 062 /** 063 * @see org.apache.tapestry.contrib.table.model.ITableModel#getCurrentPageRows() 064 */ 065 public Iterator getCurrentPageRows() 066 { 067 int nPageSize = getPagingState().getPageSize(); 068 if (nPageSize <= 0) 069 nPageSize = getRowCount(); 070 071 int nCurrentPage = getPagingState().getCurrentPage(); 072 int nFrom = nCurrentPage * nPageSize; 073 074 String strSortColumn = getSortingState().getSortColumn(); 075 ITableColumn objSortColumn = getColumnModel().getColumn(strSortColumn); 076 boolean bSortOrder = getSortingState().getSortOrder(); 077 078 return m_objBasicTableModel.getCurrentPageRows(nFrom, nPageSize, objSortColumn, bSortOrder); 079 } 080 081 }