B4J Question Whats the best way to handle multiple Windows/Views

MarcRB

Active Member
Licensed User
Longtime User
Sorry for my bad Englisch:

I'm rebuilding an old ERP application, that I wrote some years ago in Visual Basic (MDI style with toolbar).
This time I will create the application with B4J as a MS Windows desktop application.
That application has a lot of windows for example: customers, pricelist, invoices, orders, tasks,...
Each window is a view in B4J.
New layout is left sidebar as menu and at right a place where the different windows appear.

I tested B4XPages and I tested a panel that loads each view. Also I looked at another topic where somebody emulates MDI style.
In B4Xpages each page is an item in the MS Windows taskbar. Also each window has it's own (moveable) position and the menu can disapear behind one of the windows or the menu has to be placed on each window.

In panel method I can create the menu at left and load the views as needed in the panel at right. Also there is just one item in the MS Windows taskbar. Almost perfect!
But..... each view has many controls on in, all associated code is now in the same class. That will be a massive class handling controls for about 10 windows.

What is the best way to work with multiple windows?

Thanks for each advice.
 

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
In panel method I can create the menu at left and load the views as needed in the panel at right. Also there is just one item in the MS Windows taskbar. Almost perfect!
This is the best approach, and you don't need to have all the code in the same class.

When you create a class the method initialize comes with it. You can modify this method to your needs

B4X:
' customerClass

public sub initialize(customer_id) as panel
dim p as panel
p.initialize("")
p.loadlayout("customerLayout")
....
return p
end sub
do whatever you need with p on the main module.
 
Upvote 1

udg

Expert
Licensed User
Longtime User
New layout is left sidebar as menu and at right a place where the different windows appear.
Did you have a look at B4xDrawer? It works exactly like that and you should find an example B4xPages+B4xDrawer in the Forum.
 
Upvote 0

MarcRB

Active Member
Licensed User
Longtime User
Did you have a look at B4xDrawer? It works exactly like that and you should find an example B4xPages+B4xDrawer in the Forum.
B4XDrawer is quite cool.
I think I adopt this in my project.
B4XPages is also cool (at least in B4A) but I think it is not the best way for my use in this project.
All pages take a place in Windows Taskbar,
 
Upvote 0

MarcRB

Active Member
Licensed User
Longtime User
This is the best approach, and you don't need to have all the code in the same class.

When you create a class the method initialize comes with it. You can modify this method to your needs

B4X:
' customerClass

public sub initialize(customer_id) as panel
dim p as panel
p.initialize("")
p.loadlayout("customerLayout")
....
return p
end sub
do whatever you need with p on the main module.
I Think this the way, but i'm doing something (basicly) wrong.

I made a little project for test.
In the first layout I placed a button and a panel (pane).

The second layout is called LayCustomers. This layout contains a button and a label.
The code of button and label are placed in a classs and I changed the initialze sub.

What is the code in first layout for loading layout in pane?
First layout:
#Region Project Attributes
    #MainFormWidth: 600
    #MainFormHeight: 600
#End Region

Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private xui As XUI
    Private Button1 As B4XView
    Private Pane1 As B4XView
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("Layout1")  'Cotains button and panel
    MainForm.Show
End Sub

Sub Button1_Click
    'Pane1.LoadLayout("layCustomers")  'Old school layout loading
    
    'new layout loading with controls in class
    Private PanCustomers As customers_c
    PanCustomers.initialize
    
    Pane1 = PanCustomers
End Sub

Second layout (i.e. layCustomers):
Sub Class_Globals
    Private fx As JFX
    Private btnTest As Button
    Private lblTest As Label
End Sub

'Initializes the object. You can add parameters to this method if needed.
public Sub initialize() As Pane
    Dim p As Pane
    p.initialize("")
    p.loadlayout("layCustomers")
    Return p
End Sub

Private Sub btnTest_Click
    lblTest.Text = "Very nice"
End Sub
 
Upvote 0
Top