001 package net.databinder.models.hib;
002
003 /*
004 * Databinder: a simple bridge from Wicket to Hibernate
005 * Copyright (C) 2006 Nathan Hamblen nathan@technically.us
006
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 *
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * You should have received a copy of the GNU Lesser General Public
018 * License along with this library; if not, write to the Free Software
019 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
020 */
021
022 import org.apache.wicket.extensions.markup.html.repeater.data.table.*;
023 import org.apache.wicket.extensions.markup.html.repeater.data.sort.*;
024
025 /**
026 * <h1>SortableHibernateProvider</h1>
027 * <i>Copyright (C) 2008 The Scripps Research Institute</i>
028 * <p>A HibernateProvider extension that implements ISortableDataProvider so it can be used with a DefaultDataTable or an AjaxFallbackDefaultDataTable
029 * The CriteriaBuilder that handles the sorting should also implement ISortStateLocator (such as CriteriaSorter).</p>
030 *
031 * @author Mark Southern (southern at scripps dot edu)
032 */
033
034 public class SortableHibernateProvider extends HibernateProvider implements ISortableDataProvider {
035
036 private ISortStateLocator sortStateLocator = null;
037
038 private ISortState sortState;
039
040 public SortableHibernateProvider(Class<?> objectClass, CriteriaBuilder criteriaBuilder, CriteriaBuilder orderingCriteriaBuilder) {
041 super(objectClass, criteriaBuilder, orderingCriteriaBuilder);
042 if (orderingCriteriaBuilder instanceof ISortStateLocator)
043 sortStateLocator = (ISortStateLocator) orderingCriteriaBuilder;
044 }
045
046 public SortableHibernateProvider(Class<?> objectClass, OrderingCriteriaBuilder criteriaBuilder) {
047 super(objectClass, criteriaBuilder);
048 if (criteriaBuilder instanceof ISortStateLocator)
049 sortStateLocator = (ISortStateLocator) criteriaBuilder;
050 }
051
052 public ISortState getSortState() {
053 return (sortStateLocator != null) ? sortStateLocator.getSortState() : sortState;
054 }
055
056 public void setSortState(ISortState state) {
057 if (sortStateLocator != null) {
058 sortStateLocator.setSortState(state);
059 }
060 else {
061 this.sortState = state;
062 }
063 }
064 }