    001// Licensed under the Apache License, Version 2.0 (the "License");
    002// you may not use this file except in compliance with the License.
    003// You may obtain a copy of the License at
    004//
    005// http://www.apache.org/licenses/LICENSE-2.0
    006//
    007// Unless required by applicable law or agreed to in writing, software
    008// distributed under the License is distributed on an "AS IS" BASIS,
    009// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    010// See the License for the specific language governing permissions and
    011// limitations under the License.
    012
    013package org.apache.tapestry5.tree;
    014
    015/**
    016 * Tracks which <em>leaf</em> nodes of a {@link TreeModel} are currently selected. The {@linkplain DefaultTreeSelectionModel default
    017 * implementation} simply stores a set of {@linkplain TreeNode#getId() unique node
    018 * ids} to identify selected nodes. The selection model is updated whenever the user clicks on the label for a leaf node.
    019 *
    020 * In the future, new methods may be added that will support selection of folders as well as leafs, and define the rules for
    021 * how selections and de-selections propagate down to children or up to parents.
    022 *
    023 * @param <T> type of node
    024 * @see org.apache.tapestry5.corelib.components.Tree
    025 * @since 5.3
    026 */
    027public interface TreeSelectionModel<T>
    028{
    029
    030    /**
    031     * Returns {@code true}, if the given node is selected.
    032     *
    033     * @param node node to check
    034     */
    035    boolean isSelected(TreeNode<T> node);
    036
    037    /**
    038     * Selects a node.
    039     *
    040     * @param node node to select
    041     */
    042    void select(TreeNode<T> node);
    043
    044    /**
    045     * Unselects a node.
    046     *
    047     * @param node node to unselect
    048     */
    049    void unselect(TreeNode<T> node);
    050
    051    /**
    052     * Clears the selection.
    053     */
    054    void clear();
    055}