The experience of using trees in Oracle form Builder

xiaoxiao2021-03-06  23

First, the introduction of the tree developer 6.0 The above version provides the concept of hierarchy trees, and the Htree control is very convenient and only a small amount of programming can realize the purpose of displaying hierarchies.

The unique properties of the tree are more important: l Multi-Selection: Do you allow multiple nodes of the tree at once. If you are not allowed, then the second node is selected, the first selected node will deselect. l Recording Group: Specifies the name of the record group that generates the tree.

Briefly introduces the trigger (Built-in): l function get_tree_node_property (item_name var); function: Take the property: Node_State: expanded_Node (Extended Node) Collapsed_node Leaf_Node (leaf node) - Note: You cannot expand or contract Node_Depth: the level of the node in the tree. Node_Label: Node's Display Text Node_ICON: Node Node_Value: Node's value. Examples: DECLARE htree ITEM; node_value VARCHAR2 (100); BEGIN - tree obtained htree: = Find_Item ( 'tree_block.htree3'); - the currently selected node to obtain values ​​node_value: = Ftree.Get_Tree_Node_Property (htree,: SYSTEM.TRIGGER_NODE FTREE.NODE_VALUE); ... END; Note: Where: system.trigger_node refers to the currently selected tree node. l function get_tree_property (item_name varcha2, proty); Function: The property of the tree is obtained where proty has the following: DataSource Record_Group Query_text node_count: Return to the number of nodes in the tree. Selection_count allow_empty_branches allow_multi-select

l PROCEDURE SET_TREE_NODE_PROPERTY (item_name VARCHAR2, node FTREE.NODE, property NUMBER, value VARCHAR2); Function: Set the attributes of the node tree l PROCEDURE SET_TREE_PROPERTY (item_name VARCHAR2, property NUMBER, value VARCHAR2); PROCEDURE SET_TREE_PROPERTY (item_name VARCHAR2, property NUMBER, value Recordgroup); Features: Setting the property of the tree

l Procedure Populate_tree (item_name varcha2); function: Empty tree existing data and regenerates the tree according to the record group or data query. l Procedure add_tree_data (item_name varcha2, node ftree.node, offset_type number, offset number, data_source number, data varcha2); function: Add a tree in the specified node Note: Use trouble. l Function Find_Tree_Node (item_name varcha2, earch_string varcha2, search_type number, search_by number, search_root node, start_point node); Function: Find a node that displays text or values ​​in accordance with Search_String. Parameters: search_type: Find_next Find_Next_Child Search_by: Node_Label Node_Value Search_Root: The root node of queries, usually ftree.Root_Node

START_POINT: Find the start node, usually ftree.Root_Node

l Function add_tree_node (item_name varcha2, node ftree.node, offset_type number, offset number, state number, label varchar2, icon varchar2, value varchar2); features: Add a tree node. Offset_type: specifies branch type node, PARENT_OFFSET and SIBLING_OFFSET Offset: Specifies the location of the new node, PARENT_OFFSET: 1..N LAST_CHILD SIBLING_OFFSET: NEXT_NODE PREVIOUS_NODE State: EXPANDED_NODE (extension node) COLLAPSED_NODE (shrinkage node) LEAF_NODE (leaf node)

l Procedure delete_tree_node (item_name varcha2, node node); function: Remove tree node l function get_tree_node_parent (item_name varcha2, node node); function: Get the parent node of the specified node. l Function get_tree_selection (item_name varcha2, selection number); Function: Get a node in the selected state. l Procedure set_tree_selection (item_name varchar2, node, selection_type number); function: Specify the selected status parameter for a single node: Selection_Type: SELECT_ON SELECT_OFF SELECT_TOGGLE

FORM Running State Trigger: l when-tree-node-activated: Users double-click the node or press [ENTER] while the node is selected. l when-tree-node-expanded: Node Expand or shrink When l when-tree-node-selected: Trigger two when nodes are selected or deselected, the way the tree control is typically placed in a control block. : Can't put in the data block), placing the tree on Canvas is easy, and, if there is no need, the properties of the tree do not need to be set. There are several ways to generate a tree: l Run before running by setting the record group or data query attribute to implement the L operation state, through the ADD_TREE_NODE, etc., to implement the L operation state, by adding or deleting record groups Data elements are implemented

