KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > contrib > table > model > common > BasicTableModelWrap


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.model.common;
16
17 import java.util.Iterator JavaDoc;
18
19 import org.apache.tapestry.contrib.table.model.IBasicTableModel;
20 import org.apache.tapestry.contrib.table.model.ITableColumn;
21 import org.apache.tapestry.contrib.table.model.ITableColumnModel;
22 import org.apache.tapestry.contrib.table.model.simple.SimpleTableState;
23
24 /**
25  * @author mindbridge
26  */

27 public class BasicTableModelWrap extends AbstractTableModel
28 {
29     private static final long serialVersionUID = 1L;
30     
31     private IBasicTableModel m_objBasicTableModel;
32     private ITableColumnModel m_objTableColumnModel;
33
34     public BasicTableModelWrap(IBasicTableModel objBasicTableModel, ITableColumnModel objColumnModel)
35     {
36         this(objBasicTableModel, objColumnModel, new SimpleTableState());
37     }
38
39     public BasicTableModelWrap(IBasicTableModel objBasicTableModel, ITableColumnModel objColumnModel, SimpleTableState objState)
40     {
41         super(objState);
42         m_objBasicTableModel = objBasicTableModel;
43         m_objTableColumnModel = objColumnModel;
44     }
45
46     /**
47      * @see org.apache.tapestry.contrib.table.model.ITableModel#getColumnModel()
48      */

49     public ITableColumnModel getColumnModel()
50     {
51         return m_objTableColumnModel;
52     }
53
54     /**
55      * @see org.apache.tapestry.contrib.table.model.common.AbstractTableModel#getRowCount()
56      */

57     protected int getRowCount()
58     {
59         return m_objBasicTableModel.getRowCount();
60     }
61
62     /**
63      * @see org.apache.tapestry.contrib.table.model.ITableModel#getCurrentPageRows()
64      */

65     public Iterator JavaDoc getCurrentPageRows()
66     {
67         int nPageSize = getPagingState().getPageSize();
68         if (nPageSize <= 0)
69             nPageSize = getRowCount();
70
71         int nCurrentPage = getPagingState().getCurrentPage();
72         int nFrom = nCurrentPage * nPageSize;
73         
74         String JavaDoc strSortColumn = getSortingState().getSortColumn();
75         ITableColumn objSortColumn = getColumnModel().getColumn(strSortColumn);
76         boolean bSortOrder = getSortingState().getSortOrder();
77         
78         return m_objBasicTableModel.getCurrentPageRows(nFrom, nPageSize, objSortColumn, bSortOrder);
79     }
80
81 }
82
Popular Tags