Dynamic JTree from database query,how 2 build JTree wth dynamic hierarchy ?
843805Dec 5 2005 — edited Apr 17 2006i need to create JTree dynamically from database query, below my script for table and table data (my database is Oracle):
create table tvr_jv_menus(menu_id number, menu_name varchar2(50), menu_description varchar2(4000), menu_parent_id number, menu_icon_path varchar2(100), menu_type number, menu_status number);
insert into tvr_jv_menus values (1,'File','Default Menu',null,'/img/file.jpg',1,1);
insert into tvr_jv_menus values (2,'Process','Process Menu',null,'/img/proc.jpg',1,1);
insert into tvr_jv_menus values (3,'Connect','Connect to Oracle',1,'/img/conn.jpg',2,1);
insert into tvr_jv_menus values (4,'Exit','Close Application',1,'/img/file.jpg',2,1);
insert into tvr_jv_menus values (5,'Manual','Manual Process',2,'/img/manual.jpg',1,1);
insert into tvr_jv_menus values (6,'Automation','Automatic Process',2,'/img/auto.jpg',1,1);
insert into tvr_jv_menus values (7,'Drive','Manual Drive Process',5,'/img/mndrive.jpg',2,1);
insert into tvr_jv_menus values (8,'Drive','Automatic Drive Process',6,'/img/autodrive.jpg',2,1);
insert into tvr_jv_menus values (9,'Shoot','Automatic Shoot Process',6,'/img/autoshoot.jpg',2,1);
commit;
then using this query i can populate hierarchial data :
select level, menu_id, menu_name, menu_description, menu_parent_id, menu_icon_path, menu_type, menu_status
from tvr_jv_menus
connect by prior menu_id = menu_parent_id
start with menu_parent_id is null
data resulted from above query should be like this :
LEVEL MENU_ID MENU_NAME MENU_PARENT_ID MENU_TYPE
1 1 File 1
2 3 Connect 1 2
2 4 Exit 1 2
1 2 Process 1
2 5 Manual 2 1
3 7 Drive 5 2
2 6 Automation 2 1
3 8 Drive 6 2
3 9 Shoot 6 2
level column indicating the hierarchy of the treenode, its parentnode is indicated by menu_parent_id column.
menu_name column should be the node name, which is visually seen by the user.
menu_type indicating whether a node is contained by an event or not. Value 1 means the node doesn't have any event, otherwise, 2 means the node have event. For example menu_name = 'Exit' has menu_type value equals to 2, so if exit node is doubleclicked then it should trigger an event to exit the application.
menu_description should be the tooltip of the node and menu_icon_path should be the path for the node's icon.
the problem are, users are freely creating their menu. it can be 3 level hierarchy or more. and users are freely too to determine the action for each menu which its menu_type = 2.
how to create dynamic JTree with these requirements ?
thanks' alot !!!