B4J Question [ABMaterial] Reuse Row from BuildPage

Harris

Expert
Licensed User
Longtime User
Essentially, I have a row and a cell that are used for 2 different purposes - depending on what is currently shown (state of ABMSwitch). Currently, it all works well yet I fret whether it is efficient, since I am building (adding) multiple ABMContainers on the fly... It is slower to build since a new object is created for each list item.

The code creates a new ABMContainer (inits, add rows and builds) for each item in a list.
I have tried to shortcut this but nothing produces the correct result (other than shown below).

Any advise is appreciated.

Thanks


B4X:
Sub btnshowallagenda_clicked(Target As String)
   
    Dim shall As ABMSwitch = page.Component("btnshowallagenda")
    Dim choice As ABMCombo = page.Component("agend")
    Dim ph As Int = choice.GetActiveItemId
   
    Dim SQL As SQL = DBM.GetSQL
   
    If shall.State Then   ' show all or only select combo item
      Dim sql_str As String = "Select * from cagenda where comp_id = 0 OR comp_id = "&Main.comp_id
    Else
      Dim sql_str As String = "Select * from cagenda where id ="&ph
    End If     
   
    Dim agnitems As List = DBM.SQLSelect(SQL,sql_str,Null)
   
    page.Row(4).Cell(2).RemoveAllComponents   ' clear all in this row, cell
   
    For i = 0 To agnitems.Size - 1
        Dim curritem As Map = agnitems.Get(i)
        Dim cname As String = curritem.Get("name")
        Dim cnum As Int = curritem.Get("id")
       
        ' create a NEW container to add to this row
        Dim cont1 As ABMContainer
        cont1.Initialize(page,  "scont"&i, "")
        cont1.AddRowsM(1,False ,0,0, "").AddCellsOSMP(1,0 ,0,0,12,12,12, 0,0,0,0,"")
        cont1.BuildGrid ' IMPORTANT
           Dim agnitemslbl As ABMLabel ' = cont1.Component("pres1")
      
        agnitemslbl.Text = ""
       
       If shall.State Then
          cname = agnitemslbl.Text&"{B}"&(i+1)&"){NBSP}"&cname.ToUpperCase&"{/B}{BR}"
       Else
          cname = agnitemslbl.Text&"{B}"&cname.ToUpperCase&"{/B}{BR}"
       End If
       agnitemslbl.Text = cname

       Dim sql_str As String = "Select * from cagendaitems where comp_id = "&Main.comp_id&" AND mastid = "&ActiveCaseId&" AND itemid = "&cnum
       Dim agnitemrecs As List = DBM.SQLSelect(SQL,sql_str,Null)
      
       If agnitemrecs.Size = 0 Then
             Dim des As String = "..."
          des = "{NBSP}{NBSP}{NBSP}"&des
          agnitemslbl.Text = agnitemslbl.Text&des&""
       Else   
          Dim dmap As Map = agnitemrecs.Get(0)
          Dim desc As String = dmap.Get("descrip")
          desc = "{NBSP}{NBSP}{NBSP}"&desc
          agnitemslbl.Text = agnitemslbl.Text&desc&""
       End If
      
       ' add this component to this container
       cont1.Cell(1,1).AddComponent(agnitemslbl)
    
        Dim attCounter As Int = 0
        Dim SQL1 As SQL = DBM.GetSQL
        Dim sql_s As String = "SELECT * FROM cagendattach WHERE mastid = " & ActiveCaseId &" AND CaseACaseID = "&cnum
        Dim attachs As List = DBM.SQLSelect(SQL1,sql_s, Null)
               
        Dim attLocation As String =  "../uploads/" &"comp_"&Main.comp_id&"/"
        For j=0 To attachs.Size - 1
            Dim attach As Map = attachs.Get(j)
            Dim CaseAID As String  =  attach.Get("caseavalue")
            Dim filename As String = attach.Get("shortname")

            Dim chip As ABMChip
            attCounter = attCounter + 1
            Dim casetype As Int = attach.Get("caseatype")
            
            If casetype = 0 Then
               chip.Initialize(page,  ""&attCounter, "{AL}" & attLocation & CaseAID & "{AT}" &filename & "{/AL}" , False, "chip1")
            Else
               chip.Initialize(page,  ""&attCounter, "{AL}" &  CaseAID & "{AT}" &filename & "{/AL}" , False, "chip1")
            End If  
            chip.Tag = filename
            ' add this chip to arraycomponent
            cont1.Cell(1,1).AddArrayComponent(chip, "Chiplnk1")
        Next   
            
         If shall.State Then
              Dim spc As ABMLabel  ' this is to give some space between last added and divider
             spc.Initialize(page,"spc"&i," " , ABM.SIZE_PARAGRAPH,False,"")
             cont1.Cell(1,1).AddComponent( spc )       
       
             Dim ln As ABMDivider
             ln.Initialize(page,"dv"&i,"")
             cont1.Cell(1,1).AddComponent(ln)
         End If
                     
        DBM.CloseSQL(SQL1)
        page.Row(4).Cell(2).AddComponent(cont1)   
      
    Next

    DBM.CloseSQL(SQL)
    page.Cell(4,2).Refresh
   
End Sub
 

Harris

Expert
Licensed User
Longtime User
I can't really see a more efficient way to do it right now. On average, what is the size of 'agnitems' (or how many containers need to be build)?
There are only 15 items in this list (currently). It does work well enough (fast), just wondering...
Thanks for your advise.
 
Upvote 0
Top