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 org.apache.tapestry.contrib.table.model.IBasicTableModel;
018 import org.apache.tapestry.contrib.table.model.ITableColumn;
019 import org.apache.tapestry.contrib.table.model.ITableColumnModel;
020 import org.apache.tapestry.contrib.table.model.simple.SimpleTableState;
021
022 import java.util.Iterator;
023
024 /**
025 * @author mindbridge
026 */
027 public class BasicTableModelWrap extends AbstractTableModel
028 {
029
030 private static final long serialVersionUID = 1L;
031
032 private IBasicTableModel m_objBasicTableModel;
033 private ITableColumnModel m_objTableColumnModel;
034
035 public BasicTableModelWrap(IBasicTableModel objBasicTableModel,
036 ITableColumnModel objColumnModel)
037 {
038 this(objBasicTableModel, objColumnModel, new SimpleTableState());
039 }
040
041 public BasicTableModelWrap(IBasicTableModel objBasicTableModel,
042 ITableColumnModel objColumnModel, SimpleTableState objState)
043 {
044 super(objState);
045 m_objBasicTableModel = objBasicTableModel;
046 m_objTableColumnModel = objColumnModel;
047 }
048
049 /**
050 * @see org.apache.tapestry.contrib.table.model.ITableModel#getColumnModel()
051 */
052 public ITableColumnModel getColumnModel()
053 {
054 return m_objTableColumnModel;
055 }
056
057 /**
058 * @see org.apache.tapestry.contrib.table.model.common.AbstractTableModel#getRowCount()
059 */
060 public int getRowCount()
061 {
062 return m_objBasicTableModel.getRowCount();
063 }
064
065 /**
066 * @see org.apache.tapestry.contrib.table.model.ITableModel#getCurrentPageRows()
067 */
068 public Iterator getCurrentPageRows()
069 {
070 int nPageSize = getPagingState().getPageSize();
071 if (nPageSize <= 0) nPageSize = getRowCount();
072
073 int nCurrentPage = getPagingState().getCurrentPage();
074 int nFrom = nCurrentPage * nPageSize;
075
076 String strSortColumn = getSortingState().getSortColumn();
077 ITableColumn objSortColumn = getColumnModel().getColumn(strSortColumn);
078 boolean bSortOrder = getSortingState().getSortOrder();
079
080 return m_objBasicTableModel.getCurrentPageRows(nFrom, nPageSize,
081 objSortColumn, bSortOrder);
082 }
083
084 }