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.components;
020
021 import org.apache.wicket.Component;
022 import org.apache.wicket.extensions.markup.html.repeater.data.table.filter.ChoiceFilter;
023 import org.apache.wicket.extensions.markup.html.repeater.data.table.filter.ChoiceFilteredPropertyColumn;
024 import org.apache.wicket.extensions.markup.html.repeater.data.table.filter.FilterForm;
025 import org.apache.wicket.markup.html.form.ChoiceRenderer;
026 import org.apache.wicket.markup.html.form.IChoiceRenderer;
027 import org.apache.wicket.model.IModel;
028 import org.apache.wicket.model.PropertyModel;
029
030 /**
031 * DataTable property filter column that works with joined entities instead of string properties.
032 * @author Mark Southern
033 */
034 public class ObjectFilteredPropertyColumn extends ChoiceFilteredPropertyColumn {
035 private ChoiceRenderer choiceRenderer;
036 private String displayProperty;
037
038 public ObjectFilteredPropertyColumn(IModel displayModel, String sortProperty, String displayProperty, String propertyExpression, String filterLabelProperty, IModel filterChoices) {
039 super(displayModel,sortProperty,propertyExpression,filterChoices);
040 choiceRenderer = new ChoiceRenderer(filterLabelProperty);
041 this.displayProperty = displayProperty;
042 }
043
044 protected IChoiceRenderer getChoiceRenderer() {
045 return choiceRenderer;
046 }
047
048 protected IModel createLabelModel(IModel embeddedModel) {
049 return new PropertyModel(embeddedModel, displayProperty);
050 }
051
052 public Component getFilter(String componentId, FilterForm form) {
053 ChoiceFilter cf = (ChoiceFilter) super.getFilter(componentId, form);
054 cf.getChoice().setNullValid(true);
055 return cf;
056 }
057 }