001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.wicket.extensions.markup.html.repeater.util;
018
019import org.apache.wicket.extensions.markup.html.repeater.data.sort.ISortState;
020import org.apache.wicket.extensions.markup.html.repeater.data.sort.SortOrder;
021import org.apache.wicket.extensions.markup.html.repeater.data.table.ISortableDataProvider;
022
023
024/**
025 * Convenience implementation of a data provider that can also act as a locator for a
026 * {@link SingleSortState} object.
027 * 
028 * Most times it is convenient to keep sort and filtering information inside the data provider
029 * implementation because it makes that information easy to access within the data provider.
030 * 
031 * @author Igor Vaynberg (ivaynberg at apache dot org)
032 * @param <T>
033 * @param <S>
034 *            the type of the sorting parameter
035 */
036public abstract class SortableDataProvider<T, S> implements ISortableDataProvider<T, S>
037{
038        private static final long serialVersionUID = 1L;
039
040        private final SingleSortState<S> state = new SingleSortState<>();
041
042        @Override
043        public final ISortState<S> getSortState()
044        {
045                return state;
046        }
047
048        /**
049         * Returns current sort state
050         * 
051         * @return current sort state
052         */
053        public SortParam<S> getSort()
054        {
055                return state.getSort();
056        }
057
058        /**
059         * Sets the current sort state
060         * 
061         * @param param
062         *            parameter containing new sorting information
063         */
064        public void setSort(final SortParam<S> param)
065        {
066                state.setSort(param);
067        }
068
069        /**
070         * Sets the current sort state
071         * 
072         * @param property
073         *            sort property
074         * @param order
075         *            sort order
076         */
077        public void setSort(final S property, final SortOrder order)
078        {
079                state.setPropertySortOrder(property, order);
080        }
081}