Through broker.ui.*services, we can have access to different functions related to the user’s interface and navigation control of the different Layouts of the application.

PUBLIC METHODS

void broker.ui.push(String layoutName)

It displays the layout referenced in layoutName and adds it to the navigation stack. In the same action, a model corresponding to the one configured as datasource in the layoutName layout is autogenerated and bound .This method can only be used with experiences (not valid for layout of crossmenu type).

Arguments
layoutName String: Name of the layout.
Exceptions
LayoutNotFound – Layout layoutName not found.
InvalidUIAction – Error when trying to execute push action outside application navigation stack.

void broker.ui.push(String layoutName, Model… dataSourceModel)

It displays the layout referenced in layoutName and adds it to the current navigation stack. In the same action, the models passed after the first argument are bound to the datasouce models configured in the layout. For the experiences, there is always 1 dataSource to bind, at most.

In the case of the layout of crossmenu type, the argument models to be bound in the dataSource are as many as the number of items the menu has. It is important to point out that for this kind of layout, every layout referenced inside the crossmenu must have a binding dataSource on its definition.

Arguments
layoutName String: Name of the layout.
dataSourceModel Model: Model bound to the first dataSource configured in the layout.
dataSourceModelN Model: Nth model bound to the nth dataSource set up in the layout.
Exceptions
LayoutNotFound – Layout layoutName not found.
InvalidUIAction – Error when trying to execute push action outside application navigation stack.
WrongNumberOfArgumentsInCall – Trying to navigate to layout layoutName with wrong number of datasources.

void broker.ui.pop()

It finishes the display of the current layout and removes it from the navigation stack. This method can only be used if a layout was added previously using the push method.

Exceptions
InvalidUIAction – Error when trying to execute pop action outside application navigation stack.

void broker.ui.present(String layoutName)

It displays the layout referenced in layoutName and adds it to the navigation stack modally. In the same action, a model corresponding to the one configured as datasource in the layoutName layout is autogenerated and bound. This method can only be used with experiences (not valid for layout of crossmenu type).

Arguments
layoutName String: Name of the layout.
Exceptions
LayoutNotFound – Layout layoutName not found.
InvalidUIAction – Error when trying to execute push action outside application navigation stack.

void broker.ui.present(String layoutName, Model… dataSourceModel)

It displays the layout referenced in layoutName and adds it to the navigation stack, modally. In the same action, the models passed after the first argument are bound to the datasouce models configured in the layout. For the experiences, there is always 1 dataSource to bind, at most.

In the case of the layout of crossmenu type, the argument models to be bound in the dataSource are as many as the number of items the menu has. It is important to point out that for this kind of layout, every layout referenced inside the crossmenu must have a binding dataSource on its definition.

Arguments
layoutName String: Name of the layout.
dataSourceModel Model:Model bound to the first dataSource configured in the layout.
dataSourceModelN Model: Nth model bound to the nth dataSource set up in the layout.
Exceptions
LayoutNotFound – Layout layoutName not found.
InvalidUIAction – Error when trying to execute present action outside application navigation stack.
WrongNumberOfArgumentsInCall – Trying to navigate to layout layoutName with wrong number of datasources.

void broker.ui.dismiss()

It finishes the display of the current layout and removes it from the navigation stack. This method can only be used if a layout was added previously using the present method.

Exceptions
InvalidUIAction – Error when trying to execute dismiss action outside application navigation stack.

void broker.ui.setInitialExperience(String layoutName)

It displays the layout referenced in layoutName by replacing the current navigation stack for a new one that only contains the new layout. In the same action, a model corresponding to the one configured as datasource in the layoutName layout is autogenerated and bound. This method can only be used with experiences (not valid for layout of crossmenu type).

Argumentos
nombreLayout String: Name of the layout.
Excepciones
LayoutNotFound – Layout nombreLayout not found.
InvalidUIAction – Error when trying to execute push action outside application navigation stack.

void broker.ui.setInitialExperience(String layoutName, Model… dataSourceModel)

It displays the layout referenced in layoutName by replacing the current navigation stack for a new one that only contains the new layout. In the same action, the models passed after the first argument are bound to the datasource models configured in the layout. For the experiences, there is always 1 dataSource to bind, at most.

In the case of the layout of crossmenu type, the argument models to be bound in the dataSource are as many as the number of items the menu has. It is important to point out that for this kind of layout, every layout referenced inside the crossmenu must have a binding dataSource on its definition.

Argumentos
nombreLayout String: Name of the layout.
dataSourceModel Model: Model bound to the first dataSource configured in the layout.
dataSourceModelN Model: Nth model bound to the nth dataSource set up in the layout.
Exceptions
Excepciones
LayoutNotFound – Layout nombreLayout not found.
InvalidUIAction – Error when trying to execute push action outside application navigation stack.
WrongNumberOfArgumentsInCall – Trying to navigate to layout nombreLayout with wrong number of datasources.