Analysis: 1. Direct operation of the tree: find_tree_node finds the specified node, add_tree_node to add its lower node. Disadvantages: More programming is complicated, the operation is not flexible, and it is easier to erode. Advantages: The process of adding nodes can be controlled to implement some special requirements. Examples: --dept_cur CURSOR to take unit, emp_cur employee to take the CURSOR htree: = Find_Item ( 'tree_view.tree_emp'); open dept_cur; loop fetch dept_cur into aa; exit when dept_cur% notfound; del_node: = Ftree.Find_Tree_Node (htree, aa.kjmc, ftree.find_next, ftree.node_label, ftree.root_node, ftree.root_node;

- Delete unit nodes and its subpost if not ftree.id_null (del_node) Then ftree.delete_tree_node (htree, del_node); end if; end loop; close dept_cur;

- open unit according to a first node layer of a spanning tree acquired CURSOR dept_cur; loop fetch dept_cur into aa; exit when dept_cur% notfound; new_node: = Ftree.Add_Tree_Node (htree, Ftree.ROOT_NODE, Ftree.parent_OFFSET, Ftree.LAST_CHILD , AA.DNAME, '', AA.DEPTNO; End loop; Close Dept_Cur; - Depending on the lower-level node of the employee cursor generates the lower node Open EMP_CUR; LOOP FETCH EMP_CUR INTO BB; EXIT WHEN EMP_CUR% NOTFOUND; FIND_NODE: = Ftree.Find_Tree_Node (htree, bb.kjbh, Ftree.FIND_NEXT, Ftree.NODE_value, Ftree.ROOT_node, Ftree.ROOT_NODE); new_node: = Ftree.Add_Tree_Node (htree, find_node, Ftree.parent_OFFSET, Ftree.LAST_CHILD, Ftree.EXPANDED_NODE , bb.ename, '', bb.empno; end loop; close Emp_cur; - Get the root node of the tree SS: = ftree.get_tree_property (htree, ftree.node_count); - loop until all nodes of the tree Expand for J IN 1..SS loop exp_node: = ftree.find_tree_node (htree, ''); state: = ftree.get_tree_node_property (htree, j, ftree.node_state); if state = ftree.collapsed_node dam FTree.Set_tree_node_property (htree, j, ftree.node_state, ftree.expanded_node); end if; endloop

Second, the data format of the record group used by the dynamic record group hierarchy: - car | - - AirPlane | - Boeing | - Boeing

Initial state layer display text icon value -1 (shrink node) 1 'car' '' 'car' 0 (leaf node) 2 'Honda' '' 'CIVIC' 1 (Expand Node) 1 'AirPlane' '' 'PLANE '0 2' Boeing '' '' 747 '0 2' BoEing '' '' 757 '

The way the record group is generated is divided into two. 1. Describe from the query generation record group: Generate a record group and set the property of the tree using the tree query statement (Connect By ... PRIOR ... START with ...). Advantages: simple programming, convenient. Disadvantages: Only for a tree query statement can be constructed. Example: V_IGNORE NUMBER; RG_EMPS Recordgroup; Begin Rg_Emps: = FIND_GROUP ('EMPS'); = CREATE_GROUP_FROM_QUERY ('Emps', 'SELECT 1, Level, ENAME, NULL, TO_CHAR (Empno) ||' from Emp '||' Connect by Prior Empno = Mgr '||' Start with job = '' PRESIDENT '' '); V_ignore: = Populate_group (rg_emps); ftree.set_tree_property (' Tree.Record_Group, Rg_EMPS); END; 2, Direct Construction Record Group Description with Row Column Data: Recorder is generally a row structure to cycle The way the unit data is added directly to the record group. Advantages: The style of the record group can be directly controlled. Disadvantages: For multi-layer structure, programming is also complicated. Examples: - Unit CURSOR cursor cursor_dept is select dname, deptno from dept order by dname; - employee CURSOR cursor cursor_emp (p_dno number) is select ename, empno from emp where deptno = p_dno order by ename; v_i number; v_ignore number;

RG_EMPS Recordgroup; rg_depts recordgroup;

v_init_state groupcolumn; v_level groupcolumn; v_label groupcolumn; v_icon groupcolumn; v_value groupcolumn; begin rg_depts: = find_group ( 'DEPTS'); - if the data is empty group record if not id_null (rg_depts) then delete_group (rg_depts); end if Rg_depts: = crete_group ('DePts'); - Customize the data type and length of the columns in the record group you need (refer to the expansion, shrink or leaf node) v_init_state: = add_group_column (rg_depts,' init_state ', number_column); - where floors v_level: = add_group_column (rg_depts,' level ', number_column); - text v_label: = add_group_column (rg_depts,' label ', char_column, 40); - icon v_icon: = add_group_column (rg_depts, 'icon', char_column, 20); - values ​​v_value: = add_group_column (rg_depts, 'value', char_column, 5); v_i: = 1; for deptrec in cursor_dept loop add_group_row (rg_depts, v_i); set_group_number_cell (v_init_state, v_i, 1); set_group_number_cell (v_level, v_i, 1); set_group_ Char_cell (v_label, v_i, deptrec.dname); set_group_char_cell (v_icon, v_i, null); set_group_char_cell (v_value, v_i, to_char (deptrec.deptno)); v_i: = v_i 1;

转载请注明原文地址:https://www.9cbs.com/read-79603.html

New Post(0)