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.table.ISortableDataProvider;
021import org.apache.wicket.extensions.markup.html.repeater.tree.ISortableTreeProvider;
022
023/**
024 * Convenience implementation of a tree provider that can also act as a locator for a
025 * {@link SingleSortState} object.
026 * 
027 * @author svenmeier
028 * @param <T>
029 * @param <S>
030 *            the type of the sorting parameter
031 */
032public abstract class SortableTreeProvider<T, S> implements ISortableTreeProvider<T, S>
033{
034        private static final long serialVersionUID = 1L;
035
036        private final SingleSortState<S> state = new SingleSortState<>();
037
038        /**
039         * @see ISortableDataProvider#getSortState()
040         */
041        @Override
042        public final ISortState<S> getSortState()
043        {
044                return state;
045        }
046
047        /**
048         * Returns current sort state
049         * 
050         * @return current sort state
051         */
052        public SortParam<S> getSort()
053        {
054                return state.getSort();
055        }
056
057        /**
058         * Sets the current sort state
059         * 
060         * @param param
061         *            parameter containing new sorting information
062         */
063        public void setSort(SortParam<S> param)
064        {
065                state.setSort(param);
066        }
067
068        /**
069         * Sets the current sort state
070         * 
071         * @param property
072         *            sort property
073         * @param ascending
074         *            sort direction
075         */
076        public void setSort(S property, boolean ascending)
077        {
078                setSort(new SortParam<>(property, ascending));
079        }
080
081        /**
082         * @see ISortableDataProvider#detach()
083         */
084        @Override
085        public void detach()
086        {
087        }
088}