001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.wicket.extensions.markup.html.repeater.data.table; 018 019import org.apache.wicket.AttributeModifier; 020import org.apache.wicket.Component; 021import org.apache.wicket.markup.html.WebComponent; 022import org.apache.wicket.markup.html.WebMarkupContainer; 023import org.apache.wicket.markup.html.navigation.paging.IPageableItems; 024import org.apache.wicket.markup.html.navigation.paging.PagingNavigator; 025import org.apache.wicket.model.IModel; 026 027/** 028 * Toolbar that displays links used to navigate the pages of the datatable as well as a message 029 * about which rows are being displayed and their total number in the data table. 030 * 031 * @author Igor Vaynberg (ivaynberg) 032 */ 033public class NavigationToolbar extends AbstractToolbar 034{ 035 private static final long serialVersionUID = 1L; 036 037 /** 038 * Constructor 039 * 040 * @param table 041 * data table this toolbar will be attached to 042 */ 043 public NavigationToolbar(final DataTable<?, ?> table) 044 { 045 super(table); 046 047 WebMarkupContainer span = new WebMarkupContainer("span"); 048 add(span); 049 span.add(AttributeModifier.replace("colspan", (IModel<String>) () -> String.valueOf(table.getColumns().size()).intern())); 050 051 span.add(newPagingNavigator("navigator", table)); 052 span.add(newNavigatorLabel("navigatorLabel", table)); 053 } 054 055 /** 056 * Factory method used to create the paging navigator that will be used by the datatable 057 * 058 * @param navigatorId 059 * component id the navigator should be created with 060 * @param table 061 * dataview used by datatable 062 * @return paging navigator that will be used to navigate the data table 063 */ 064 protected PagingNavigator newPagingNavigator(final String navigatorId, 065 final DataTable<?, ?> table) 066 { 067 return new PagingNavigator(navigatorId, table); 068 } 069 070 /** 071 * Factory method used to create the navigator label. 072 * 073 * @param navigatorId 074 * component id navigator label should be created with 075 * @param table 076 * DataTable used by datatable 077 * @return navigator label that will be used to navigate the data table 078 * 079 */ 080 protected Component newNavigatorLabel(final String navigatorId, final DataTable<?, ?> table) 081 { 082 return new NavigatorLabel(navigatorId, table); 083 } 084 085 /** {@inheritDoc} */ 086 @Override 087 protected void onConfigure() 088 { 089 super.onConfigure(); 090 setVisible(getTable().getPageCount() > 1); 091 } 092}