KickJava   Java API By Example, From Geeks To Geeks.

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


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.io.Serializable JavaDoc;
18
19 import org.apache.tapestry.contrib.table.model.ITableModel;
20 import org.apache.tapestry.contrib.table.model.ITablePagingState;
21 import org.apache.tapestry.contrib.table.model.ITableSortingState;
22 import org.apache.tapestry.contrib.table.model.simple.SimpleTableState;
23
24 /**
25  * A base table model that implements the handling of the model state.
26  * Used by most standard ITableModel implementations.
27  *
28  * @author mindbridge
29  */

30 public abstract class AbstractTableModel implements ITableModel, Serializable JavaDoc
31 {
32     private SimpleTableState m_objTableState;
33
34     protected AbstractTableModel()
35     {
36         this(new SimpleTableState());
37     }
38
39     protected AbstractTableModel(SimpleTableState objTableState)
40     {
41         m_objTableState = objTableState;
42     }
43     
44     /**
45      * @see org.apache.tapestry.contrib.table.model.ITableModel#getPagingState()
46      */

47     public ITablePagingState getPagingState()
48     {
49         return getState().getPagingState();
50     }
51
52     /**
53      * @see org.apache.tapestry.contrib.table.model.ITableModel#getSortingState()
54      */

55     public ITableSortingState getSortingState()
56     {
57         return getState().getSortingState();
58     }
59
60     /**
61      * Returns the tableState.
62      * @return SimpleTableState
63      */

64     public SimpleTableState getState()
65     {
66         return m_objTableState;
67     }
68
69     protected abstract int getRowCount();
70     
71     public int getPageCount()
72     {
73         int nRowCount = getRowCount();
74         if (nRowCount == 0)
75             return 1;
76
77         int nPageSize = getPagingState().getPageSize();
78         if (nPageSize <= 0)
79             return 1;
80
81         return (nRowCount - 1) / nPageSize + 1;
82     }
83     
84 }
85
Popular Tags