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.markup.html.form.Button;
020import org.apache.wicket.markup.html.panel.Panel;
021import org.apache.wicket.model.IModel;
022import org.apache.wicket.model.ResourceModel;
023
024/**
025 * Filter component that generates a 'go' button that when pressed submits the filter form
026 * 
027 * @author Igor Vaynberg (ivaynberg)
028 * 
029 */
030public class GoFilter extends Panel
031{
032        private static final long serialVersionUID = 1L;
033
034        protected static final IModel<String> DEFAULT_GO_MODEL = new ResourceModel("datatable.go",
035                "filter");
036
037        private final Button go;
038
039        /**
040         * Constructor
041         * 
042         * This constructor will use the default model for the button's text
043         * 
044         * @param id
045         *            component id
046         */
047        public GoFilter(final String id)
048        {
049                this(id, DEFAULT_GO_MODEL);
050        }
051
052        /**
053         * Constructor
054         * 
055         * @param id
056         *            component id
057         * @param goModel
058         *            model for the button's text
059         */
060        public GoFilter(final String id, final IModel<String> goModel)
061        {
062                super(id);
063
064                go = new Button("go", goModel)
065                {
066                        private static final long serialVersionUID = 1L;
067
068                        @Override
069                        public void onSubmit()
070                        {
071                                onGoSubmit(this);
072                        }
073                };
074
075                add(go);
076        }
077
078        protected Button getGoButton()
079        {
080                return go;
081        }
082
083        /**
084         * This method can be overridden by subclasses to provide non-standard behavior for the 'go'
085         * button.
086         * 
087         * @param button
088         *            the 'go' button, can be used to get to the Form object and through that to the
089         *            filter state object by retrieving the form's model object
090         * 
091         */
092        protected void onGoSubmit(final Button button)
093        {
094        }
095
096}