columntagutils.java

来自「分页查询控件 分页查询控件」· Java 代码 · 共 207 行

JAVA
207
字号
/* * 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.tag;import org.apache.commons.lang.StringUtils;import org.extremecomponents.base.BaseModel;import org.extremecomponents.base.BaseProperties;import org.extremecomponents.base.BaseResourceBundle;import org.extremecomponents.table.bean.Column;import org.extremecomponents.table.core.TableModelUtils;import org.extremecomponents.util.ExtremeUtils;/** * Pull all the values for the ColumnTag. Because the default values could be * coming from the properties or resource bundle this class will abstract that * out. *  * A very useful helper class, that should be called from any custom tags. *  * @author Jeff Johnston */public class ColumnTagUtils {    public static String getProperty(BaseModel model, String property) {        return property;    }    public static String getTitle(BaseModel model, String title, String property) {        if (StringUtils.isEmpty(title)) {            return ExtremeUtils.camelCaseToWord(property);        }        if (TableModelUtils.isResourceBundleProperty(title)) {            String resourceValue = model.getResourceBundle().getResource(title);            if (resourceValue != null) {                return resourceValue;            }        }        return title;    }    public static String getStyleClass(BaseModel model, String styleClass) {        return styleClass;    }    public static String getHeaderClass(BaseModel model, String headerClass) {        if (StringUtils.isEmpty(headerClass)) {            return model.getTableHandler().getTable().getHeaderClass();        }        return headerClass;    }    public static String getCell(BaseModel model, String cell) {        if (StringUtils.isBlank(cell)) {            return model.getProperties().getProperty(BaseProperties.CELL);        }        return cell;    }    public static String getFilterCell(BaseModel model, String filterCell) {        if (StringUtils.isBlank(filterCell)) {            return model.getProperties().getProperty(BaseProperties.FILTER_CELL);        }        return filterCell;    }    public static String getHeaderCell(BaseModel model, String headerCell) {        if (StringUtils.isBlank(headerCell)) {            return model.getProperties().getProperty(BaseProperties.HEADER_CELL);        }        return headerCell;    }    /**     * If this is a named format then it should be in the resource bundle. For     * backwards compatibility check the properties file also.     *      * Be sure to call the getCell() method before calling this method.     */    public static String getFormat(BaseModel model, String format, String cell) {        String result = getFormatInResourceBundle(model, format, cell);        if (StringUtils.isBlank(result)) {            result = getFormatInProperties(model, format, cell);        }        if (StringUtils.isNotBlank(result)) {            return result;        }        return format;    }    private static String getFormatInResourceBundle(BaseModel model, String format, String cell) {        if (StringUtils.isNotBlank(format) && isNamedFormat(format)) {            return model.getResourceBundle().getResourceByPrefix(BaseResourceBundle.FORMAT + format);        }                if (StringUtils.isBlank(format)) {            if (cell.equals(Column.CURRENCY)) {                return model.getResourceBundle().getResourceByPrefix(BaseResourceBundle.FORMAT + Column.CURRENCY);            } else if (cell.equals(Column.DATE)) {                return model.getResourceBundle().getResourceByPrefix(BaseResourceBundle.FORMAT + Column.DATE);            }        }        return null;    }    private static String getFormatInProperties(BaseModel model, String format, String cell) {        if (StringUtils.isNotBlank(format) && isNamedFormat(format)) {            return model.getProperties().getProperty(BaseResourceBundle.FORMAT + format);        }        if (StringUtils.isBlank(format)) {            if (cell.equals(Column.CURRENCY)) {                return model.getProperties().getProperty(BaseResourceBundle.FORMAT + Column.CURRENCY);            } else if (cell.equals(Column.DATE)) {                return model.getProperties().getProperty(BaseResourceBundle.FORMAT + Column.DATE);            }        }        return null;    }        /**     * If the format contains any of these formats then it is     * custom format doing inline.      */    private static boolean isNamedFormat(String format) {        char args[] = {'#', '/', '-'};        if (StringUtils.containsNone(format, args)) {            return true;        }                return false;    }    /**     * Be sure to call the getCell() method before calling this method.     */    public static String getParse(BaseModel model, String parse, String cell) {        if (StringUtils.isNotBlank(parse)) {            return parse;        }        if (cell.equals(Column.DATE)) {            return model.getProperties().getProperty(BaseProperties.PARSE + Column.DATE);        }        return parse;    }    public static String getFilterable(BaseModel model, String filterable) {        if (StringUtils.isEmpty(filterable)) {            return model.getTableHandler().getTable().getFilterable();        }        return filterable;    }    public static String getSortable(BaseModel model, String sortable) {        if (StringUtils.isEmpty(sortable)) {            return model.getTableHandler().getTable().getSortable();        }        return sortable;    }    public static String getWidth(BaseModel model, String width) {        return width;    }    public static String getStyle(BaseModel model, String style) {        return style;    }    public static String getExportable(BaseModel model, String exportable) {        if (StringUtils.isBlank(exportable)) {            return model.getProperties().getProperty(BaseProperties.EXPORTABLE);        }        return exportable;    }    public static String getShowTotal(BaseModel model, String showTotal) {        return showTotal;    }}

⌨️ 快捷键说明

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