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.tree; 018 019import java.util.List; 020import java.util.Set; 021 022import org.apache.wicket.Component; 023import org.apache.wicket.extensions.markup.html.repeater.data.table.DataTable; 024import org.apache.wicket.extensions.markup.html.repeater.data.table.HeadersToolbar; 025import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn; 026import org.apache.wicket.extensions.markup.html.repeater.data.table.NavigationToolbar; 027import org.apache.wicket.extensions.markup.html.repeater.data.table.NoRecordsToolbar; 028import org.apache.wicket.extensions.markup.html.repeater.tree.content.Folder; 029import org.apache.wicket.extensions.markup.html.repeater.tree.theme.WindowsTheme; 030import org.apache.wicket.markup.repeater.Item; 031import org.apache.wicket.markup.repeater.OddEvenItem; 032import org.apache.wicket.model.IModel; 033 034/** 035 * An implementation of the TableTree that aims to solve the 90% usecase by using {@link Folder}s 036 * and by adding navigation, headers and no-records-found toolbars to a standard {@link TableTree}. 037 * 038 * @param <T> 039 * The node type 040 * @param <S> 041 * the type of the sorting parameter 042 * @author svenmeier 043 */ 044public class DefaultTableTree<T, S> extends TableTree<T, S> 045{ 046 047 private static final long serialVersionUID = 1L; 048 049 /** 050 * Construct. 051 * 052 * @param id 053 * component id 054 * @param columns 055 * columns for the {@link DataTable} 056 * @param provider 057 * the provider of the tree 058 * @param rowsPerPage 059 * rows to show on each page 060 */ 061 public DefaultTableTree(String id, List<? extends IColumn<T, S>> columns, 062 ISortableTreeProvider<T, S> provider, int rowsPerPage) 063 { 064 this(id, columns, provider, rowsPerPage, null); 065 } 066 067 /** 068 * Construct. 069 * 070 * @param id 071 * component id 072 * @param columns 073 * columns for the {@link DataTable} 074 * @param provider 075 * the provider of the tree 076 * @param rowsPerPage 077 * rows to show on each page 078 * @param state 079 * expansion state 080 */ 081 public DefaultTableTree(String id, List<? extends IColumn<T, S>> columns, 082 ISortableTreeProvider<T, S> provider, int rowsPerPage, IModel<? extends Set<T>> state) 083 { 084 super(id, columns, provider, rowsPerPage, state); 085 086 getTable().addTopToolbar(new NavigationToolbar(getTable())); 087 getTable().addTopToolbar(new HeadersToolbar<>(getTable(), provider)); 088 getTable().addBottomToolbar(new NoRecordsToolbar(getTable())); 089 090 add(new WindowsTheme()); 091 } 092 093 /** 094 * Creates {@link Folder} for each node. 095 * 096 * @param id 097 * component id 098 * @param model 099 * the node model 100 */ 101 @Override 102 protected Component newContentComponent(String id, IModel<T> model) 103 { 104 return new Folder<>(id, this, model); 105 } 106 107 /** 108 * Creates an {@link OddEvenItem}. 109 * 110 * @param id 111 * component id 112 * @param node 113 * the node model 114 */ 115 @Override 116 protected Item<T> newRowItem(String id, int index, IModel<T> node) 117 { 118 return new OddEvenItem<>(id, index, node); 119 } 120}