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.ajax.markup.html.repeater.data.table;
018
019import java.util.List;
020
021import org.apache.wicket.extensions.markup.html.repeater.data.table.DataTable;
022import org.apache.wicket.extensions.markup.html.repeater.data.table.HeadersToolbar;
023import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn;
024import org.apache.wicket.extensions.markup.html.repeater.data.table.ISortableDataProvider;
025import org.apache.wicket.extensions.markup.html.repeater.data.table.NavigationToolbar;
026import org.apache.wicket.extensions.markup.html.repeater.data.table.NoRecordsToolbar;
027import org.apache.wicket.markup.repeater.Item;
028import org.apache.wicket.markup.repeater.OddEvenItem;
029import org.apache.wicket.model.IModel;
030
031
032/**
033 * An implementation of the DataTable that aims to solve the 90% usecase by adding navigation,
034 * headers, an no-records-found toolbars to a standard {@link DataTable}.
035 * <p>
036 * The {@link NavigationToolbar} and the {@link HeadersToolbar} are added as top toolbars, while the
037 * {@link NoRecordsToolbar} toolbar is added as a bottom toolbar.
038 * 
039 * @see DataTable
040 * @see HeadersToolbar
041 * @see NavigationToolbar
042 * @see NoRecordsToolbar
043 * 
044 * @author Igor Vaynberg ( ivaynberg )
045 * 
046 * @param <T>
047 *     The model object type
048 * @param <S>
049 *     the type of the sorting parameter
050 * 
051 */
052public class AjaxFallbackDefaultDataTable<T, S> extends DataTable<T, S>
053{
054        private static final long serialVersionUID = 1L;
055
056        /**
057         * Constructor
058         * 
059         * @param id
060         *            component id
061         * @param columns
062         *            list of columns
063         * @param dataProvider
064         *            data provider
065         * @param rowsPerPage
066         *            number of rows per page
067         */
068        public AjaxFallbackDefaultDataTable(final String id, final List<? extends IColumn<T, S>> columns,
069                final ISortableDataProvider<T, S> dataProvider, final int rowsPerPage)
070        {
071                super(id, columns, dataProvider, rowsPerPage);
072                setOutputMarkupId(true);
073                setVersioned(false);
074                addToolBars(dataProvider);
075        }
076
077        /**
078         * Factory method for toolbars
079         * @param dataProvider {@link org.apache.wicket.extensions.markup.html.repeater.data.table.ISortableDataProvider}
080         */
081        protected void addToolBars(final ISortableDataProvider<T, S> dataProvider)
082        {
083                addTopToolbar(new AjaxNavigationToolbar(this));
084                addTopToolbar(new AjaxFallbackHeadersToolbar<>(this, dataProvider));
085                addBottomToolbar(new NoRecordsToolbar(this));
086        }
087
088        @Override
089        protected Item<T> newRowItem(final String id, final int index, final IModel<T> model)
090        {
091                return new OddEvenItem<>(id, index, model);
092        }
093
094}