📄 pagingnavigationincrementlink.java
字号:
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.apache.wicket.markup.html.navigation.paging;import org.apache.wicket.Page;import org.apache.wicket.markup.html.link.Link;/** * An incremental link to a page of a PageableListView. Assuming your list view navigation looks * like * * <pre> * * [first / << / <] 1 | 2 | 3 [> / >> /last] * * </pre> * * <p> * and "<" meaning the previous and "<<" goto the "current page - 5", than it is this kind * of incremental page links which can easily be created. * * @author Juergen Donnerstag * @author Martijn Dashorst */public class PagingNavigationIncrementLink extends Link{ private static final long serialVersionUID = 1L; /** The increment. */ private final int increment; /** The PageableListView the page links are referring to. */ protected final IPageable pageable; /** * Constructor. * * @param id * See Component * @param pageable * The pageable component the page links are referring to * @param increment * increment by */ public PagingNavigationIncrementLink(final String id, final IPageable pageable, final int increment) { super(id); setAutoEnable(true); this.increment = increment; this.pageable = pageable; } /** * @see org.apache.wicket.markup.html.link.Link#onClick() */ public void onClick() { // Tell the PageableListView which page to print next pageable.setCurrentPage(getPageNumber()); // We do need to redirect, else refresh refresh will go to next, next setRedirect(true); // Return the current page. setResponsePage(getPage()); } /** * Determines the next page number for the pageable component. * * @return the new page number */ public final int getPageNumber() { // Determine the page number based on the current // PageableListView page and the increment int idx = pageable.getCurrentPage() + increment; // make sure the index lies between 0 and the last page return Math.max(0, Math.min(pageable.getPageCount() - 1, idx)); } /** * @return True if it is referring to the first page of the underlying PageableListView. */ public boolean isFirst() { return pageable.getCurrentPage() <= 0; } /** * @return True if it is referring to the last page of the underlying PageableListView. */ public boolean isLast() { return pageable.getCurrentPage() >= (pageable.getPageCount() - 1); } /** * Returns true if the page link links to the given page. * * @param page * ignored * @return True if this link links to the given page * @see org.apache.wicket.markup.html.link.PageLink#linksTo(org.apache.wicket.Page) */ public boolean linksTo(final Page page) { pageable.getCurrentPage(); return ((increment < 0) && isFirst()) || ((increment > 0) && isLast()); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -