01: /*
02: * $Id: NoRecordsToolbar.java 458270 2005-12-09 07:43:11Z ivaynberg $
03: * $Revision: 458270 $
04: * $Date: 2005-12-09 08:43:11 +0100 (Fri, 09 Dec 2005) $
05: *
06: * ====================================================================
07: * Licensed under the Apache License, Version 2.0 (the "License");
08: * you may not use this file except in compliance with the License.
09: * You may obtain a copy of the License at
10: *
11: * http://www.apache.org/licenses/LICENSE-2.0
12: *
13: * Unless required by applicable law or agreed to in writing, software
14: * distributed under the License is distributed on an "AS IS" BASIS,
15: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16: * See the License for the specific language governing permissions and
17: * limitations under the License.
18: */
19: package wicket.extensions.markup.html.repeater.data.table;
20:
21: import wicket.AttributeModifier;
22: import wicket.Component;
23: import wicket.markup.html.WebMarkupContainer;
24: import wicket.markup.html.basic.Label;
25: import wicket.model.AbstractReadOnlyModel;
26: import wicket.model.IModel;
27: import wicket.model.Model;
28:
29: /**
30: * A toolbar that displays a "no records found" message when the data table
31: * contains no rows.
32: * <p>
33: * The message can be overridden by providing a resource with key
34: * <code>datatable.no-records-found</code>
35: *
36: * @see DefaultDataTable
37: *
38: * @author Igor Vaynberg (ivaynberg)
39: *
40: */
41: public class NoRecordsToolbar extends AbstractToolbar {
42: private static final long serialVersionUID = 1L;
43:
44: private static final IModel DEFAULT_MESSAGE_MODEL = new AbstractReadOnlyModel() {
45: private static final long serialVersionUID = 1L;
46:
47: public Object getObject(Component component) {
48: return component.getLocalizer().getString(
49: "datatable.no-records-found", component,
50: "No Records Found");
51: }
52: };
53:
54: /**
55: * Constructor
56: *
57: * @param table
58: * data table this toolbar will be attached to
59: */
60: public NoRecordsToolbar(final DataTable table) {
61: this (table, DEFAULT_MESSAGE_MODEL);
62: }
63:
64: /**
65: * @param table
66: * data table this toolbar will be attached to
67: * @param messageModel
68: * model that will be used to display the "no records found"
69: * message
70: */
71: public NoRecordsToolbar(final DataTable table, IModel messageModel) {
72: super (table);
73: WebMarkupContainer td = new WebMarkupContainer("td");
74: add(td);
75:
76: td.add(new AttributeModifier("colspan", true, new Model(String
77: .valueOf(table.getColumns().length))));
78: td.add(new Label("msg", messageModel));
79: }
80:
81: /**
82: * Only shows this toolbar when there are no rows
83: *
84: * @see wicket.Component#isVisible()
85: */
86: public boolean isVisible() {
87: return getTable().getRowCount() == 0;
88: }
89:
90: }
|