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
017/**
018 * Tracks which <em>leaf</em> nodes of a {@link TreeModel} are currently selected. The {@linkplain DefaultTreeSelectionModel default
019 * implementation} simply stores a set of {@linkplain TreeNode#getId() unique node
020 * ids} to identify selected nodes. The selection model is updated whenever the user clicks on the label for a leaf node.
021 * <p/>
022 * In the future, new methods may be added that will support selection of folders as well as leafs, and define the rules for
023 * how selections and de-selections propagate down to children or up to parents.
024 *
025 * @param <T> type of node
026 * @see org.apache.tapestry5.corelib.components.Tree
027 * @since 5.3
028 */
029public interface TreeSelectionModel<T>
030{
031
032    /**
033     * Returns {@code true}, if the given node is selected.
034     *
035     * @param node node to check
036     */
037    boolean isSelected(TreeNode<T> node);
038
039    /**
040     * Selects a node.
041     *
042     * @param node node to select
043     */
044    void select(TreeNode<T> node);
045
046    /**
047     * Unselects a node.
048     *
049     * @param node node to unselect
050     */
051    void unselect(TreeNode<T> node);
052
053    /**
054     * Clears the selection.
055     */
056    void clear();
057}