Designer 10.5 | webMethods Mobile Development | Creating Business Logic for a Mobile Application | Logic for a Dialog
 
Logic for a Dialog
Logic to Display a Dialog
You can open a dialog in the following ways:
*Open a dialog in response to a listener event.
If you want to open a dialog in response to a listener event, add an OpenDialog object to the model and select the name of the dialog you want to open for the OpenDialog object’s Dialog property. For more information, see Responding to User-Initiated Events and OpenDialog Properties.
*Open a dialog by creating the dialog class.
To create the dialog class, invoke the class that Mobile Development generates for the dialog, for example, MyAlertDialog.java, where MyAlertDialog is the value you specified for the AlertDialog object’s Class Name property. For example:
call new MyAlertDialog(delegate).open();
In the code line to create the dialog, delegate is an instance of iDialogDelegate. By default, all abstract controllers implement iDialogDelegate.
*Open a dialog by invoking the openDialog method, which is in the AbstractApplicationController.java in the gen/api-src folder in the com.softwareag.mobile.runtime.toolkit package. In this case, pass a generated instance of an AbstractAlertDialog to the openDialog() method.
For example, for an application named "MyApplication" and a dialog named "MyAlertDialog", you can use the following:
MyApplicationControllerImpl.openDialog(new MyAlertDialog(dialogDelegate));
Note:
Only one dialog can be opened at the same time.
Logic to Close a Dialog
A dialog closes when a user presses any button in the dialog.
You can also programmatically close a dialog by invoking the closeDialog() method, which is in the AbstractApplicationController.java in the gen.api-src.com.softwareag.mobile.runtime.toolkit package.
Additional Logic
When you add a dialog object to the user interface, you can add one or several DialogButton object(s) as a child object. When you generate sources for the mobile project, Mobile Development generates code to:
*Display the alert dialog with the text you specify in the AlertDialog object’s Text property.
*Display the pop-up menu with the text you specify in the PopupMenu object’s Cancel Text property.
If you want a dialog that simply displays text with a single close button, you do not need to add any further custom code.
If you want to perform additional logic in the dialog or add additional DialogButton child objects, you can customize the logic for the dialog.
When you generate sources for a mobile project, Mobile Development generates a Java class for the dialog where you can add your custom logic. The name of the Java class is the name you specify for the dialog object’s Class Name property. Mobile Development generates the class in the src folder in the package_name.ui.dialog package. For example, if you specify "MyAlertDialog" for the Class Name property and assign the package name "com.mycompany" to the mobile project, Mobile Development generates MyAlertDialog.java in the com.mycompany.ui.dialog package.
When a user presses a button in the dialog, the onDialogButtonPressed(final AbstractDialog dialog, final intbuttonID) method in the iDialogDelegate Java class is invoked. The buttonID is the value of the Id property that you specified for the DialogButton object in the model. If a dialog contains multiple buttons, your logic can identify the button a user selected and take action based on the specific button the user pressed. The following shows sample logic:
public void onDialogButtonPressed(AbstractDialog dialog,
int buttonId) {
switch (buttonId) {
case YMNDialog.YESBUTTON:
getView().getDialogResult().setText("YES !!!");
break;
case YMNDialog.MAYBEBUTTON:
getView().getDialogResult().setText("MAYBE !!!");
break;
case YMNDialog.NOBUTTON:
getView().getDialogResult().setText("NO !!!");
break;
 
default:
break;
}
dialog.close();
}
For a PopupMenu object, you can also add buttons dynamically. To do so, you must override the initDialog() method in the generated PopupMenuName class. In this class, you must call the super method to initially create the pop-up menu. Then you can add the required buttons as follows:
protected nUIPopupMenuBuilder initDialog() {
nUIPopupMenuBuilder popupMenuBuilder = super.initDialog();
popupMenuBuilder.addItem("dynamicButton", new Runnable() {
public void run() {
// handle this
}
});
return popupMenuBuilder;
}
You can also dynamically decide which buttons should be shown or hidden in a pop-up menu. In this way, you can define the menu completely in the model and programmatically decide which buttons to show or hide depending on the current data. The following shows the sample logic:
public boolean showDialogButton(AbstractDialog dialog, int buttonId) {
switch (buttonId) {
case Constants.NUIID_BUTTON1:
return shouldButton1BeVisible();
case Constants.NUIID_BUTTON2:
return shouldButton2BeVisible();
default:
return true;
}
}
Related Topics