Search this API

y.view.hierarchy
Class HierarchyTreeModel

java.lang.Object
  extended by y.view.hierarchy.HierarchyTreeModel
All Implemented Interfaces:
javax.swing.tree.TreeModel

public class HierarchyTreeModel
extends java.lang.Object
implements javax.swing.tree.TreeModel

This class represents a tree model view of a graph hierarchy managed by HierarchyManager. The tree model can be used with a JTree to visualize the nodes within the graph hierarchy.

The root of the tree model will be the root graph of the graph hierarchy. Any other element of the tree model will be a node within a graph within the hierarchy.

Whenever the graph hierarchy within the associated hierarchy manager changes the tree model will fire corresponding tree model events.

 

Constructor Summary
HierarchyTreeModel(HierarchyManager hierarchy)
          Creates a new instance of HierarchyTreeModel for the nodes within the given HierarchyManager.
 
Method Summary
 void addTreeModelListener(javax.swing.event.TreeModelListener l)
           
static java.util.Comparator createLabelTextComparator()
          Returns a comparator that compares Graph2D nodes by their label text.
static java.util.Comparator createNodeStateComparator(HierarchyManager hierarchy)
          Returns a comparator that uses the hierarchical state of the nodes as a first criterion.
static java.util.Comparator createToStringComparator()
          Returns a comparator that compares the nodes in the tree by their default string value.
 void dispose()
          Disposes this HierarchyTreeModel instance.
 java.lang.Object getChild(java.lang.Object parent, int index)
           
 java.util.Comparator getChildComparator()
          Returns the comparator used to sort the children in each folder.
 int getChildCount(java.lang.Object parent)
           
 int getIndexOfChild(java.lang.Object parent, java.lang.Object child)
           
 java.lang.Object getRoot()
           
 boolean isLeaf(java.lang.Object node)
           
 void removeTreeModelListener(javax.swing.event.TreeModelListener l)
           
 void setChildComparator(java.util.Comparator c)
          Sets a comparator used to sort the children in each folder.
 void valueForPathChanged(javax.swing.tree.TreePath path, java.lang.Object newValue)
          This method propagates the result of the inline editor to the label of the node in the Graph2D, as long as there is one.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HierarchyTreeModel

public HierarchyTreeModel(HierarchyManager hierarchy)
Creates a new instance of HierarchyTreeModel for the nodes within the given HierarchyManager.

Method Detail

dispose

public void dispose()
Disposes this HierarchyTreeModel instance. To free resources, this method should be called after a HierarchyTreeModel instance is not needed anymore.

Note: It is not safe to invoke any methods on a disposed HierarchyTreeModel instance. Doing so may result in NullPointerException being thrown.


setChildComparator

public void setChildComparator(java.util.Comparator c)
Sets a comparator used to sort the children in each folder.

By default no comparator is set.


getChildComparator

public java.util.Comparator getChildComparator()
Returns the comparator used to sort the children in each folder.


addTreeModelListener

public void addTreeModelListener(javax.swing.event.TreeModelListener l)
Specified by:
addTreeModelListener in interface javax.swing.tree.TreeModel

removeTreeModelListener

public void removeTreeModelListener(javax.swing.event.TreeModelListener l)
Specified by:
removeTreeModelListener in interface javax.swing.tree.TreeModel

getChild

public java.lang.Object getChild(java.lang.Object parent,
                                 int index)
Specified by:
getChild in interface javax.swing.tree.TreeModel

getChildCount

public int getChildCount(java.lang.Object parent)
Specified by:
getChildCount in interface javax.swing.tree.TreeModel

getIndexOfChild

public int getIndexOfChild(java.lang.Object parent,
                           java.lang.Object child)
Specified by:
getIndexOfChild in interface javax.swing.tree.TreeModel

getRoot

public java.lang.Object getRoot()
Specified by:
getRoot in interface javax.swing.tree.TreeModel

isLeaf

public boolean isLeaf(java.lang.Object node)
Specified by:
isLeaf in interface javax.swing.tree.TreeModel

valueForPathChanged

public void valueForPathChanged(javax.swing.tree.TreePath path,
                                java.lang.Object newValue)
This method propagates the result of the inline editor to the label of the node in the Graph2D, as long as there is one. Finally it updates all views, which might be affected by this change.

Specified by:
valueForPathChanged in interface javax.swing.tree.TreeModel

createToStringComparator

public static java.util.Comparator createToStringComparator()
Returns a comparator that compares the nodes in the tree by their default string value.


createLabelTextComparator

public static java.util.Comparator createLabelTextComparator()
Returns a comparator that compares Graph2D nodes by their label text.


createNodeStateComparator

public static java.util.Comparator createNodeStateComparator(HierarchyManager hierarchy)
Returns a comparator that uses the hierarchical state of the nodes as a first criterion. Group nodes and folder nodes will come first, then normal nodes. If two nodes have the same state then the label text of these nodes decides their order.


© Copyright 2000-2022,
yWorks GmbH.
All rights reserved.