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.Iterator; 020 021import org.apache.wicket.model.IDetachable; 022import org.apache.wicket.model.IModel; 023 024/** 025 * Provider of a tree. 026 * 027 * You can use the {@link IDetachable#detach()} method for cleaning up your ITreeProvider instance. 028 * 029 * @see IDetachable 030 * @see AbstractTree 031 * 032 * @author svenmeier 033 * @param <T> 034 * the node type 035 */ 036public interface ITreeProvider<T> extends IDetachable 037{ 038 039 /** 040 * Get the roots of the tree. 041 * 042 * @return roots 043 */ 044 Iterator<? extends T> getRoots(); 045 046 /** 047 * Does the given object have children - note that this method may return <code>true</code> even 048 * if {@link #getChildren(Object)} returns an empty iterator. 049 * 050 * @param node 051 * the node to check for children 052 * @return {@code true} if node has children 053 */ 054 boolean hasChildren(T node); 055 056 /** 057 * Get the children of the given node. 058 * 059 * @param node 060 * node to get children for 061 * @return children of node 062 */ 063 Iterator<? extends T> getChildren(T node); 064 065 /** 066 * Callback used by the consumer of this tree provider to wrap objects retrieved from 067 * {@link #getRoots()} or {@link #getChildren(Object)} with a model (usually a detachable one). 068 * <p> 069 * Important note: The model must implement {@link Object#equals(Object)} and 070 * {@link Object#hashCode()} ! 071 * 072 * @param object 073 * the object that needs to be wrapped 074 * 075 * @return the model representation of the object 076 */ 077 IModel<T> model(T object); 078}