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    
015    package org.apache.tapestry.contrib.table.model.simple;
016    
017    import java.io.Serializable;
018    
019    import org.apache.tapestry.contrib.table.model.ITableColumnModel;
020    import org.apache.tapestry.contrib.table.model.ITableDataModel;
021    import org.apache.tapestry.contrib.table.model.ITableModel;
022    import 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
027     * model into the session.
028     * 
029     * @author mindbridge
030     */
031    public class SimpleTableSessionStateManager implements
032            ITableSessionStateManager
033    {
034    
035        private ITableDataModel m_objDataModel;
036        private ITableColumnModel m_objColumnModel;
037    
038        public SimpleTableSessionStateManager(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) return null;
060            SimpleTableState objSimpleState = (SimpleTableState) objState;
061            return new SimpleTableModel(m_objDataModel, m_objColumnModel,
062                    objSimpleState);
063        }
064    
065    }