Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
AbstractTableModel |
|
| 1.6666666666666667;1.667 |
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 org.apache.tapestry.contrib.table.model.ITableModel; | |
18 | import org.apache.tapestry.contrib.table.model.ITablePagingState; | |
19 | import org.apache.tapestry.contrib.table.model.ITableSortingState; | |
20 | import org.apache.tapestry.contrib.table.model.simple.SimpleTableState; | |
21 | ||
22 | import java.io.Serializable; | |
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 | |
31 | { | |
32 | private SimpleTableState m_objTableState; | |
33 | ||
34 | protected AbstractTableModel() | |
35 | { | |
36 | 0 | this(new SimpleTableState()); |
37 | 0 | } |
38 | ||
39 | protected AbstractTableModel(SimpleTableState objTableState) | |
40 | 0 | { |
41 | 0 | m_objTableState = objTableState; |
42 | 0 | } |
43 | ||
44 | /** | |
45 | * @see org.apache.tapestry.contrib.table.model.ITableModel#getPagingState() | |
46 | */ | |
47 | public ITablePagingState getPagingState() | |
48 | { | |
49 | 0 | return getState().getPagingState(); |
50 | } | |
51 | ||
52 | /** | |
53 | * @see org.apache.tapestry.contrib.table.model.ITableModel#getSortingState() | |
54 | */ | |
55 | public ITableSortingState getSortingState() | |
56 | { | |
57 | 0 | return getState().getSortingState(); |
58 | } | |
59 | ||
60 | /** | |
61 | * Returns the tableState. | |
62 | * @return SimpleTableState | |
63 | */ | |
64 | public SimpleTableState getState() | |
65 | { | |
66 | 0 | return m_objTableState; |
67 | } | |
68 | ||
69 | public int getPageCount() | |
70 | { | |
71 | 0 | int nRowCount = getRowCount(); |
72 | 0 | if (nRowCount == 0) |
73 | 0 | return 1; |
74 | ||
75 | 0 | int nPageSize = getPagingState().getPageSize(); |
76 | 0 | if (nPageSize <= 0) |
77 | 0 | return 1; |
78 | ||
79 | 0 | return (nRowCount - 1) / nPageSize + 1; |
80 | } | |
81 | } |