Creating a Tree Item

We will use the following design to create a tree item based on a query and show how to get the EMP details by EMPNO for each tree node selection:

Begin by initializing the tree item with a data query based on a SELECT with CONNECT BY and START WITH clauses. This has to be specified in the Data Query property of the tree item:

SELECT -1, LEVEL, ename, NULL, TO_CHAR(empno) FROM emp START WITH mgr IS NULL CONNECT BY PRIOR empno = mgr;

This query lists all the organizations along with their reporting (parent) organizations at one level above them.

The data columns in the above query are selected as follows :

Next, populate the tree item on form startup. Write a WHEN-NEW-FORM-INSTANCE trigger using FTREE.POPULATE_TREE :

DECLARE item_id Item; BEGIN item_id := FIND_ITEM(''TREE_BLOCK.HTREE''); IF NOT ID_NULL(item_id) THEN FTREE.POPULATE_TREE(item_id); END IF; END;

Simply specifying a data query does not automatically populate the tree.

Tip

Tree items should belong to single-row blocks, and the tree item should be the only item in the block.

Категории