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.data.table.filter;
018
019import org.apache.wicket.Component;
020import org.apache.wicket.model.IModel;
021import org.apache.wicket.model.PropertyModel;
022
023/**
024 * A filtered property column that creates a textfield filter component. The default model of the
025 * created textfield is a property model with the same property expression as the one used to
026 * display data. This works well when the filter state object is of the same type as the objects in
027 * the data table.
028 * 
029 * @author Igor Vaynberg (ivaynberg)
030 * @param <T>
031 *            The column's model object type
032 * @param <F>
033 *            Filter's model object type
034 * @param <S>
035 *            the type of the sort property
036 * 
037 */
038public class TextFilteredPropertyColumn<T, F, S> extends FilteredPropertyColumn<T, S>
039{
040        private static final long serialVersionUID = 1L;
041
042        /**
043         * @param displayModel
044         * @param sortProperty
045         * @param propertyExpression
046         */
047        public TextFilteredPropertyColumn(final IModel<String> displayModel, final S sortProperty,
048                final String propertyExpression)
049        {
050                super(displayModel, sortProperty, propertyExpression);
051        }
052
053        /**
054         * @param displayModel
055         * @param propertyExpression
056         */
057        public TextFilteredPropertyColumn(final IModel<String> displayModel,
058                final String propertyExpression)
059        {
060                super(displayModel, propertyExpression);
061        }
062
063        /**
064         * @see org.apache.wicket.extensions.markup.html.repeater.data.table.filter.IFilteredColumn#getFilter(java.lang.String,
065         *      org.apache.wicket.extensions.markup.html.repeater.data.table.filter.FilterForm)
066         */
067        @Override
068        public Component getFilter(final String componentId, final FilterForm<?> form)
069        {
070                return new TextFilter<>(componentId, getFilterModel(form), form);
071        }
072
073        /**
074         * Returns the model that will be passed on to the text filter. Users can override this method
075         * to change the model.
076         * 
077         * @param form
078         *            filter form
079         * @return model passed on to the text filter
080         */
081        protected IModel<F> getFilterModel(final FilterForm<?> form)
082        {
083                return new PropertyModel<>(form.getDefaultModel(), getPropertyExpression());
084        }
085
086
087}