Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
TableViewSessionStateManager |
|
| 2.3333333333333335;2.333 |
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.components; |
|
16 | ||
17 | import java.io.Serializable; |
|
18 | ||
19 | import org.apache.tapestry.contrib.table.model.ITableModel; |
|
20 | import org.apache.tapestry.contrib.table.model.ITableSessionStateManager; |
|
21 | import org.apache.tapestry.contrib.table.model.simple.SimpleTableState; |
|
22 | ||
23 | /** |
|
24 | * Acts like {@link org.apache.tapestry.contrib.table.model.common.FullTableSessionStateManager} |
|
25 | * if the model is provided via the tableModel parameter; |
|
26 | * saves only the model state otherwise. |
|
27 | * |
|
28 | * @author mindbridge |
|
29 | */ |
|
30 | public class TableViewSessionStateManager implements ITableSessionStateManager |
|
31 | { |
|
32 | private TableView m_objView; |
|
33 | ||
34 | public TableViewSessionStateManager(TableView objView) |
|
35 | 0 | { |
36 | 0 | m_objView = objView; |
37 | 0 | } |
38 | ||
39 | /** |
|
40 | * @see org.apache.tapestry.contrib.table.model.ITableSessionStateManager#getSessionState(org.apache.tapestry.contrib.table.model.ITableModel) |
|
41 | */ |
|
42 | public Serializable getSessionState(ITableModel objModel) |
|
43 | { |
|
44 | // if the model is provided using the 'tableModel' parameter, |
|
45 | // emulate FullTableSessionStateManager and save everything |
|
46 | // (backward compatibility) |
|
47 | 0 | if (m_objView.getCachedTableModelValue() != null) |
48 | 0 | return (Serializable) objModel; |
49 | ||
50 | // otherwise save only the state |
|
51 | 0 | return new SimpleTableState(objModel.getPagingState(), objModel.getSortingState()); |
52 | } |
|
53 | ||
54 | /** |
|
55 | * @see org.apache.tapestry.contrib.table.model.ITableSessionStateManager#recreateTableModel(java.io.Serializable) |
|
56 | */ |
|
57 | public ITableModel recreateTableModel(Serializable objState) |
|
58 | { |
|
59 | // if the state implements ITableModel, return itself |
|
60 | // (backward compatibility) |
|
61 | 0 | if (objState instanceof ITableModel) |
62 | 0 | return (ITableModel) objState; |
63 | ||
64 | // otherwise have the component re-generate the model using the provided state |
|
65 | 0 | return m_objView.generateTableModel((SimpleTableState) objState); |
66 | } |
|
67 | ||
68 | } |