Model broker.ui.getDataSource()

It returns the model bound to the layout that is being displayed or null, if no model is found.

Return
Model Model bound to the layout that is being displayed or null, if no model is found.

void broker.ui.showAlert(String title, String description)

It shows a dialogue box with title and description.

Parameters
title String: Title to be displayed in the dialogue box.
description String: Description to be displayed in the dialogue box.
Exceptions
InvalidUIAction – Error when trying to execute showAlert action outside application navigation stack.

Integer broker.ui.showAlert(String title, String description, String positiveBtnTitle)

It shows a dialogue box with title, description and a button with the following text: ‘positiveBtnTitle’.

Parameters
title String: Title to be displayed in the dialogue box.
description String: Description to be displayed in the dialogue box.
positiveBtnTitle String: Text to be displayed in the positive button.
Return
Integer It always returns value 1 corresponding to the positive button.
Exceptions
InvalidUIAction – Error when trying to execute showAlert action outside application navigation stack.

Integer broker.ui.showAlert(String title, String description, String positiveBtnTitle, String negativeBtnTitle)

It shows a dialogue box with title, description and buttons with the following texts: ‘positiveBtnTitle’ and ‘negativeBtnTitle’.

Parameters
title String: Title to be displayed in the dialogue box.
description String: Description to be displayed in the dialogue box.
positiveBtnTitle String: Text to be displayed in the positive button.
negativeBtnTitle String: Text to be displayed in the negative button.
Return
 Integer It returns 1 if the user clicks on the positive button. It returns 0-1 if the user clicks on the negative button.
Exceptions
InvalidUIAction – Error when trying to execute showAlert action outside application navigation stack.

Integer broker.ui.showAlert(String title, String description, String positiveBtnTitle, String negativeBtnTitle, String cancelBtnTitle)

It shows a dialogue box with title, description and buttons with the following texts: ‘positiveBtnTitle’, ‘negativeBtnTitle’ and ‘cancelBtnTitle’.

Parameters
title String: Title to be displayed in the dialogue box.
description String: Description to be displayed in the dialogue box.
positiveBtnTitle String: Text to be displayed in the positive button.
negativeBtnTitle String: Text to be displayed in the negative button.
cancelBtnTitle String: Text to be displayed in the cancel button.
Return
 Integer It returns 1 if the user clicks on the positive button.It returns 0-1 if the user clicks on the negative button. It returns 0 if the user clicks on the cancel button.
Exceptions
InvalidUIAction – Error when trying to execute showAlert action outside application navigation stack.

void broker.ui.showLoading()

It displays an activity indicator view on top of the layout that is being displayed, catches user touch events blocking any posible user interaction.

void broker.ui.hideLoading()

It hides the activity indicator that is being displayed due to a previous call to broker.ui.hideLoading() service.

Important: The mat|r developer is responsible for balancing broker.ui.showLoading() and broker.ui.hideLoading() calls.

Example:

Experience Main {
    Decision rule1 action("MainContext.pushExperience") label("Push Experience")
    Decision rule2 action("MainContext.presentExperience") label("Present Experience")
    Decision rule4 action("MainContext.showAlert") label("Show Alert")
    Decision rule5 action("MainContext.fetchDataAndStoreOnCloud") label("fetchDataAndStoreOnCloud")	
}

Experience SecondExperience {
    Decision rule1 action("MainContext.popExperience") label("Pop Experience")
    Decision rule2 action("MainContext.dismissExperience") label("Dismiss Experience")
}

RuleContext MainContext {

    Rule pushExperience {
        //create an instance of SecondExperience
        SecondExperience exp = SecondExperience()
        //show experience using push method
        broker.ui.push("SecondExperience", exp)
    }

    Rule presentExperience {
        SecondExperience segExp = SecondExperience()
        //show experience using present method, this creates a new navigations layout stack
        broker.ui.present("SecondExperience", segExp)
    }

    Rule popExperience {
        broker.ui.pop()
    }

    Rule dismissExperience {
        broker.ui.dismiss()
    }

    Rule showAlert {
        broker.ui.showAlert("Title", "Description")
    }

    Rule fetchDataAndStoreOnCloud {
        broker.ui.showLoading() //prevent user interacts with Experience and show an activity indicator
        Array<ResponseDTO> rspData = service.longFetch.call()
        for rsp in rspData { //some processing with rsp
            broker.cloudStorage.save(rsp)
        }
        broker.ui.hideLoading() 
    }
}