⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 filterhandler.java

📁 分页查询控件 分页查询控件
💻 JAVA
字号:
/* * Copyright 2004 original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * *    http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package org.extremecomponents.table.handler;import java.util.Collection;import java.util.Iterator;import java.util.List;import java.util.Map;import org.apache.commons.lang.StringUtils;import org.extremecomponents.base.BaseModel;import org.extremecomponents.table.bean.Column;import org.extremecomponents.table.callback.FilterRowsCallback;import org.extremecomponents.table.cell.Cell;import org.extremecomponents.table.core.ParameterRegistry;import org.extremecomponents.table.core.TableModelUtils;/** * Deal with the filtering. *  * @author Jeff Johnston */public class FilterHandler {    public final static String CLEAR = "clear";    public final static String SEARCH = "search";    public final static String BUTTON = "button";    public final static String SEARCH_ARROW_IMAGE = "searchArrow";    public final static String SEARCH_IMAGE = "search";    public final static String CLEAR_IMAGE = "clear";    private String button;    private BaseModel model;    public FilterHandler(BaseModel model) {        this.model = model;    }    public boolean doFilter() {        Map parameters = model.getRegistry().getParameters(ParameterRegistry.FILTER);        return parameters.size() > 0;    }    public boolean doClear() {        if (!StringUtils.isEmpty(getButton()) && getButton().equals(CLEAR)) {            return true;        }        return false;    }    public String getButton() {        if (button == null) {            button = model.getRegistry().getParameter(ParameterRegistry.FILTER + BUTTON);        }        return button;    }    /**     * Filter out the table using the Predicate pattern.     */    public Collection filterRows(BaseModel model, Collection rows)            throws Exception {        if (doClear()) //we pressed the clear button        {            model.getRegistry().clearParameters(ParameterRegistry.FILTER);            return rows;        }        if (!doFilter()) {            return rows;        }        FilterRowsCallback filterRowsCallback = (FilterRowsCallback) model.getCallback(model.getTableHandler()                .getTable().getFilterRowsCallback());        return filterRowsCallback.filterRows(model, rows);    }    public List getFilterColumns() {        List columns = model.getColumnHandler().getColumns();        for (Iterator iter = columns.iterator(); iter.hasNext();) {            Column column = (Column) iter.next();            String value = model.getRegistry().getParameter(ParameterRegistry.FILTER + column.getProperty());            if ((!StringUtils.isEmpty(button) && button.equals(CLEAR)) || StringUtils.isEmpty(value))            {                value = "";            }            Cell cell = TableModelUtils.buildFilterCell(model, column, value);            column.setValue(cell.html());            cell.destroy();        }        return columns;    }        public Map getFilters() {        return TableModelUtils.getSortedOrFilteredParameters(model, ParameterRegistry.FILTER);    }    public void destroy() {        button = null;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -