001 /*
002 * Databinder: a simple bridge from Wicket to Hibernate
003 * Copyright (C) 2006 Nathan Hamblen nathan@technically.us
004
005 * This library is free software; you can redistribute it and/or
006 * modify it under the terms of the GNU Lesser General Public
007 * License as published by the Free Software Foundation; either
008 * version 2.1 of the License, or (at your option) any later version.
009 *
010 * This library is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013 * Lesser General Public License for more details.
014 *
015 * You should have received a copy of the GNU Lesser General Public
016 * License along with this library; if not, write to the Free Software
017 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
018 */
019 package net.databinder.models;
020
021 import org.apache.wicket.markup.repeater.data.DefaultDataProvider;
022 import org.apache.wicket.model.CompoundPropertyModel;
023 import org.apache.wicket.model.IModel;
024
025 /**
026 * Base IDataProvider class with support for wrapping item models in a
027 * CompoundPropertyModel.
028 * @author Nathan Hamblen
029 */
030 public abstract class PropertyDataProvider extends DefaultDataProvider {
031
032 /** Controls wrapping with a compound property model. */
033 private boolean wrapWithPropertyModel = true;
034
035 public PropertyDataProvider setWrapWithPropertyModel(boolean wrapWithPropertyModel) {
036 this.wrapWithPropertyModel = wrapWithPropertyModel;
037 return this;
038 }
039
040 /**
041 * Wraps object in a persistent object model, and also CompoundPropertyModel if
042 * wrapInCompoundModel is true.
043 * @param object object DataView would like to wrap
044 * @return object wrapped in a peristent model and possibly CompoundPropertyModel
045 */
046 public IModel model(Object object) {
047 IModel model = dataModel(object);
048 if (wrapWithPropertyModel)
049 model = new CompoundPropertyModel(model);
050 return model;
051 }
052
053 /** Wrap in appropriate persistent model in subclass */
054 protected abstract IModel dataModel(Object object);
055
056 }