|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--y.view.hierarchy.HierarchyManager
This class manages a hierarchy of grouped nodes and nested graphs. A graph hierarchy always contains a top level graph called the root graph. Each graph within the hierarchy can have an arbitrary number of nodes. These nodes can either be normal nodes, group nodes or so called folder nodes. Folder nodes serve as proxy elements to access graphs in a lower hierarchy level. The graph that is accessible from a folder node is called the inner graph of that node. A folder node is also called anchor node, since it serves to attach an inner graph to a hierarchically higher graph. The hierarchically higher graph is called the parent graph of the inner graph.
Like a folder node, a group node can also contain other nodes that conceptually belong to a lower hierarchy level. Unlike a folder node, the child nodes of a group nodes belong to the same graph as the group node itself.
A hierarchy manager allows to create and remove new group and folder nodes within a graph. It allows to move part of a graph a level up the hierarchy or a level down the hierarchy. It also allows to group and ungroup nodes.
When moving parts of a graph to another hierarchy level it is possible that the endpoints of edges come to lie in different graphs. The hierarchy manager will automatically redirect such edges in a clever and consistent way. An edge will always be part of the graph that is the hierarchically highest common ancestor of the graphs that contain the original source and target nodes of the edge. In case the original endpoint of the edge is not in the same graph, then the folder node hosting this endpoint will be chosen as local endpont of that edge. Such a redirected edge is called an interedge, since it actually connects nodes in different graphs. The original endpoints of an interedge are called real node and real target.
A hierarchy manager fires high level events that signal the change of the
hierarchic structure and the change of the node elements within the hierarchy.
Clients interested in this information must implement the HierarchyListener
interface and register to the hierarchy manager. Listeners will be informed by receiving
messages of type HierarchyEvent
whenever the hierarchy changes.
Note that hierarchy events of type HierarchyEvent.NODE_CHANGED
will not
be fired by the HierarchyManager itself since it does not know enough about
specific nodes. In order to receive NODE_CHANGED hierarchy events it is necessary
to add a Graph-, or Graph2DListener to the root graph of the hierarchy that
translates the incoming events to HierarchyEvents. Class DefaultNodeChangePropagator
for example, serves this purpose.
The hierarchy manager is also responsible for creating new nodes and graphs
when the hierarchy grows. A hierachy manager uses an aggregated factory of type
GraphFactory
to create these elements. Clients can provide their own
factories to customize graph object creation.
Nested Class Summary | |
static interface |
HierarchyManager.NodeVisitor
Callback interface that allows to perform some action when nodes within the hierarchy get visited in a certain order. |
Constructor Summary | |
HierarchyManager(Graph root)
Creates a new hierarchy manager that initially manages a flat graph hierarchy whose root graph will be the given graph. |
|
HierarchyManager(Graph root,
GraphFactory factory)
Creates a new hierarchy manager that initially manages a flat graph hierarchy whose root graph will be the given graph. |
Method Summary | |
void |
addHierarchyListener(HierarchyListener listener)
Adds a HierarchyListener to this HierarchyManager; |
void |
closeGroup(Node groupNode)
Convenience method that performs all necessary steps to convert a group node to a folder node. |
boolean |
contains(Graph graph)
Returns whether or not the given graph is part of this graph hierarchy |
static boolean |
containsGroupNodes(Graph graph)
Whether or not the given graph contains any group nodes. |
boolean |
containsGroups()
Queries the hierarchy if it contains any group nodes. |
void |
convertToFolderNode(Node v)
Converts a group node or a normal node to a folder node. |
void |
convertToFolderNode(Node v,
Graph innerGraph)
Like HierarchyManager.convertToFolderNode(y.base.Node) with the additional option to
specify the inner graph to be used by the folder node. |
void |
convertToGroupNode(Node v)
Converts a folder node or a normal node to a group node Emits HierarchyEvents of type HierarchyEvent.PRE_NODE_STATE_CHANGE
and HierarchyEvent.NODE_STATE_CHANGED . |
void |
convertToInterEdge(Edge e,
Node realSource,
Node realTarget)
Converts a normal edge to an inter edge. |
void |
convertToNormalEdge(Edge e)
Converts an inter edge to a normal edge. |
void |
convertToNormalNode(Node v)
Converts a group or folder node to a normal node. |
Node |
createFolderNode(Graph parentGraph)
Similar to HierarchyManager.createFolderNode(Node) . |
Node |
createFolderNode(Node parent)
Returns a newly created folder node that will be created as a child node of the given folder or group node. |
Node |
createGroupNode(Graph graph)
Similar to HierarchyManager.createGroupNode(Node) . |
Node |
createGroupNode(Node parent)
Returns a newly created group node that will be created as a child node of the given group or folder node. |
void |
dispose()
Disposes this HierarchtyManager instance. |
protected void |
fireHierarchyEvent(HierarchyEvent e)
Propagates the given hierarchy event to all registered hierarchy listeners. |
void |
foldSubgraph(NodeList subNodes,
Node folderNode)
Moves part of a graph into a folder node. |
Node |
getAnchorNode(Graph graph)
Returns the anchor node of the given graph. |
NodeCursor |
getChildren(Node node)
Returns all direct child nodes of a group or folder node. |
NodeList |
getFolderNodes(Graph rootGraph,
boolean recursive)
Returns all folder nodes that are either contained in given graph or contained in the given graph or one of its graph decendants. |
Object[] |
getFolderPath(Object item)
Returns the hierarchy of folder nodes that lie above the given item within this hierarchy. |
GraphFactory |
getGraphFactory()
Returns the registered graph factory of this hierarchy manager. |
DataProvider |
getGroupNodeDataProvider()
Returns a data provider the provides boolean values for each node indicating whether or not the given node is a group node. |
Graph |
getInnerGraph(Node folderNode)
Returns the inner graph accessible from the given folder node. |
static HierarchyManager |
getInstance(Graph graph)
This static method returns the hierarchy manager instance that is responsible for managing the given graph. |
InterEdgeConfigurator |
getInterEdgeConfigurator()
Returns the InterEdgeConfigurator used by this class. |
int |
getLocalGroupDepth(Node node)
Returns the hierarchy level of the given node within its graph. |
Graph |
getNearestCommonAncestor(Graph g1,
Graph g2)
Finds the graph that is the nearest common ancestor of two graphs in the hierarchy. |
Node |
getNearestCommonAncestor(NodeList subNodes)
Finds the group or folder node that is the nearest common ancestor of all given nodes. |
DataProvider |
getNodeIdDataProvider()
Returns a data provider the provides a unique ID for each node within the hierarchy. |
Graph |
getParentGraph(Graph graph)
Returns the parent graph of the given graph within this hierarchy. |
Node |
getParentNode(Node node)
Returns the parent node of the given node. |
DataProvider |
getParentNodeIdDataProvider()
Returns a data provider the provides the parent ID for each node within the hierarchy. |
Node |
getRealSource(Edge e)
Returns the real source node associated with the given inter edge. |
Node |
getRealTarget(Edge e)
Returns the real target node associated with the given inter edge. |
Graph |
getRootGraph()
Returns the root graph of this hierarchy. |
Object[] |
getTreePath(Object item)
Returns the hierarchy of group and folder nodes that lie above the given item within this hierarchy. |
Object[] |
getTreePath(Object item,
boolean includeItem)
Like HierarchyManager.getTreePath(Object) with the additional option to
include the given item as the last element of the path. |
void |
groupSubgraph(NodeList subNodes,
Node groupNode)
Assigns the given nodes to the given group node. |
boolean |
isAncestor(Node presumedAncestor,
Node node)
Queries the hierarchy if a given node is an ancestor of another node in the hierarchy. |
boolean |
isFolderNode(Node v)
Returns whether or not the given node is a folder node. |
boolean |
isGroupNode(Node v)
Returns whether or not the given node is agroup node. |
boolean |
isInterEdge(Edge e)
Returns whether or not the given edge is an inter edge. |
boolean |
isNormalNode(Node v)
Returns whether or not the given node is a normal node, i.e. neither group nor folder node. |
boolean |
isRootGraph(Graph graph)
Returns whether or not the given graph is the root graph of this hierarchy. |
void |
moveToFirst(Node childNode)
Makes the given node the first child of its parent. |
void |
moveToLast(Node childNode)
Makes the given node the last child of its parent. |
void |
openFolder(Node folderNode)
Convenience method that performs all necessary steps to convert a folder node to a group node. |
void |
postTraverse(HierarchyManager.NodeVisitor visitor)
Posttraverse all nodes within the hierarchy. |
void |
postTraverse(Node rootNode,
HierarchyManager.NodeVisitor visitor)
Posttraverse all nodes within the hierarchy, that are descendants of the given group or folder node. |
void |
preTraverse(HierarchyManager.NodeVisitor visitor)
Pretraverse all nodes within the hierarchy. |
void |
preTraverse(Node rootNode,
HierarchyManager.NodeVisitor visitor)
Pretraverse all nodes within the hierarchy, that are descendants of the given group or folder node. |
void |
removeHierarchyListener(HierarchyListener listener)
Removes the given HierarchyListener from the lsit of registered listeners of this HierarchyManager. |
void |
setGraphFactory(GraphFactory factory)
Sets the graph factory used by this manager to create new nodes and graphs. |
void |
setInterEdgeConfigurator(InterEdgeConfigurator interEdgeConfigurator)
Sets the InterEdgeConfigurator for this class. |
void |
unfoldSubgraph(Graph innerGraph,
NodeList subNodes)
Moves part of a nested graph up the hierarchy to the parent graph. |
void |
ungroupSubgraph(NodeList subNodes)
Conveniance method that moves all given nodes a hierarchy level up, if possible. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public HierarchyManager(Graph root)
Graph factory DefaultHierarchyGraphFactory
is used by default.
HierarchyManager.HierarchyManager(Graph, GraphFactory)
public HierarchyManager(Graph root, GraphFactory factory)
The given graph factory is used by this manager to create new nodes and graphs. The graph factory is responsible for creating the right kind of node and graph elements within this hierarchy. The factory is also responsible for propagating registered listeners from the parent graph to the newly generated graphs.
The hierarchy manager passes certain hints to the registered graph factory. If the hint for node creation is of type Graph then the created node will be a folder node whose inner graph is represented by the hint. The hint for graph creation is always the parent graph of the newly created graph.
By default a factory of type DefaultHierarchyGraphFactory
is set.
Method Detail |
public static HierarchyManager getInstance(Graph graph)
graph
- a graph whose associated hierarchy manager is being sought.
null
in case the given graph is not part of a hierarchy.public void dispose()
public Node createFolderNode(Node parent)
GraphFactory
is responsible for both
the creation of the new inner graph accessible by the folder node and
the folder node itself.
Emits a HierarchyEvents of type HierarchyEvent.PRE_NODE_STATE_CHANGE
,
and HierarchyEvent.NODE_STATE_CHANGED
.
parent
- the node that represents the graph in which to create the folder node.
public Node createFolderNode(Graph parentGraph)
HierarchyManager.createFolderNode(Node)
. The newly created folder node will
be created as a child node of getAnchorNode(parentGraph))
.
public Node createGroupNode(Node parent)
GraphFactory
is responsible for the creation
and configuration of the group node.
Emits a HierarchyEvent of type HierarchyEvent.PRE_NODE_STATE_CHANGE
and
HierarchyEvent.NODE_STATE_CHANGED
.
parent
- the group or folder node that will be the parent of
the newly created node.
public Node createGroupNode(Graph graph)
HierarchyManager.createGroupNode(Node)
. The newly created group node will
be created as a child node of getAnchorNode(parentGraph))
.
public void convertToGroupNode(Node v)
Emits HierarchyEvents of type HierarchyEvent.PRE_NODE_STATE_CHANGE
and HierarchyEvent.NODE_STATE_CHANGED
.
v
- a folder node or a normal node that should be converted to a group nodepublic void convertToFolderNode(Node v)
Emits HierarchyEvents of type HierarchyEvent.PRE_NODE_STATE_CHANGE
and HierarchyEvent.NODE_STATE_CHANGED
.
v
- a group node or a normal node that should be converted to a folder nodepublic void convertToFolderNode(Node v, Graph innerGraph)
HierarchyManager.convertToFolderNode(y.base.Node)
with the additional option to
specify the inner graph to be used by the folder node.
public void closeGroup(Node groupNode)
public void openFolder(Node folderNode)
public void convertToNormalNode(Node v)
public void convertToInterEdge(Edge e, Node realSource, Node realTarget)
The specified real source node must be either identical with the source node of the given edge or the real source node must be contained within the graph hierarchy subtree reachable from the source node of the given edge. The same applies to the given real target node.
The given edge must be a normal edge.
e
- the edge to be converted to an inter edgerealSource
- the real source node associated with the
inter edgerealTarget
- the real target node associated with the
inter edgepublic void convertToNormalEdge(Edge e)
e
- the edge to be converted to a normal edgepublic void setGraphFactory(GraphFactory factory)
A hierarchy manager passes certain hints to the registered graph factory. If the hint for node creation is of type Graph then the created node will be a folder node whose inner graph is represented by the hint. The hint for graph creation is always the parent graph of the newly created graph.
By default a factory of type DefaultHierarchyGraphFactory
is set.
public GraphFactory getGraphFactory()
HierarchyManager.setGraphFactory(GraphFactory)
public InterEdgeConfigurator getInterEdgeConfigurator()
public void setInterEdgeConfigurator(InterEdgeConfigurator interEdgeConfigurator)
DefaultInterEdgeConfigurator
is set.
public void preTraverse(HierarchyManager.NodeVisitor visitor)
public void preTraverse(Node rootNode, HierarchyManager.NodeVisitor visitor)
public void postTraverse(HierarchyManager.NodeVisitor visitor)
public void postTraverse(Node rootNode, HierarchyManager.NodeVisitor visitor)
public DataProvider getNodeIdDataProvider()
public DataProvider getParentNodeIdDataProvider()
getNodeIdDataProvider().get(getParentNode(v)) == getParentNodeDataProvider().get(v)
HierarchyManager.getNodeIdDataProvider()
public DataProvider getGroupNodeDataProvider()
isGroupNode(v) == getGroupNodeDataProvider().getBool(v)
public static boolean containsGroupNodes(Graph graph)
public Node getRealSource(Edge e)
e
- the inter edge for which to return the real source nodepublic Node getRealTarget(Edge e)
e
- the inter edge for which to return the real target nodepublic boolean contains(Graph graph)
public boolean isInterEdge(Edge e)
public boolean isFolderNode(Node v)
public boolean isGroupNode(Node v)
public boolean isNormalNode(Node v)
public boolean containsGroups()
public Graph getInnerGraph(Node folderNode)
folderNode
- the anchor node.
public Node getAnchorNode(Graph graph)
null
gets returned.
Otherwise a folder node whose inner graph is the given graph
will be returned.
public Node getParentNode(Node node)
null
if the given node has no parent node. In such a case
the node belongs to the root graph.
public boolean isAncestor(Node presumedAncestor, Node node)
presumedAncestor
- the presumed ancestor of nodenode
- the presumed descendant of presumedAncestorpublic Graph getParentGraph(Graph graph)
public Graph getRootGraph()
public boolean isRootGraph(Graph graph)
public Object[] getFolderPath(Object item)
item
- either a graph within this hierarchy or a node contained in such a graph.
public Object[] getTreePath(Object item)
item
- either a graph within this hierarchy or a node contained in such a graph.
public Object[] getTreePath(Object item, boolean includeItem)
HierarchyManager.getTreePath(Object)
with the additional option to
include the given item as the last element of the path.
includeItem
- whether or not to include the given item as the last
element of the path.public Node getNearestCommonAncestor(NodeList subNodes)
subNodes
- arbitrary nodes being part of this hierarchy.
null
will
be returned.public Graph getNearestCommonAncestor(Graph g1, Graph g2)
g1
- the first graphg2
- the second graph
public NodeList getFolderNodes(Graph rootGraph, boolean recursive)
The result will be returned as an ordered list of nodes. The order of nodes is such that a hierchically higher folder node will always occur before a hierachically lower node in the list.
public int getLocalGroupDepth(Node node)
0
. If it parent node
of the given node is a group node p
then the result will be
the same as the one for p
plus 1
.
public NodeCursor getChildren(Node node)
public void addHierarchyListener(HierarchyListener listener)
public void removeHierarchyListener(HierarchyListener listener)
protected void fireHierarchyEvent(HierarchyEvent e)
public void moveToFirst(Node childNode)
HierarchyManager.postTraverse(y.view.hierarchy.HierarchyManager.NodeVisitor)
,
HierarchyManager.preTraverse(y.view.hierarchy.HierarchyManager.NodeVisitor)
public void moveToLast(Node childNode)
HierarchyManager.postTraverse(y.view.hierarchy.HierarchyManager.NodeVisitor)
,
HierarchyManager.preTraverse(y.view.hierarchy.HierarchyManager.NodeVisitor)
public void foldSubgraph(NodeList subNodes, Node folderNode)
Edges that have exactly one end point within the moved subgraph will be redefined, in such a way that the edge will have both of it's end points within the same graph. Edges that stay within the parent graph will be redefined to have one endpoint to be the given folder node. If both endpoints of the edge lie somewhere within the given folder node after the operation, then the edge will be redefined as well.
public void unfoldSubgraph(Graph innerGraph, NodeList subNodes)
HierarchyManager.foldSubgraph(NodeList, Node)
.
The given graph must have a parent graph.
The effect of the method calls
foldSubGraph(subNodes, folderNode) unfoldSubGraph(getInnerGraph(folderNode), subNodes)first folds and then unfolds a subgraph again. The graphs and graph hierarchy will appear unchangeed after this call sequence.
The given graph must have a parent graph
innerGraph
- the nested graph that is the source of the subgraph movementsubNodes
- nodes within graph that will be moved to the parent graphpublic void groupSubgraph(NodeList subNodes, Node groupNode)
public void ungroupSubgraph(NodeList subNodes)
1
, if it is not already 0
.
HierarchyManager.getLocalGroupDepth(Node).
|
© Copyright 2000-2003, yWorks GmbH. All rights reserved. 2003 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |