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.FormComponent; 020import org.apache.wicket.markup.html.panel.Panel; 021import org.apache.wicket.model.IModel; 022 023/** 024 * Base class for filters that provides some useful functionality 025 * 026 * @author Igor Vaynberg (ivaynberg) 027 */ 028public class AbstractFilter extends Panel 029{ 030 private static final long serialVersionUID = 1L; 031 032 private final FilterForm<?> form; 033 034 /** 035 * @param id 036 * component id 037 * @param form 038 * filter form of the filter toolbar 039 */ 040 public AbstractFilter(final String id, final FilterForm<?> form) 041 { 042 super(id); 043 this.form = form; 044 } 045 046 /** 047 * Enables the tracking of focus for the specified form component. This allows the filter form 048 * to restore focus to the component which caused the form submission. Great for when you are 049 * inside a filter textbox and use the enter key to submit the filter. 050 * 051 * @param fc 052 * form component for which focus tracking will be enabled 053 */ 054 protected void enableFocusTracking(final FormComponent<?> fc) 055 { 056 form.enableFocusTracking(fc); 057 } 058 059 protected IFilterStateLocator<?> getStateLocator() 060 { 061 return form.getStateLocator(); 062 } 063 064 protected IModel<?> getStateModel() 065 { 066 return form.getDefaultModel(); 067 } 068 069 protected Object getState() 070 { 071 return form.getDefaultModelObject(); 072 } 073 074}