Page 1 of 1

Refresh a changed #PRIM_TBLO.Item

Posted: Sat Nov 03, 2018 7:24 am
by gstenstrom
I'm dynamically creating a layout grid using #PRIM_TBLO.Column and #PRIM_TBLO.Item
To start with I have 4 #PRIM_TBLO.Rows already defined.

After I create the grid with panels in the first row, a button is added that spans 2 of the columns using the Layout Item (#PRIM_TBLO.Item)

There is a click event for the buttons which loops on the array of #PRIM_TBLO.Item to find the one managing the button and change the ColumnSpan from 2 to 1.

I was hoping the button would shrink in size to be only be in one panel but it is not.

What am I missing?
Tried several methods but nothing works.

Glynn

Code: Select all

* Collections for the buttons, panels and layoutitems being created dynamically
Define_Com Class(#Prim_acol<#PRIM_TBLO.Column>) Name(#loColumns)
Define_Com Class(#Prim_acol<#PRIM_TBLO.Row>) Name(#loRows)
Define_Com Class(#Prim_acol<#Prim_tblo.Item>) Name(#LayoutItemPanels)
Define_Com Class(#Prim_acol<#Prim_tblo.Item>) Name(#LayoutItemBottons)
Define_Com Class(#Prim_acol<#Prim_panl>) Name(#Panels)
Define_Com Class(#Prim_acol<#PRIM_PHBN>) Name(#Buttons)


Define Field(#wDate) Type(*Date)

Evtroutine Handling(#Com_owner.Initialize)
#wDate := #wDate.Now
Begin_Loop Using(#STD_INT) To(10)
#wDate := #wDate.Adjust( 1 )
* #SYS_WEB.Console.Log( #STD_INT.AsString )
* #SYS_WEB.Console.Log( #wDate.AsDayOfWeek )
* #SYS_WEB.Console.Log( #wDate.AsDisplayString( CCYYMMDD ) )
#loColumns.Insert( (*New #PRIM_TBLO.Column) )
#loColumns.Last.Parent <= #LayoutMain
#loColumns.Last.DisplayPosition := #STD_INT
#loColumns.Last.Units := Proportion
#loColumns.Last.Width := 1.0
#loColumns.Last.ComponentTag := #wDate.AsDisplayString( MMsDDsCCYY )

#Panels.Insert( (*New #Prim_panl) )
#Panels.Last.Parent <= #COM_OWNER

If Cond((#wDate.AsDayOfWeek *EQ 'SATURDAY') *Or (#wDate.AsDayOfWeek *EQ 'SUNDAY'))
#Panels.Last.Style <= #WeekendStyle
Else
#Panels.Last.Style <= #WeekdayStyle
Endif

#LayoutItemPanels.Insert( (*New #PRIM_TBLO.Item) )
#LayoutItemPanels.Last.Parent <= #LayoutMain
#LayoutItemPanels.Last.Sizing := FitBoth
#LayoutItemPanels.Last.Alignment := Center
#LayoutItemPanels.Last.Flow := None
#LayoutItemPanels.Last.Column <= #loColumns.Last
#LayoutItemPanels.Last.Row <= #LayoutMainRow1
#LayoutItemPanels.Last.Manage <= #Panels.Last

End_Loop

* add button
#Buttons.Insert( (*New #PRIM_PHBN) )
#Buttons.Last.Parent <= #COM_OWNER
#Buttons.Last.DisplayPosition := 1
#Buttons.Last.Caption := #loColumns.Item<4>.ComponentTag
#Buttons.Last.ComponentTag := #loColumns.Item<4>.ComponentTag


#LayoutItemBottons.Insert( (*New #PRIM_TBLO.Item) )
#LayoutItemBottons.Last.Parent <= #LayoutMain
#LayoutItemBottons.Last.Sizing := FitToWidth
* #LayoutItemBottons.Last.Alignment := Center
#LayoutItemBottons.Last.Marginleft := 20
#LayoutItemBottons.Last.Marginright := 20
#LayoutItemBottons.Last.Columnspan := 2
#LayoutItemBottons.Last.Flow := None
#LayoutItemBottons.Last.Column <= #loColumns.Item<4>
#LayoutItemBottons.Last.Row <= #LayoutMainRow1
#LayoutItemBottons.Last.Manage <= #Buttons.Last


Endroutine

Evtroutine Handling(#Buttons<>.Click) Com_Sender(#Button)
#SYS_WEB.Console.Log( ('button: ' + #Button.ComponentTag) )
For Each(#LayoutItemBotton) In(#LayoutItemBottons)
#SYS_WEB.Console.Log( ('#LayoutItemBotton: ' + #Button.ComponentTag) )
If Cond(#LayoutItemBotton.ComponentTag *EQ #Button.ComponentTag)
#LayoutItemBotton.ColumnSpan := 1
#Button.Scale Scalewidth(1) Scaleheight(1)
Leave
Endif
Endfor
Endroutine

Re: Refresh a changed #PRIM_TBLO.Item

Posted: Mon Nov 05, 2018 9:25 am
by dannyoorburg
Hi,

I don't think your code does what you think it does :) I never see the ComponentTag of the layout item being assigned any value...

I suggest you just compare references, instead of ComponentTag values, so instead of

Code: Select all

If Cond(#LayoutItemBotton.ComponentTag *EQ #Button.ComponentTag)
it is be much easier to test for the references being equal, as in:

Code: Select all

If (#LayoutItemBotton.Manage *IsEqualTo #Button)
then you don't need the ComponentTag 'trick'.

When I make that change I see the "ColumnSpan := 1" actually being executed and working as expected.


For future references, LANSA has got quite a nifty feature for associating 2 objects, like you're trying to do here with buttons and their corresponding layout items.

You can do that with a Dictionary Collection (PRIM_DCOL). It would reduce your code to something as simple as:

Code: Select all

Define_Com Class(#PRIM_LCOL<#PRIM_PHBN>) Name(#Buttons)
Define_Com Class(#PRIM_DCOL<#PRIM_TBLO.ITEM #PRIM_PHBN>) Name(#LayoutItems)

Mthroutine Name(CreateButton)

Define_Com Class(#PRIM_PHBN) Name(#Button) Reference(*DYNAMIC)

#Button <= *New #PRIM_PHBN
#Buttons.Insert( #Button )

#LayoutItems<#Button> <= *New #PRIM_TBLO.ITEM
#LayoutItems<#Button>.Manage <= #Button

Endroutine

Evtroutine Handling(#Buttons<>.Click) Com_Sender(#Button)

#LayoutItems<#Button>.RowSpan := 1

Endroutine
Cheers,
Danny

Re: Refresh a changed #PRIM_TBLO.Item

Posted: Tue Nov 06, 2018 1:25 am
by gstenstrom
Thanks for the post. I see where I missed adding the Component Tag to #LayoutItemButtons.

I reworked my code to use the #PRIM_DCOL you suggested. This technic will be a big help going forward.

Thanks again,
Glynn

Re: Refresh a changed #PRIM_TBLO.Item

Posted: Tue Nov 06, 2018 10:23 am
by dannyoorburg
No problem. Feel free to ask more questions as they pop up.

Just on the side: I'm always a bit wary of RDMLX that dynamically creates UI. You end up missing out on all the designer features because you're now doing it in code, and unless you're writing some sort of framework (which isn't easy), there's usually not much of a reason to do it.

So unless I've got a very good reason I just stick to drag and drop and using the designer :)

Goodluck,
Danny