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.markup.html.WebMarkupContainer; 021import org.apache.wicket.markup.html.basic.Label; 022import org.apache.wicket.model.IModel; 023import org.apache.wicket.model.ResourceModel; 024 025/** 026 * A toolbar that displays a "no records found" message when the data table contains no rows. 027 * <p> 028 * The message can be overridden by providing a resource with key 029 * <code>datatable.no-records-found</code> 030 * 031 * @see DefaultDataTable 032 * 033 * @author Igor Vaynberg (ivaynberg) 034 * 035 */ 036public class NoRecordsToolbar extends AbstractToolbar 037{ 038 private static final long serialVersionUID = 1L; 039 040 private static final IModel<String> DEFAULT_MESSAGE_MODEL = new ResourceModel( 041 "datatable.no-records-found"); 042 043 /** 044 * Constructor 045 * 046 * @param table 047 * data table this toolbar will be attached to 048 */ 049 public NoRecordsToolbar(final DataTable<?, ?> table) 050 { 051 this(table, DEFAULT_MESSAGE_MODEL); 052 } 053 054 /** 055 * @param table 056 * data table this toolbar will be attached to 057 * @param messageModel 058 * model that will be used to display the "no records found" message 059 */ 060 public NoRecordsToolbar(final DataTable<?, ?> table, final IModel<String> messageModel) 061 { 062 super(table); 063 064 WebMarkupContainer td = new WebMarkupContainer("td"); 065 add(td); 066 067 td.add(AttributeModifier.replace("colspan", new IModel<String>() 068 { 069 private static final long serialVersionUID = 1L; 070 071 @Override 072 public String getObject() 073 { 074 return String.valueOf(table.getColumns().size()).intern(); 075 } 076 })); 077 td.add(new Label("msg", messageModel)); 078 } 079 080 /** 081 * Only shows this toolbar when there are no rows 082 */ 083 @Override 084 protected void onConfigure() 085 { 086 super.onConfigure(); 087 setVisible(getTable().getRowCount() == 0); 088 } 089}