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 * A node within a {@link TreeModel}. In a {@link DefaultTreeModel}, most of the node's information
021 * comes via the {@link TreeModelAdapter}.
022 * 
023 * @param <T>
024 *            type of node
025 * @since 5.3
026 */
027public interface TreeNode<T>
028{
029    /**
030     * Returns a string Id for the node that uniquely identifies it.
031     * 
032     * @return unique string identifying the node
033     * @see TreeModel#getById(String)
034     */
035    String getId();
036
037    /** Returns the value represented by this node. */
038    T getValue();
039
040    /**
041     * If true, then this node is a leaf node, which never has children (i.e., a file). If false, the node
042     * may have children (i.e., a folder).
043     * 
044     * @return true for leaf nodes, false for folder nodes
045     * @see TreeModelAdapter#isLeaf(Object)
046     */
047    boolean isLeaf();
048
049    /**
050     * Returns true if this non-leaf node has child nodes. This will not be invoked for leaf nodes.
051     * 
052     * @see TreeModelAdapter#hasChildren(Object)
053     */
054    boolean getHasChildren();
055
056    /**
057     * Returns the actual children of this non-leaf node, as additional nodes.
058     * 
059     * @see TreeModelAdapter#getChildren(Object)
060     */
061    List<TreeNode<T>> getChildren();
062
063    // TODO: Some way to influence the rendered output (i.e., to display different icons based on
064    // file type).
065
066    /**
067     * Returns a textual label for the node. Not all UIs will make use of the label, but default UIs will.
068     * 
069     * @see TreeModelAdapter#getLabel(Object)
070     */
071    public String getLabel();
072}