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

📄 tablemodelutils.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.core;import java.util.HashMap;import java.util.Iterator;import java.util.Map;import java.util.Set;import org.apache.commons.lang.StringUtils;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import org.extremecomponents.base.BaseModel;import org.extremecomponents.table.bean.Column;import org.extremecomponents.table.cell.Cell;import org.extremecomponents.table.handler.FilterHandler;/** * Helpful utilities directly related to the TableModel. *  * @author Jeff Johnston */public class TableModelUtils {    private static Log logger = LogFactory.getLog(TableModelUtils.class);    private TableModelUtils() {    }        /**     * Determine whether or not this is a resource bundle key. It      * is a resource bundle key if the value has a '.' character     * in it.     *      * @param value The value that will be inspected to find out if resource key     * @return True if this is a resource bundle key     */    public static boolean isResourceBundleProperty(String value) {        if (StringUtils.contains(value, ".")) {            return true;        }                return false;    }    /**     * Get the collection of properties and values that was sorted or filtered.     *      * @param model BaseModel object     * @param parameter Either the ParameterRegistry.FILTER or ParameterRegistry.SORT     * @return Map of property/value pairs     */    public static Map getSortedOrFilteredParameters(BaseModel model, String parameter) {        Map subset = new HashMap();        String prefixWithCollection = model.getTableHandler().prefixWithCollection();        String find =  model.getTableHandler().prefixWithCollection() + parameter;        Set set = model.getRegistry().getParameters().keySet();        for (Iterator iter = set.iterator(); iter.hasNext();) {            String key = (String) iter.next();            if (key.startsWith(find)) {                String parameterToFind = StringUtils.substringAfter(key, prefixWithCollection);                 String value = (String) model.getRegistry().getParameter(parameterToFind);                if (StringUtils.isNotBlank(value)) {                    subset.put(StringUtils.substringAfter(key, find), value);                }            }        }        return subset;    }        /**     * generate the script to submit the filter     */    public static String doSearchJavaScript(BaseModel model) {        return "javascript:document." + model.getTableHandler().prefixWithCollection() + "filter."                + model.getTableHandler().prefixWithCollection() + ParameterRegistry.FILTER + FilterHandler.BUTTON + ".value='" + FilterHandler.SEARCH                + "';document." + model.getTableHandler().prefixWithCollection() + "filter.submit()";    }    /**     * generate the script to submit the pagination     */    public static String doPaginationJavaScript(BaseModel model) {        return "javascript:document." + model.getTableHandler().prefixWithCollection() + "toolbar.submit()";    }    /**     * Build up the cells in the row. Will either load up a known cell type, or     * just instantiate a new Cell using the fully qualified package name.     *      * NOTE: Whoever calls this is responsible for cleaning up the cell.     */    public static Cell buildCell(BaseModel model, Column column, Object value, Object propertyValue, int rowcount) {        String cellName = column.getCell();        String className = model.getProperties().getProperty(TableProperties.CELL + cellName);        return initCell(model, column, value, propertyValue, new Integer(rowcount), cellName, className);     }    /**     * Build up the cells in the row. Will either load up a known cell type, or     * just instantiate a new Cell using the fully qualified package name.     *      * NOTE: Whoever calls this is responsible for cleaning up the cell.     */    public static Cell buildFilterCell(BaseModel model, Column column, Object value) {        String cellName = column.getFilterCell();        String className = model.getProperties().getProperty(TableProperties.FILTER_CELL + cellName);        return initCell(model, column, value, value, null, cellName, className);     }    /**     * Build up the cells in the row. Will either load up a known cell type, or     * just instantiate a new Cell using the fully qualified package name.     *      * NOTE: Whoever calls this is responsible for cleaning up the cell.     */    public static Cell buildHeaderCell(BaseModel model, Column column, Object value) {        String cellName = column.getHeaderCell();        String className = model.getProperties().getProperty(TableProperties.HEADER_CELL + cellName);        return initCell(model, column, value, value, null, cellName, className);     }        private static Cell initCell(BaseModel model, Column column, Object value, Object propertyValue, Integer rowcount, String cellName, String cellClassName) {        Cell cell = null;        if (cellClassName == null) //a custom cell        {            cellClassName = cellName;        }        try {            cell = model.getCachedCell(Class.forName(cellClassName));            column.setValue(value);            column.setPropertyValue(propertyValue);            cell.init(model, column, rowcount);        } catch (Exception e) {            logger.error("Could not build the cell for column [" + column.getProperty()                    + "]. The class was not found or does not exist.", e);        }        return cell;    }}

⌨️ 快捷键说明

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