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
015package org.apache.tapestry.contrib.table.model.simple;
016
017import java.io.Serializable;
018
019import org.apache.tapestry.contrib.table.model.ITableColumnModel;
020import org.apache.tapestry.contrib.table.model.ITableDataModel;
021import org.apache.tapestry.contrib.table.model.ITableModel;
022import org.apache.tapestry.contrib.table.model.ITableSessionStateManager;
023
024/**
025 * A {@link org.apache.tapestry.contrib.table.model.ITableSessionStateManager} 
026 * implementation that saves only the paging and sorting state of the table model 
027 * into the session.
028 * 
029 * @author mindbridge
030 */
031public class SimpleTableSessionStateManager
032        implements ITableSessionStateManager
033{
034        private ITableDataModel m_objDataModel;
035        private ITableColumnModel m_objColumnModel;
036
037        public SimpleTableSessionStateManager(
038                ITableDataModel objDataModel,
039                ITableColumnModel objColumnModel)
040        {
041                m_objDataModel = objDataModel;
042                m_objColumnModel = objColumnModel;
043        }
044
045        /**
046         * @see org.apache.tapestry.contrib.table.model.ITableSessionStateManager#getSessionState(ITableModel)
047         */
048        public Serializable getSessionState(ITableModel objModel)
049        {
050                SimpleTableModel objSimpleModel = (SimpleTableModel) objModel;
051                return objSimpleModel.getState();
052        }
053
054        /**
055         * @see org.apache.tapestry.contrib.table.model.ITableSessionStateManager#recreateTableModel(Serializable)
056         */
057        public ITableModel recreateTableModel(Serializable objState)
058        {
059                if (objState == null)
060                        return null;
061                SimpleTableState objSimpleState = (SimpleTableState) objState;
062                return new SimpleTableModel(
063                        m_objDataModel,
064                        m_objColumnModel,
065                        objSimpleState);
066        }
067
068}