com.yworks.yfiles.server.graphml.support
Class NodeHierarchy

java.lang.Object
  extended bycom.yworks.yfiles.server.graphml.support.NodeHierarchy

public final class NodeHierarchy
extends java.lang.Object

Provides static utility functions to query and modify the the node hierarchy of a grouped LayoutGraph.

Internally, the hierarchy is managed using data providers that can be obtained from the graph using the following keys:

See Also:
LayoutGraph

Method Summary
static void enableGrouping(Graph graph)
          Adds the DataProviders that are required for working with hierarchic layout graphs and calls transferMapperIDs(y.base.Graph).
static NodeList getChildren(Node parent)
          Returns a list of all child nodes of the given parent node.
static NodeList getNeighbors(Node node)
          Returns a list containing the given node and all it's neighbor nodes.
static NodeList getNodes(Graph graph)
          Returns a node cursor that allows for breadth-first iteration over the node hierarchy of the provided graph.
static Node getParent(Node child)
          Get the parent node of the provided node.
static NodeList getTopLevelNodes(Graph graph)
          Returns a cursor over all top level nodes of the provided graph, i.e., all nodes for which NodeHierarchy.getParent( node ) yields null.
static boolean isGroupNode(Node node)
          Whether the given node is considered a group node.
static void setGroupNode(Node node, boolean isGroupNode)
          Set whether the provided node should be considered a group node.
static void setParent(NodeList children, Node parent)
          Adds all nodes contained in the provided NodeList as children of the provided parent node.
static void setParent(Node child, Node parent)
          Set the parent node for a given node.
static void transferMapperIDs(Graph graph)
          Replaces the DataProvider for grouping keys with the id data provider used by yFiles FLEX.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getParent

public static Node getParent(Node child)
Get the parent node of the provided node. If the node is a top-level node, null is returned.

Parameters:
child - The child node
Returns:
The parent node, or null if child is a top-level node.

setParent

public static void setParent(Node child,
                             Node parent)
Set the parent node for a given node. To make child a top-level node, pass null as the parent.

Calls enableGrouping(y.base.Graph) to make sure that the graph instance supports hierarchies.

Parameters:
child - The node to assign a new parent.
parent - The parent node to assign to child.
Throws:
java.lang.UnsupportedOperationException - if parent is a child of child, or parent equals child.

setParent

public static void setParent(NodeList children,
                             Node parent)
Adds all nodes contained in the provided NodeList as children of the provided parent node.

Parameters:
children - A list of nodes to be added as children of the provided parent node.
parent - The parent node.

setGroupNode

public static void setGroupNode(Node node,
                                boolean isGroupNode)
Set whether the provided node should be considered a group node. A group node may (but doesn't have to) have children.

Parameters:
node - A node
isGroupNode - Whether to consider the given node a group node.

isGroupNode

public static boolean isGroupNode(Node node)
Whether the given node is considered a group node.

This method may return true, even if the given node doesn't have any child nodes.

Parameters:
node - A node.
Returns:
Whether the given node is considered a group node.

getChildren

public static NodeList getChildren(Node parent)
Returns a list of all child nodes of the given parent node.

Parameters:
parent - A parent node
Returns:
A list of all child nodes of the given parent node.

getNeighbors

public static NodeList getNeighbors(Node node)
Returns a list containing the given node and all it's neighbor nodes.

If the given node is top-level, all top-level nodes are returned. Otherwise all child nodes of the given node's parent node are returned.

Parameters:
node - The node to get the neighbors for.
Returns:
A list containing the given node and all it's neighbor nodes.

enableGrouping

public static void enableGrouping(Graph graph)
Adds the DataProviders that are required for working with hierarchic layout graphs and calls transferMapperIDs(y.base.Graph).

See Also:
GroupingKeys, transferMapperIDs(y.base.Graph)

getNodes

public static NodeList getNodes(Graph graph)
Returns a node cursor that allows for breadth-first iteration over the node hierarchy of the provided graph.

Parameters:
graph - The graph for which to return a hierarchy iterator
Returns:
A node cursor that allows to traverse all nodes of the provided graph in in breadth-first manner.

getTopLevelNodes

public static NodeList getTopLevelNodes(Graph graph)
Returns a cursor over all top level nodes of the provided graph, i.e., all nodes for which NodeHierarchy.getParent( node ) yields null.

Parameters:
graph - A graph
Returns:
A cursor that allows to iterate over all top level nodes of the provided graph.

transferMapperIDs

public static void transferMapperIDs(Graph graph)
Replaces the DataProvider for grouping keys with the id data provider used by yFiles FLEX.

After using this function, graph.getDataProvider( GroupingKeys.NODE_ID_DPKEY ) and graph.getDataProvider(AbstractGraphRoundtripSupport.NODE_2_ID_DPKEY ) will yield the same instance. This instance will automatically generate ids for newly created nodes.

Clients should only call this function if the graph is read directly using a GraphML I/O handler instance.

See Also:
AbstractGraphRoundtripSupport.NODE_2_ID_DPKEY, GroupingKeys.NODE_ID_DPKEY, GroupingKeys.PARENT_NODE_ID_DPKEY


Copyright © 2000-2013 yWorks GmbH. All rights reserved