📄 paginationhandler.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 org.apache.commons.lang.StringUtils;import org.extremecomponents.base.BaseModel;import org.extremecomponents.table.core.ParameterRegistry;/** * Keep track of the page information * * @author Jeff Johnston */public class PaginationHandler { //toolbar statics public final static String FIRST = "First"; public final static String LAST = "Last"; public final static String PREV = "Prev"; public final static String NEXT = "Next"; public final static String PAGE = "Page"; //image statics public final static String LAST_PAGE = "lastPage"; public final static String LAST_PAGE_DISABLED = "lastPageDisabled"; public final static String FIRST_PAGE = "firstPage"; public final static String FIRST_PAGE_DISABLED = "firstPageDisabled"; public final static String PREV_PAGE = "prevPage"; public final static String PREV_PAGE_DISABLED = "prevPageDisabled"; public final static String NEXT_PAGE = "nextPage"; public final static String NEXT_PAGE_DISABLED = "nextPageDisabled"; private BaseModel model; public PaginationHandler(BaseModel model) { this.model = model; } public boolean isFirstPageEnabled(int page) { if (page == 1) { return false; } return true; } public boolean isPrevPageEnabled(int page) { if (page - 1 < 1) { return false; } return true; } public boolean isNextPageEnabled(int page, int totalPages) { if (page + 1 > totalPages) { return false; } return true; } public boolean isLastPageEnabled(int page, int totalPages) { if (page == totalPages || totalPages == 0) { return false; } return true; } public int getPage() { String pagination = model.getRegistry().getParameter(ParameterRegistry.PAGE); int page = 1; if (!StringUtils.isEmpty(pagination)) { page = Integer.parseInt(pagination); } return page; } public int getTotalPages() { int rowsDisplayed = Integer.parseInt(model.getTableHandler().getTable().getRowsDisplayed()); if (rowsDisplayed == 0) { rowsDisplayed = model.getTableHandler().getTotalRows(); } int totalRows = model.getTableHandler().getTotalRows(); int totalPages = 1; if (rowsDisplayed != 0) { totalPages = totalRows / rowsDisplayed; } if ((rowsDisplayed != 0) && ((totalRows % rowsDisplayed) > 0)) { totalPages++; } return totalPages; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -