Use the following code as an example for creating and manipulating a hierarchical tree:
The first action will typically be to populate the hierarchical tree (htree) with data.
DECLARE htree ITEM; node ftree.node; state varchar2(30);
BEGIN -- Find the tree itself. htree := Find_Item('tree_block.htree3'); -- Sets the record group and causes the data to display. Ftree.Set_Tree_Property(htree, Ftree.RECORD_GROUP, 'record_group5'); END;
This code example will expand all nodes in a tree.
DECLARE htree ITEM; node ftree.node; state varchar2(30);
BEGIN -- Find the tree itself. htree := Find_Item('tree_block.htree3');
-- Find the root node of the tree.
node := Ftree.Find_Tree_Node(htree, '');
-- Loop through all nodes and expand each one if it is collapsed.
WHILE NOT Ftree.ID_NULL(node) LOOP
state := Ftree.Get_Tree_Node_Property(htree, node, Ftree.NODE_STATE);
IF state = Ftree.COLLAPSED_NODE THEN
Ftree.Set_Tree_Node_Property(htree, node, Ftree.NODE_STATE, Ftree.EXPANDED_NODE);
END IF;
node := Ftree.Find_Tree_Node(htree, '', ftree.find_NEXT,Ftree.NODE_LABEL,'', node);
END LOOP;
END;
This sample code will delete all tree nodes marked as selected. See the Ftree.Set_Tree_Selection Built-in for a definition of "selected".
DECLARE
htree ITEM;
num_selected NUMBER;
BEGIN
-- Find the tree itself.
htree := Find_Item('tree_block.htree3');
-- Find the number of nodes marked as selected.
num_selected := Ftree.Get_Tree_Property(htree, Ftree.SELECTION_COUNT);
-- Loop through nodes and delete them. Since nodes are internally
-- re-numbered when one is deleted, be sure to loop in reverse
-- order from last to first.
FOR j IN num_selected..1 LOOP
Ftree.Delete_Tree_Node(htree, Ftree.Get_Tree_Selection(htree, j));
END LOOP;
END;