How to create a Columnar tree view (Version 11 only)

Date:July 2005
Product/Release:Visual LANSA V11
Abstract:How to create a Columnar tree view (Version 11 only)
Submitted By:LANSA Technical Support

Prior to Version 11 it was only possible to create a tree view with one visible column. This column became the main tree column. In Version 11 it is now possible to now create a Columnar tree, that is a tree with multiple columns above and beyond the main tree column. An example of this is as follows:

Example of a Columnar tree

In the above example you will notice how the tree view has two columns. The columnar tree will allow multiple columns. In order to create the above example perform the following in Version 11:

  • Ensure that you have imported the LANSA demonstration objects.
  • Create a form and ensure that the component or partition is enabled for full RDMLX
  • Cut and paste the code example listed below
  • Compile and run

Note: The code is commented in places to assist understanding. Please refer to the LANSA guides for further clarity of new features/command syntax used in this example.

Function Options(*DIRECT)
Begin_Com Role(*EXTENDS #PRIM_FORM) Clientheight(499) Clientwidth(644) Height(533) Layoutmanager(#ATLM_1) Left(92) Top(130) Width(652)
Define_Com Class(#PRIM_ATLM) Name(#ATLM_1)
Define_Com Class(#PRIM_PANL) Name(#PANL_1) Displayposition(1) Height(42) Left(0) Parent(#COM_OWNER) Tabposition(1) Tabstop(False) Top(457) Width(644)
Define_Com Class(#PRIM_ATLI) Name(#ATLI_1) Attachment(Bottom) Manage(#PANL_1) Parent(#ATLM_1)

* A new property called Viewstyle has been added to the PRIM_TRVW
* Unlevelled means that that the tree no longer creates a level per field, and instead, creates a column per field.
* The developer is now reponsible for the level at which a tree item exists.
* This is governed by setting the PARENTITEM property of a tree item to another tree item

* NOTE - The tree can still be processed using SELECTLIST.
* Entries will be returned in the sequence they were added to the list. This may not reflect the order as seen in the tree
* To process in order sequence, use the FOR command
Define_Com Class(#PRIM_TRVW) Name(#Personnel) Componentversion(1) Displayposition(2) Height(457) Left(0) Parent(#COM_OWNER) Tabposition(2) Top(0) Viewstyle(UnLevelled) Width(644)
Define_Com Class(#PRIM_ATLI) Name(#ATLI_2) Attachment(Center) Manage(#Personnel) Parent(#ATLM_1)
Define_Com Class(#PRIM_TVCL) Name(#TVCL_1) Caption('Code') Captiontype(Caption) Displayposition(1) Level(1) Parent(#Personnel) Source(#STD_OBJ)
Define_Com Class(#PRIM_TVCL) Name(#TVCL_2) Caption('Description') Captiontype(Caption) Displayposition(2) Level(2) Parent(#Personnel) Source(#STD_DESC) Widthtype(Remainder)
Define_Com Class(#PRIM_PHBN) Name(#pb_load) Caption('Load Tree') Displayposition(1) Left(8) Parent(#PANL_1) Tabposition(1) Top(8)

Evtroutine Handling(#pb_load.Click)

Clr_List Named(#personnel)

#com_owner.Add_departments
Endroutine

Mthroutine Name(Add_departments) Access(*private)
Define_Com Class(#prim_tvit) Name(#Department_item) Reference(*dynamic)
Select Fields(#Deptment #deptdesc) From_File(Deptab)
#com_owner.Add_Entry I_Code(#deptment) I_Description(#deptdesc) O_Tree_Item(#Department_item)

* Add the sections for the department
#com_owner.Add_sections I_Parent_Item(#department_item) I_Department(#deptment)
Endselect
Endroutine

Mthroutine Name(Add_sections) Access(*private)
Define_Map For(*input) Class(#prim_tvit) Name(#i_parent_item) Pass(*by_reference)
Define_Map For(*input) Class(#deptment) Name(#i_department)
Define_Com Class(#prim_tvit) Name(#Section_item) Reference(*dynamic)
Select Fields(#section #secdesc) From_File(sectab) With_Key(#i_department)
#com_owner.Add_Entry I_Code(#section) I_Description(#secdesc) O_Tree_Item(#Section_item) I_Parent_Item(#i_parent_item)

* Add the Employees for the section
#com_owner.Add_Employees I_Parent_Item(#Section_item) I_Department(#deptment) I_Section(#Section)
Endselect

* Set a margin on the last item to help separate the groups of tree items
#personnel.Currentitem.marginbottom := 5
Endroutine

Mthroutine Name(Add_Employees) Access(*private)
Define_Map For(*input) Class(#prim_tvit) Name(#i_parent_item) Pass(*by_reference)
Define_Map For(*input) Class(#deptment) Name(#i_Department)
Define_Map For(*input) Class(#section) Name(#i_Section)
Define_Com Class(#prim_tvit) Name(#Employee_item) Reference(*dynamic)
Select Fields(#empno #givename #surname) From_File(pslmst1) With_Key(#i_Department #i_section)
#com_owner.Add_Entry I_Code(#empno) I_Description(#Surname.trim + ', ' + #Givename) I_Parent_Item(#i_parent_item) O_Tree_Item(#employee_item)

* Add the skills for the employee
#Com_Owner.Add_Skills I_Parent_Item(#employee_item) I_Employee(#empno)
Endselect

* Set a margin on the last item to help separate the groups of tree items
#personnel.Currentitem.marginbottom := 5
Endroutine

Mthroutine Name(Add_Skills) Access(*private)
Define_Map For(*input) Class(#prim_tvit) Name(#i_parent_item) Pass(*by_reference)
Define_Map For(*input) Class(#empno) Name(#i_Employee)
Select Fields(#skilcode) From_File(pslskl) With_Key(#i_Employee)
Fetch Fields(#skildesc) From_File(skltab) With_Key(#skilcode)
#com_owner.Add_Entry I_Code(#skilcode) I_Description(#skildesc) I_Parent_Item(#i_parent_item)
Endselect

* Set a margin on the last item to help separate the groups of tree items
#personnel.Currentitem.marginbottom := 5
Endroutine

Mthroutine Name(Add_entry) Access(*private)
Define_Map For(*input) Class(#std_obj) Name(#i_code)
Define_Map For(*input) Class(#std_Desc) Name(#i_Description)
Define_Map For(*input) Class(#prim_tvit) Name(#i_Parent_item) Mandatory(*null) Pass(*by_reference)
Define_Map For(*output) Class(#prim_tvit) Name(#o_Tree_item) Mandatory(*null) Pass(*by_reference)

* The same fields are used regardless of the "level" of the tree item
#std_obj := #i_code
#std_desc := #i_Description
Add_Entry To_List(#Personnel)

* Set the new tree item's parent to the supplied parent. A null parent means that the item will appear as a root node
* The parent is no longer governed by the data. It is a choice the developer can now make.
* Effectively, there is NO LIMIT to the number of levels.
* Note: The parent of a tree item is completely dynamic. It can be set at any time
Set Com(#Personnel.currentitem) Parentitem(#i_parent_item)

* Return the tree item for use as a parent
Set_Ref Com(#o_tree_item) To(#Personnel.currentitem)
Endroutine
End_Com