com.yworks.yfiles.server.graphml.flexio.data
Class DefaultNodeHierarchy

java.lang.Object
  extended bycom.yworks.yfiles.server.graphml.flexio.data.DefaultNodeHierarchy
All Implemented Interfaces:
INodeHierarchy

public class DefaultNodeHierarchy
extends java.lang.Object
implements INodeHierarchy

A default implementation of INodeHierarchy using the utility functions offered by NodeHierarchy.


Constructor Summary
DefaultNodeHierarchy(Graph graph)
          Creates a new instance of a DefaultNodeHierarchy which uses the specified graph to work on.
 
Method Summary
 void enableGrouping()
          Adds the DataProviders that are required for working with hierarchic layout graphs and calls transferMapperIDs().
 NodeList getChildren(Node parent)
          Returns a list of all child nodes of the given parent node.
 NodeList getNeighbors(Node node)
          Returns a list containing the given node and all it's neighbor nodes.
 NodeList getNodes()
          Returns a node cursor that allows for breadth-first iteration over the node hierarchy of the provided graph.
 Node getParent(Node child)
          Gets the parent node of the provided node.
 NodeList getTopLevelNodes()
          Returns a cursor over all top level nodes of the provided graph, i.e., all nodes for which NodeHierarchy.getParent( node ) yields null.
 boolean isGroupNode(Node node)
          Whether the given node is considered a group node.
 void setGroupNode(Node node, boolean isGroupNode)
          Sets whether the provided node should be considered a group node.
 void setParent(NodeList children, Node parent)
          Adds all nodes contained in the provided NodeList as children of the provided parent node.
 void setParent(Node child, Node parent)
          Sets the parent node for a given node.
 void transferMapperIDs()
          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
 

Constructor Detail

DefaultNodeHierarchy

public DefaultNodeHierarchy(Graph graph)
Creates a new instance of a DefaultNodeHierarchy which uses the specified graph to work on.

Parameters:
graph - The graph to work on.
Method Detail

getParent

public Node getParent(Node child)
Description copied from interface: INodeHierarchy
Gets the parent node of the provided node. If the node is a top-level node, null is returned.

Specified by:
getParent in interface INodeHierarchy
Parameters:
child - The child node.
Returns:
The parent node, or null if child is a top-level node.

setParent

public void setParent(Node child,
                      Node parent)
Description copied from interface: INodeHierarchy
Sets the parent node for a given node. To make child a top-level node, pass null as the parent.

Calls INodeHierarchy.enableGrouping() to make sure that the graph instance supports hierarchies.

Specified by:
setParent in interface INodeHierarchy
Parameters:
child - The node to assign a new parent.
parent - The parent node to assign to child.

setParent

public void setParent(NodeList children,
                      Node parent)
Description copied from interface: INodeHierarchy
Adds all nodes contained in the provided NodeList as children of the provided parent node.

Specified by:
setParent in interface INodeHierarchy
Parameters:
children - A list of nodes to be added as children of the provided parent node.
parent - The parent node.

setGroupNode

public void setGroupNode(Node node,
                         boolean isGroupNode)
Description copied from interface: INodeHierarchy
Sets whether the provided node should be considered a group node. A group node may (but doesn't have to) have children.

Specified by:
setGroupNode in interface INodeHierarchy
Parameters:
node - A node.
isGroupNode - Whether to consider the given node a group node.

isGroupNode

public boolean isGroupNode(Node node)
Description copied from interface: INodeHierarchy
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.

Specified by:
isGroupNode in interface INodeHierarchy
Parameters:
node - A node.
Returns:
Whether the given node is considered a group node.

getChildren

public NodeList getChildren(Node parent)
Description copied from interface: INodeHierarchy
Returns a list of all child nodes of the given parent node.

Specified by:
getChildren in interface INodeHierarchy
Parameters:
parent - A parent node.
Returns:
A list of all child nodes of the given parent node.

getNeighbors

public NodeList getNeighbors(Node node)
Description copied from interface: INodeHierarchy
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.

Specified by:
getNeighbors in interface INodeHierarchy
Parameters:
node - The node to get the neighbors for.
Returns:
A list containing the given node and all it's neighbor nodes.

enableGrouping

public void enableGrouping()
Description copied from interface: INodeHierarchy
Adds the DataProviders that are required for working with hierarchic layout graphs and calls INodeHierarchy.transferMapperIDs().

Specified by:
enableGrouping in interface INodeHierarchy
See Also:
GroupingKeys, INodeHierarchy.transferMapperIDs()

getNodes

public NodeList getNodes()
Description copied from interface: INodeHierarchy
Returns a node cursor that allows for breadth-first iteration over the node hierarchy of the provided graph.

Specified by:
getNodes in interface INodeHierarchy
Returns:
A node cursor that allows to traverse all nodes of the provided graph in in breadth-first manner.

getTopLevelNodes

public NodeList getTopLevelNodes()
Description copied from interface: INodeHierarchy
Returns a cursor over all top level nodes of the provided graph, i.e., all nodes for which NodeHierarchy.getParent( node ) yields null.

Specified by:
getTopLevelNodes in interface INodeHierarchy
Returns:
A cursor that allows to iterate over all top level nodes of the provided graph.

transferMapperIDs

public void transferMapperIDs()
Description copied from interface: INodeHierarchy
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.

Specified by:
transferMapperIDs in interface INodeHierarchy
See Also:
AbstractGraphRoundtripSupport.NODE_2_ID_DPKEY, GroupingKeys.NODE_ID_DPKEY, GroupingKeys.PARENT_NODE_ID_DPKEY


Copyright © 2000-2013 yWorks GmbH. All rights reserved