001    /*
002     * Copyright (c) 2005 Einar Pehrson, Malin Johansson and Sofia Nilsson
003     *
004     * This file is part of
005     * CleanSheets Extension for Dependency Trees
006     *
007     * CleanSheets Extension for Dependency Trees is free software; you can
008     * redistribute it and/or modify it under the terms of the GNU General Public
009     * License as published by the Free Software Foundation; either version 2 of
010     * the License, or (at your option) any later version.
011     *
012     * CleanSheets Extension for Dependency Trees is distributed in the hope that
013     * it will be useful, but WITHOUT ANY WARRANTY; without even the implied
014     * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
015     * See the GNU General Public License for more details.
016     *
017     * You should have received a copy of the GNU General Public License
018     * along with CleanSheets Extension for Dependency Trees; if not, write to the
019     * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
020     * Boston, MA  02111-1307  USA
021     */
022    package csheets.ext.deptree;
023    
024    import java.util.SortedSet;
025    import java.util.TreeSet;
026    
027    import javax.swing.tree.DefaultTreeModel;
028    
029    import csheets.core.Cell;
030    
031    /**
032     * A tree node for a cell, to which the cell's dependents are added dynamically
033     * when the node is expanded.
034     * @author Einar Pehrson
035     */
036    @SuppressWarnings("serial")
037    public class DependentsNode extends CellNode {
038    
039            /** The dependents of the node's cell. */
040            private SortedSet<Cell> dependents = new TreeSet<Cell>();
041    
042            /**
043             * Creates a new dependents node.
044             * @param cell the cell of the node
045             * @param treeModel the data model to which the node belongs
046             */
047            public DependentsNode(Cell cell, DefaultTreeModel treeModel) {
048                    super(cell, treeModel);
049                    dependents = cell.getDependents();
050            }
051    
052            protected void addChildren() {
053                    for (Cell dependent : dependents)
054                            add(new DependentsNode(dependent, treeModel));
055            }
056    
057            /**
058             * Returns whether the cell has references.
059             * @return true if the cell has references
060             */
061            public boolean isLeaf() {
062                    return dependents.isEmpty();
063            }
064    }