📄 modellimitfactory.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.limit;import java.util.HashMap;import java.util.Iterator;import java.util.Map;import java.util.Set;import org.apache.commons.lang.StringUtils;import org.extremecomponents.table.core.BaseModel;import org.extremecomponents.table.core.TableConstants;/** * @author Jeff Johnston */public final class ModelLimitFactory { public static Limit createInstanceOfLimit(BaseModel model) { return new ModelLimit(model); } public static void setLimitFilterAndSortAttr(Limit limit) { limit.setFilterSet(getFilterSet((ModelLimit)limit)); limit.setSort(getSort((ModelLimit)limit)); } public static void setLimitPageAndRowAttr(Limit limit, int totalRows) { if (limit.getTotalRows() != 0) { totalRows = limit.getTotalRows(); } int currentRowsDisplayed = resolveCurrentRowsDisplayed((ModelLimit)limit, totalRows); int page = getPage((ModelLimit)limit); int rowStart = (page - 1) * currentRowsDisplayed; int rowEnd = rowStart + currentRowsDisplayed; if (rowEnd > totalRows) { rowEnd = totalRows; } limit.setPage(page); limit.setCurrentRowsDisplayed(currentRowsDisplayed); limit.setTotalRows(totalRows); limit.setRowStart(rowStart); limit.setRowEnd(rowEnd); } private static int resolveCurrentRowsDisplayed(ModelLimit limit, int totalRows) { boolean invokeExport = limit.getModel().getExportHandler().invokeExport(); boolean showPagination = limit.getModel().getTableHandler().getTable().showPagination(); if (invokeExport || !showPagination) { return totalRows; } String currentRowsDisplayed = limit.getModel().getRegistry().getParameter(TableConstants.CURRENT_ROWS_DISPLAYED); if (StringUtils.isNotBlank(currentRowsDisplayed)) { return Integer.parseInt(currentRowsDisplayed); } return limit.getModel().getTableHandler().getTable().getRowsDisplayed(); } private static int getPage(ModelLimit limit) { String pagination = limit.getModel().getRegistry().getParameter(TableConstants.PAGE); if (!StringUtils.isEmpty(pagination)) { return Integer.parseInt(pagination); } return 1; } private static Sort getSort(ModelLimit limit) { Map sortedParameters = getSortedOrFilteredParameters(limit, TableConstants.SORT); return LimitFactoryUtils.getSort(sortedParameters); } private static FilterSet getFilterSet(ModelLimit limit) { Map filteredParameters = getSortedOrFilteredParameters(limit, TableConstants.FILTER); FilterSet filterSet = LimitFactoryUtils.getFilterSet(filteredParameters); if (filterSet.isCleared()) { limit.getModel().getRegistry().clearParameters(TableConstants.FILTER); } return filterSet; } private static Map getSortedOrFilteredParameters(ModelLimit limit, String parameter) { Map subset = new HashMap(); String prefixWithTableId = limit.getModel().getTableHandler().prefixWithTableId(); String find = limit.getModel().getTableHandler().prefixWithTableId() + parameter; Set set = limit.getModel().getRegistry().getParameters().keySet(); for (Iterator iter = set.iterator(); iter.hasNext();) { String key = (String) iter.next(); if (key.startsWith(find)) { String parameterToFind = StringUtils.substringAfter(key, prefixWithTableId); String value = limit.getModel().getRegistry().getParameter(parameterToFind); if (StringUtils.isNotBlank(value)) { subset.put(StringUtils.substringAfter(key, find), value); } } } return subset; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -