projectviewer.vpt
Class ProjectCustomTreeModel

java.lang.Object
  extended by javax.swing.tree.DefaultTreeModel
      extended by projectviewer.vpt.ProjectTreeModel
          extended by projectviewer.vpt.ProjectCustomTreeModel
All Implemented Interfaces:
java.io.Serializable, javax.swing.tree.TreeModel
Direct Known Subclasses:
VPTCompactModel, VPTFileListModel, VPTFilteredModel, VPTWorkingFileListModel

public abstract class ProjectCustomTreeModel
extends ProjectTreeModel

A tree model for customized trees, trees that do not follow the node hierarchy as defined by the original data. This class provides some useful methods for caching and doing boring tree management work for these trees.

Since:
PV 3.0.0
Author:
Marcelo Vanzin
See Also:
Serialized Form

Field Summary
 
Fields inherited from class javax.swing.tree.DefaultTreeModel
asksAllowsChildren, listenerList, root
 
Constructor Summary
protected ProjectCustomTreeModel(VPTNode root)
           
 
Method Summary
protected  void addChild(VPTProject proj, VPTNode child)
          Adds a child to the list of children of the given project.
protected  javax.swing.tree.TreeNode[] buildPathToRoot(javax.swing.tree.TreeNode aNode, javax.swing.tree.TreeNode... children)
          Returns the path from the root to the given node, appending an optional list of children of the node to the path.
protected  java.util.Map<VPTProject,java.util.List<VPTNode>> getCache()
          Returns the internally cached children lists.
protected  java.util.List<VPTNode> getCachedChildren(VPTProject proj)
          Retrieves the list of child nodes from the given project, first trying the cache.
 java.lang.Object getChild(java.lang.Object parent, int index)
          Returns the child at the given index of the given parent.
 int getChildCount(java.lang.Object parent)
          Returns the number of children of the given node, based on the internal cached data.
protected abstract  java.util.List<VPTNode> getChildren(VPTProject proj)
          Subclasses should implement this method to populate the list of children of a project node.
 int getIndexOfChild(java.lang.Object parent, java.lang.Object child)
          Returns the index of the given child in the given parent, according to the information in the internal cache.
 javax.swing.tree.TreeNode[] getPathToRoot(javax.swing.tree.TreeNode aNode)
          Builds the path to the root of the tree up to the given node.
protected  boolean isCustom()
          Overrides the parent implementation, returning "true".
 void nodeChanged(javax.swing.tree.TreeNode node)
          Handles a node changed request.
 void nodeStructureChanged(javax.swing.tree.TreeNode node)
          Called when some node in the tree is changed.
 void projectClosed(VPTProject p)
          Remove data related to the project from the cache.
protected  void removeChild(VPTProject proj, VPTNode child)
          Remove a child from the internal cache for the given project.
 
Methods inherited from class projectviewer.vpt.ProjectTreeModel
fileClosed, fileOpened, getName
 
Methods inherited from class javax.swing.tree.DefaultTreeModel
addTreeModelListener, asksAllowsChildren, fireTreeNodesChanged, fireTreeNodesInserted, fireTreeNodesRemoved, fireTreeStructureChanged, getListeners, getPathToRoot, getRoot, getTreeModelListeners, insertNodeInto, isLeaf, nodesChanged, nodesWereInserted, nodesWereRemoved, reload, reload, removeNodeFromParent, removeTreeModelListener, setAsksAllowsChildren, setRoot, valueForPathChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ProjectCustomTreeModel

protected ProjectCustomTreeModel(VPTNode root)
Method Detail

getChild

public java.lang.Object getChild(java.lang.Object parent,
                                 int index)
Returns the child at the given index of the given parent. If the parent is a project, treats the children in such a way to allow all files in the project to be displayed in a flat list.

Specified by:
getChild in interface javax.swing.tree.TreeModel
Overrides:
getChild in class javax.swing.tree.DefaultTreeModel

getChildCount

public int getChildCount(java.lang.Object parent)
Returns the number of children of the given node, based on the internal cached data.

Specified by:
getChildCount in interface javax.swing.tree.TreeModel
Overrides:
getChildCount in class javax.swing.tree.DefaultTreeModel

getIndexOfChild

public int getIndexOfChild(java.lang.Object parent,
                           java.lang.Object child)
Returns the index of the given child in the given parent, according to the information in the internal cache.

Specified by:
getIndexOfChild in interface javax.swing.tree.TreeModel
Overrides:
getIndexOfChild in class javax.swing.tree.DefaultTreeModel

getPathToRoot

public javax.swing.tree.TreeNode[] getPathToRoot(javax.swing.tree.TreeNode aNode)
Builds the path to the root of the tree up to the given node.

Overrides:
getPathToRoot in class javax.swing.tree.DefaultTreeModel

nodeChanged

public void nodeChanged(javax.swing.tree.TreeNode node)
Handles a node changed request.

Overrides:
nodeChanged in class javax.swing.tree.DefaultTreeModel

nodeStructureChanged

public void nodeStructureChanged(javax.swing.tree.TreeNode node)
Called when some node in the tree is changed. If not the root, then tracks down which project was changed and forces a refresh of the internal cache of child nodes.

Overrides:
nodeStructureChanged in class javax.swing.tree.DefaultTreeModel

projectClosed

public void projectClosed(VPTProject p)
Remove data related to the project from the cache.

Overrides:
projectClosed in class ProjectTreeModel

addChild

protected void addChild(VPTProject proj,
                        VPTNode child)
Adds a child to the list of children of the given project.


buildPathToRoot

protected javax.swing.tree.TreeNode[] buildPathToRoot(javax.swing.tree.TreeNode aNode,
                                                      javax.swing.tree.TreeNode... children)
Returns the path from the root to the given node, appending an optional list of children of the node to the path.


getCache

protected java.util.Map<VPTProject,java.util.List<VPTNode>> getCache()
Returns the internally cached children lists.


getCachedChildren

protected java.util.List<VPTNode> getCachedChildren(VPTProject proj)
Retrieves the list of child nodes from the given project, first trying the cache.


getChildren

protected abstract java.util.List<VPTNode> getChildren(VPTProject proj)
Subclasses should implement this method to populate the list of children of a project node. Whenever a "cache miss" occurs, this method will be called to return the list of nodes to be added to the internal cache as the "children" of the given project.

Parameters:
proj - The project being queried.

isCustom

protected boolean isCustom()
Overrides the parent implementation, returning "true".

Overrides:
isCustom in class ProjectTreeModel

removeChild

protected void removeChild(VPTProject proj,
                           VPTNode child)
Remove a child from the internal cache for the given project.