    001// Copyright 2011 The Apache Software Foundation
    002//
    003// Licensed under the Apache License, Version 2.0 (the "License");
    004// you may not use this file except in compliance with the License.
    005// You may obtain a copy of the License at
    006//
    007// http://www.apache.org/licenses/LICENSE-2.0
    008//
    009// Unless required by applicable law or agreed to in writing, software
    010// distributed under the License is distributed on an "AS IS" BASIS,
    011// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    012// See the License for the specific language governing permissions and
    013// limitations under the License.
    014
    015package org.apache.tapestry5.tree;
    016
    017import java.util.List;
    018
    019/**
    020 * Used with {@link DefaultTreeModel} to define how to extract labels and child nodes from a value.
    021 *
    022 * @since 5.3
    023 */
    024public interface TreeModelAdapter<T>
    025{
    026    /**
    027     * Determines if the value is a leaf or a (potential) container of children.
    028     *
    029     * @see TreeNode#isLeaf()
    030     */
    031    boolean isLeaf(T value);
    032
    033    /**
    034     * Returns true if the value has children (only invoked for non-leaf values).
    035     *
    036     * @see TreeNode#getHasChildren()
    037     */
    038    boolean hasChildren(T value);
    039
    040    /**
    041     * Returns the children, in the order they should be presented to the client.
    042     * This should return the childen in the correct presentation or, or return null or an empty list.
    043     *
    044     * @see TreeNode#getChildren()
    045     */
    046    List<T> getChildren(T value);
    047
    048    /**
    049     * Returns a text label for the value, which may be presented to the client.
    050     *
    051     * @see TreeNode#getLabel()
    052     */
    053    String getLabel(T value);
    054}