001    /*
002     * $Id: MutableTreeTableNode.java 2476 2007-11-25 15:52:59Z kschaefe $
003     *
004     * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
005     * Santa Clara, California 95054, U.S.A. All rights reserved.
006     *
007     * This library is free software; you can redistribute it and/or
008     * modify it under the terms of the GNU Lesser General Public
009     * License as published by the Free Software Foundation; either
010     * version 2.1 of the License, or (at your option) any later version.
011     * 
012     * This library is distributed in the hope that it will be useful,
013     * but WITHOUT ANY WARRANTY; without even the implied warranty of
014     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
015     * Lesser General Public License for more details.
016     * 
017     * You should have received a copy of the GNU Lesser General Public
018     * License along with this library; if not, write to the Free Software
019     * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
020     */
021    package org.jdesktop.swingx.treetable;
022    
023    import java.util.Enumeration;
024    
025    /**
026     * Defines the requirements for a tree table node object that can change -- by
027     * adding or removing child nodes, or by changing the contents of a user object
028     * stored in the node.
029     * <p>
030     * Note this does not extend {@code MutableTreeNode} to minimize the contract
031     * breakage, cf. {@link TreeTableNode#getIndex(javax.swing.tree.TreeNode)}.
032     * 
033     * @see javax.swing.tree.MutableTreeNode
034     * 
035     * @author Karl Schaefer
036     */
037    public interface MutableTreeTableNode extends TreeTableNode {
038        /**
039         * Returns an enumeration this node's children.
040         * 
041         * @return an enumeration of {@code TreeTableNode}s
042         */
043        Enumeration<? extends MutableTreeTableNode> children();
044        
045        /**
046         * Adds the {@code child} to this node at the specified {@code index}. This
047         * method calls {@code setParent} on {@code child} with {@code this} as the
048         * parameter.
049         * 
050         * @param child
051         *            the node to add as a child
052         * @param index
053         *            the index of the child
054         * @throws IndexOutOfBoundsException
055         *             if {@code index} is not a valid index
056         */
057        void insert(MutableTreeTableNode child, int index);
058    
059        /**
060         * Removes the child node at the specified {@code index} from this node.
061         * This method calls {@code setParent} on {@code child} with a {@code null}
062         * parameter.
063         * 
064         * @param index
065         *            the index of the child
066         * @throws IndexOutOfBoundsException
067         *             if {@code index} is not a valid index
068         */
069        void remove(int index);
070    
071        /**
072         * Removes the specified child {@code node} from this node.
073         * This method calls {@code setParent} on {@code child} with a {@code null}
074         * parameter.
075         * 
076         * @param node
077         *            the index of the child
078         */
079        void remove(MutableTreeTableNode node);
080    
081        /**
082         * Removes this node from it's parent. Most implementations will use
083         * {@code getParent().remove(this)}.
084         * 
085         * @throws NullPointerException
086         *             if {@code getParent()} returns {@code null}
087         */
088        void removeFromParent();
089    
090        /**
091         * Sets the parent of this node to {@code newParent}. This methods remove
092         * the node from its old parent.
093         * 
094         * @param newParent
095         *            the new parent for this node
096         */
097        void setParent(MutableTreeTableNode newParent);
098    }