This example assumes that you have a report that
contains at least one level of grouping.
You can navigate to a node in the Totaller tree by
creating a group path that represents its location, or by recursively iterating
through the tree using the
getSubTotallerNodes method.
Create a new
GroupPath
object.
GroupPath groupPath = new GroupPath();
The
GroupPath
object represents where a node is positioned in the Totaller tree.
Use thefromString method to specify
the path to the node in the Totaller tree.
- To specify the report level, which
is the root node of the Totaller tree, use the empty string
"".
groupPath.fromString(""); - To specify the path to a node by
field value, separate each item with the
/ character.
groupPath.fromString("/Canada/BC"); - To specify a node by field name
and field value, use the format
field name[field
value] and separate each item with the
/ character.
groupPath.fromString("/Country[Canada]/Region[MB]); - To specify a node by the numeric
value of its position in the Totaller tree, separate each item with the
- character.
groupPath.fromString("1-0");
Get the Totaller node by calling the
RowsetController.getTotallerNode method using
the group path as the argument.
RowsetController rowsetController = rcd.getRowsetController();
ITotallerNode totallerNode = rowsetController.getTotallerNode(groupPath);
Retrieve the children of the node
using the
getSubTotallerNodes method.
TotallerNodes children = rowsetController.getSubTotallerNodes(node.getGroupPath());
Iterate through the children of the
Totaller node.
Iterator<ITotallerNode> it = children.iterator();
while (it.hasNext())
{
ITotallerNode child = it.next();
//...
}
Example:
This sample recursively traverses the Totaller tree
from the root level. Modify the
traverseChildren
method to manipulate each node of the Totaller.
void traverseTotaller(ReportClientDocument rcd) throws ReportSDKException
{
GroupPath groupPath = new GroupPath();
groupPath.fromString("");
RowsetController rowsetController = rcd.getRowsetController();
ITotallerNode totallerNode = rowsetController.getTotallerNode(groupPath);
traverseChildren(totallerNode, rowsetController);
}
void traverseChildren(ITotallerNode node, RowsetController rowsetController) throws ReportSDKException
{
String name = node.getName();
//...
TotallerNodes children = rowsetController.getSubTotallerNodes(node.getGroupPath());
Iterator<ITotallerNode> it = children.iterator();
while (it.hasNext())
{
ITotallerNode child = it.next();
traverseChildren(child, rowsetController);
}
}This list includes the classes used by the sample
code:
com.crystaldecisions.sdk.occa.report.application.ReportClientDocument
com.crystaldecisions.sdk.occa.report.application.RowsetController
com.crystaldecisions.sdk.occa.report.data.GroupPath
com.crystaldecisions.sdk.occa.report.data.ITotallerNode
com.crystaldecisions.sdk.occa.report.data.TotallerNode
com.crystaldecisions.sdk.occa.report.lib.ReportSDKException
java.util.Iterator