public class GroupingSupport extends Object
The grouping information is provided through IDataProvider
s registered with the graph with keys
GroupingKeys.NODE_ID_DPKEY
, GroupingKeys.PARENT_NODE_ID_DPKEY
and
GroupingKeys.GROUP_DPKEY
. It describes the hierarchy as a tree where a group node is the parent of the nodes
that it contains.
This is an example graph that contains group nodes.
The hierarchy tree of the grouped graph reveals the relationship among the nodes. The corresponding nodes have the same
labels as in the grouped graph. Group nodes are considered as the parents of their content which can consist of group
nodes and/or normal nodes. Top-level nodes are children of a
virtual root
. Leaf nodes can either be normal nodes or empty groups.
GroupingSupport
is not needed anymore, it should be disposed of
.Constructor and Description |
---|
GroupingSupport(Graph graph)
Creates a new
GroupingSupport instance that represents the hierarchy of the graph. |
Modifier and Type | Method and Description |
---|---|
protected INodeMap |
createInfoMap(Graph graph)
Creates a
INodeMap to store hierarchy information for each node. |
void |
dispose()
Disposes of all internal data structures held by this
instance . |
protected void |
disposeInfoMap(Graph graph,
INodeMap infoMap)
Disposes of the
INodeMap created to store hierarchy information for each node. |
NodeList |
getChildren(Node parent)
Returns the direct children of the given group node.
|
NodeList |
getDescendants(Node parent)
Returns all descendants of the given group node.
|
EdgeList |
getEdgesGoingIn(Node group)
Returns all edges crossing the bounds of the given group node such that their targets are inside the group node while
their sources lie outside the group node.
|
EdgeList |
getEdgesGoingOut(Node group)
Returns all edges crossing the bounds of the given group node such that their sources are inside the group node while
their targets lie outside the group node.
|
Graph |
getGraph()
Gets the
Graph instance for which this GroupingSupport object provides hierarchy information. |
Node |
getNearestCommonAncestor(Node node1,
Node node2)
Returns the nearest common ancestor of the given nodes in the hierarchy structure.
|
Node |
getParent(Node node)
Returns the parent for the given node.
|
Node |
getRepresentative(Node node,
Node group)
Returns an immediate child of the group node that represents the given node.
|
Node |
getRoot()
Gets a
Node instance associated with the virtual root of the hierarchy tree. |
boolean |
hasChildren(Node node)
Determines whether or not the given node is a group node with children.
|
protected void |
init()
Initializes internal data structures.
|
static boolean |
isFlat(Graph graph)
Returns whether or not the given graph is flat.
|
static boolean |
isGrouped(Graph graph)
Returns whether or not the given graph is grouped.
|
boolean |
isGroupNode(Node node)
Determines whether or not the given node is a group node.
|
boolean |
isNormalEdge(Edge edge)
Determines whether or not the given edge is a normal edge as opposed to an edge that crosses any group node bounds.
|
public GroupingSupport(Graph graph)
GroupingSupport
instance that represents the hierarchy of the graph.
The hierarchy information is cached during the constructor call. Later modifications to the graph are not considered and
may lead to errors when using this GroupingSupport
instance.
GroupingSupport
holds the current state of the graph instance, it should be disposed of
once it is not needed anymore.graph
- the graph instance from which the hierarchy information is obtainedprotected INodeMap createInfoMap(Graph graph)
INodeMap
to store hierarchy information for each node.
This method is called in init()
and may be overridden to customize how the INodeMap
is created.
graph
- the current graphINodeMap
init()
,
disposeInfoMap(Graph, INodeMap)
public void dispose()
instance
.
GroupingSupport
should be disposed of when it is not needed anymore, or if the state of the graph changes (e.g.
new nodes are added).
GroupingSupport
instance
needs to be created.protected void disposeInfoMap(Graph graph, INodeMap infoMap)
INodeMap
created to store hierarchy information for each node.
This method is called in dispose()
and may be overridden to revert changes from createInfoMap(Graph)
.
graph
- the current graphinfoMap
- the INodeMap
which contains the hierarchy information for each nodedispose()
,
createInfoMap(Graph)
public NodeList getChildren(Node parent)
If the virtual root of the hierarchy tree
is passed, all top-level nodes are returned.
parent
- the group nodegetRoot()
,
getParent(Node)
,
getDescendants(Node)
public NodeList getDescendants(Node parent)
All nodes in the subtree rooted at this group node are collected recursively.
If the virtual root of the hierarchy tree
is passed, all nodes in the graph are returned.
parent
- the group nodegetRoot()
,
getParent(Node)
,
getChildren(Node)
public EdgeList getEdgesGoingIn(Node group)
group
- the group node whose bounds are crossedgetEdgesGoingOut(Node)
,
isNormalEdge(Edge)
public EdgeList getEdgesGoingOut(Node group)
group
- the group node whose bounds are crossedgetEdgesGoingIn(Node)
,
isNormalEdge(Edge)
public Graph getGraph()
Graph
instance for which this GroupingSupport
object provides hierarchy information.public Node getNearestCommonAncestor(Node node1, Node node2)
The nearest common ancestor is the local root of the smallest subtree in the hierarchy tree that contains both nodes.
This group is the first node that contains these two nodes. If no such node exists, the virtual root
is returned.
Common ancestors in special cases:
node1 == node2
: the parent of node1
/node2
node1 is parent of node2
: the parent of node1
node2 is parent of node1
: the parent of node2
node1
- one of the two nodes whose common ancestor is determinednode2
- one of the two nodes whose common ancestor is determinedRoot
public Node getParent(Node node)
The parent is the containing group node.
IllegalArgumentException
- if the given node is null
node
- the node for which the parent is determinednull
for a top-level nodegetChildren(Node)
,
getDescendants(Node)
,
getNearestCommonAncestor(Node, Node)
public Node getRepresentative(Node node, Node group)
If this node is already a child of the group node, the group node will be its representative. In case the node is located further down in the hierarchy, the child of the group node, which is also an ancestor of the node, is used. There is no representative if the node is not a descendant of the group.
IllegalArgumentException
- if the given node is null
node
- the node for which a representative is searchedgroup
- the group node to which the representative should belongnull
if the node is not a descendant of the grouppublic Node getRoot()
Node
instance associated with the virtual root of the hierarchy tree.
This instance can be given to the getChildren(Node)
to obtain the nodes of the top level of the hierarchy.
Node
instance is not part of the graph.getChildren(Node)
public boolean hasChildren(Node node)
Normal nodes never have children.
node
- the potential parenttrue
if the given node has children, false
otherwisegetChildren(Node)
,
isGroupNode(Node)
protected void init()
This method is called from GroupingSupport(Graph)
and retrieves the state of the hierarchic graph at the moment
of invocation. It may be overridden to append additional information used for group handling.
disposed of
if this instance of GroupingSupport
is
not needed anymore.dispose()
public static final boolean isFlat(Graph graph)
A graph is considered to be flat if there exist no group nodes or there exist group nodes but none of them has children.
graph
- the input graphtrue
if there are no groups or only empty groups in the graph, false
otherwiseisGrouped(Graph)
public static final boolean isGrouped(Graph graph)
A graph is considered to be grouped if there are IDataProvider
s registered with the graph with keys
GroupingKeys.GROUP_DPKEY
, GroupingKeys.NODE_ID_DPKEY
and GroupingKeys.PARENT_NODE_ID_DPKEY
.
graph
- the input graphtrue
if the graph contains hierarchic information, false
otherwiseisFlat(Graph)
public boolean isGroupNode(Node node)
While group nodes may have children, normal nodes never have children.
node
- the potential group nodetrue
if the given node is a group node, false
otherwisehasChildren(Node)
public boolean isNormalEdge(Edge edge)
Source and target of a normal edge are part of the same hierarchy level and share the same parent node.
edge
- the edge to checktrue
if the given edge is normal, false
otherwisegetEdgesGoingIn(Node)
,
getEdgesGoingOut(Node)