Source for Snap in Instance List Example

Visual LANSA Framework

Source for Snap-in Instance List Example

The example code is:

 

* =======================================================

* Component   : XXXXXXXXXX

* Type        : Reusable Part

* Description : Sample of a snap in instance list browser

* displaying an instance list as a tree control.

* Disclaimer  : The following material is supplied as

* sample material only. No warranty concerning this

* material or its use in any way whatsoever is

* expressed or implied

* =======================================================

 

BEGIN_COM ROLE(*EXTENDS #VF_AC012) HEIGHT(181) LAYOUTMANAGER(#ATTACHMENT_MANAGER) WIDTH(482)

 

*  Overall attachment layout manager

 

DEFINE_COM CLASS(#PRIM_ATLM) NAME(#ATTACHMENT_MANAGER)

 

*  The unleveled tree

 

DEFINE_COM CLASS(#PRIM_TRVW) NAME(#VIS_Tree) COLUMNBUTTONHEIGHT(18) DISPLAYPOSITION(1) DRAGCOLUMNS(True) FULLROWSELECT(True) HEIGHT(181) LEFT(0) MULTIPLESELECTSTYLE(SameLevel) PARENT(#COM_OWNER) SELECTIONSTYLE(Multiple) TABPOSITION(1) TABSTOP(False) TOP(0) VIEWSTYLE(UnLevelled) VISUALSTYLE(#VF_VS101) WIDTH(482)

 

* Attachment item for layout management

 

DEFINE_COM CLASS(#PRIM_ATLI) NAME(#TREE_ATTACHMENT_ITEM) ATTACHMENT(Center) MANAGE(#VIS_Tree) PARENT(#ATTACHMENT_MANAGER)

 

* Standard 2 fields for all levels in the tree

 

DEFINE_COM CLASS(#PRIM_TVCL) NAME(#Tree_VID1) CAPTION('Code/Name') CAPTIONTYPE(Caption) DISPLAYPOSITION(1) LEVEL(1) PARENT(#VIS_Tree) SORTONCLICK(True) SOURCE(#VF_ELXVI1) WIDTH(17)

 

DEFINE_COM CLASS(#PRIM_TVCL) NAME(#Tree_VID2) CAPTION('Description') CAPTIONTYPE(Caption) DISPLAYPOSITION(2) LEVEL(1) PARENT(#VIS_Tree) SORTONCLICK(True) SOURCE(#VF_ELXVI2) WIDTH(16)

 

* 2 sample additional alpha columns 

 

DEFINE_COM CLASS(#PRIM_TVCL) NAME(#Tree_acolumn1) CAPTION('Phone') CAPTIONTYPE(Caption) DISPLAYPOSITION(3) LEVEL(1) PARENT(#VIS_Tree) SORTONCLICK(True) SOURCE(#VF_ELXCA1) WIDTH(13)

DEFINE_COM CLASS(#PRIM_TVCL) NAME(#Tree_acolumn2) CAPTION('Address') CAPTIONTYPE(Caption) DISPLAYPOSITION(4) LEVEL(1) PARENT(#VIS_Tree) SORTONCLICK(True) SOURCE(#VF_ELXCA2) WIDTH(14)

 

* 1 sample additional numeric column

 

DEFINE_COM CLASS(#PRIM_TVCL) NAME(#Tree_Visncolumn1) CAPTION('Zip Code') CAPTIONTYPE(Caption) COLUMNALIGN(Right) DISPLAYPOSITION(5) LEVEL(1) PARENT(#VIS_Tree) SORTONCLICK(True) SOURCE(#POSTCODE)

 

* Hidden columns to track AKey1() AKey2() AKey3() and BusinessObjectType() for every tree item 

 

DEFINE_COM CLASS(#PRIM_TVCL) NAME(#TREE_IAK1) LEVEL(1) PARENT(#VIS_Tree) SOURCE(#VF_ELXAK1) VISIBLE(False)

DEFINE_COM CLASS(#PRIM_TVCL) NAME(#TREE_IAK2) LEVEL(1) PARENT(#VIS_Tree) SOURCE(#VF_ELXAK2) VISIBLE(False)

DEFINE_COM CLASS(#PRIM_TVCL) NAME(#TREE_IAK3) LEVEL(1) PARENT(#VIS_Tree) SOURCE(#VF_ELXAK3) VISIBLE(False)

DEFINE_COM CLASS(#PRIM_TVCL) NAME(#TVCL_BOT) LEVEL(2) PARENT(#VIS_Tree) SOURCE(#VF_ELBOT) VISIBLE(False)

 

*  Currently focused tree item

 

Define_com #Prim_Objt #FocusTreeItem Reference(*dynamic)

 

*  UI Control Definitions

 

Define Field(#UI_ISDEAF) Reffld(#VF_ELBOOL)

Def_Cond Name(*UI_LISTEN) Cond('#UI_IsDeaf *ne TRUE')

 

* Tree node tracking - track department nodes and department section nodes

 

DEFINE_COM CLASS(#Prim_kcol<#Prim_tvit #deptment>) NAME(#DepNodes) STYLE(Collection)

DEFINE_COM CLASS(#Prim_kcol<#Prim_tvit #std_texts>) NAME(#DepSecNodes) STYLE(Collection)

 

* ============================================================================

* Method Definitions

* ============================================================================

* ----------------------------------------------------------------------------

* Redefine the standard uClearInstanceList method

* ----------------------------------------------------------------------------

 

MthRoutine uClearInstanceList Options(*Redefine)

 

Invoke #DepNodes.RemoveAll

 

Invoke #DepSecNodes.RemoveAll

 

Clr_List #Vis_Tree

 

Set_ref #FocusTreeItem *null

 

EndRoutine

 

* -----------------------------------------------------------------------------

* Redefine the standard uAddListEntry method

* -----------------------------------------------------------------------------

 

Mthroutine Name(uAddListEntry) Options(*Redefine)

 

Define_com #Prim_tvit #DepParent Reference(*Dynamic) 

Define_com #Prim_tvit #SecParent Reference(*Dynamic)

 

* The filter(s) supply SECTIONS and EMPLOYEES business objects in the instance

* list, but this instance list browser has decided to create a 3 level tree to

* visualize the data slightly differently. Handle each business object type differently ....   

 

CASE OF_FIELD(#BusinessObjectType.Value)

 

* ========================

* SECTIONS business object 

* ========================

 

WHEN VALUE_IS(= SECTIONS)

 

* Check for a parent department node in the tree and add one if required

 

Set_ref #DepParent #DepNodes<#AKey1.Value>

 

If_ref #DepParent is(*null)

 

#VF_ELXAK1 := #AKey1.Value

#VF_ELXAK2 := ''

#VF_ELXAK3 := ''

#VF_ELBOT  := ''

#VF_ELXVI1 := #AKey1.Value

#VF_ELXVI2 := 'Department ' + #AKey1.Value

#VF_ELXCA1 := ''

#VF_ELXCA2 := ''

#POSTCODE := 0

 

Add_Entry #Vis_Tree

 

Set_Ref #DepParent #Vis_Tree.CurrentItem

 

Set_Ref #DepNodes<#AKey1.Value> #DepParent

 

Endif

 

* Now add in the section node as a child of the department and keep a track of it 

 

#VF_ELXAK1 := #AKey1.Value

#VF_ELXAK2 := #AKey2.Value

#VF_ELXAK3 := #AKey3.Value

#VF_ELBOT  := #BusinessObjectType.Value

#VF_ELXVI1 := 'Section ' + #AKey2.Value

#VF_ELXVI2 := #AColumn1.Value

#VF_ELXCA1 := ''

#VF_ELXCA2 := ''

#POSTCODE := #Ncolumn1.Value

 

Add_Entry #Vis_Tree

 

Set #Vis_Tree.CurrentItem ParentItem(#DepParent)

 

Set_Ref #DepSecNodes<(#AKey1.Value + '.' +  #Akey2.Value)> #Vis_Tree.CurrentItem

 

* =========================

* EMPLOYEES business object

* =========================

 

WHEN VALUE_IS(= EMPLOYEES)

 

#VF_ELXAK1 := #AKey1.Value

#VF_ELXAK2 := #AKey2.Value

#VF_ELXAK3 := #AKey3.Value

#VF_ELBOT  := #BusinessObjectType.Value

#VF_ELXVI1 := #VisualId1.Value

#VF_ELXVI2 := #VisualId2.Value

#VF_ELXCA1 := #AColumn1.Value

#VF_ELXCA2 := #AColumn2.Value

#POSTCODE  := #NColumn1.Value

 

Add_Entry #Vis_Tree

 

* Final the section node (previously added) that will be this nodes tree parent

 

Set_Ref #SecParent #DepSecNodes<(#AKey1.Value + '.' +  #Akey2.Value)>

 

* Show an error or set the parent item correctly ....

 

If_ref #SecParent is(*null)

Use message_box_show ( ok ok error *Component 'Attempt to add employee with out a valid SECTIONS parent')

else

Set #Vis_Tree.CurrentItem ParentItem(#SecParent)

Endif

 

ENDCASE

 

*  Finished

 

EndRoutine

* -------------------------------------------------------------------

* Determine whether to accept selection of new Sections from the grid

* -------------------------------------------------------------------

EVTROUTINE HANDLING(#Vis_Tree.ItemGotFocusAccept #Vis_Tree.ItemGotSelectionAccept) Accept(#ACCEPT) OPTIONS(*NOCLEARMESSAGES *NOCLEARERRORS)

If (#vf_elbot *ne ' ')

If Cond('#avFrameworkManager.uCurrentLockStatus *EQ TRUE')

#ACCEPT := FALSE

#UI_ISDEAF := TRUE

Else

#ACCEPT := TRUE

#UI_ISDEAF := FALSE

Endif

Endif

ENDROUTINE

* -----------------------------------------

* Handle selection of an item from the tree

* -----------------------------------------

EvtRoutine Handling(#Vis_Tree.ItemGotSelection) OPTIONS(*NOCLEARMESSAGES *NOCLEARERRORS)

 

If (#vf_elbot *ne ' ')

 

Signal SetSelectedInstance  AKey1(#VF_ELXAK1) AKey2(#VF_ELXAK2) AKey3(#VF_ELXAK1) BusinessObjectType(#VF_ELBOT)

 

*  Handle the special case where the focus did not fire correctly

 

If_ref #FocusTreeItem is(*null)

Set_ref #FocusTreeItem #Vis_Tree.CurrentItem

Signal SetCurrentInstance  AKey1(#VF_ELXAK1) AKey2(#VF_ELXAK2) AKey3(#VF_ELXAK3) BusinessObjectType(#VF_ELBOT)

Endif

 

Endif

EndRoutine

* -------------------------------------------

* Handle unselection of an item from the tree

* -------------------------------------------

EvtRoutine Handling(#Vis_Tree.ItemLostSelection) OPTIONS(*NOCLEARMESSAGES *NOCLEARERRORS)

If (#vf_elbot *ne ' ')

Signal DropSelectedInstance  AKey1(#VF_ELXAK1) AKey2(#VF_ELXAK2) AKey3(#VF_ELXAK3) BusinessObjectType(#VF_ELBOT)

Endif

EndRoutine

* -------------------------------------

* Handle focus of an item from the tree

* -------------------------------------

EvtRoutine Handling(#Vis_Tree.ItemGotFocus) OPTIONS(*NOCLEARMESSAGES *NOCLEARERRORS)

If Cond(*UI_LISTEN)

If (#vf_elbot *ne ' ')

Signal SetCurrentInstance  AKey1(#VF_ELXAK1) AKey2(#VF_ELXAK2) AKey3(#VF_ELXAK3) BusinessObjectType(#VF_ELBOT)

Endif

Endif

EndRoutine

* ---------------------------------------------

* Handle loss of focus of an item from the tree

* ---------------------------------------------

EvtRoutine Handling(#Vis_Tree.ItemLostFocus) OPTIONS(*NOCLEARMESSAGES *NOCLEARERRORS)

If (#vf_elbot *ne ' ')

Signal DropCurrentInstance  AKey1(#VF_ELXAK1) AKey2(#VF_ELXAK2) AKey3(#VF_ELXAK3) BusinessObjectType(#VF_ELBOT)

Endif

EndRoutine

 

End_Com