Book Image

ExtGWT Rich Internet Application Cookbook

By : Odili Charles Opute , Oded Nissan
Book Image

ExtGWT Rich Internet Application Cookbook

By: Odili Charles Opute , Oded Nissan

Overview of this book

<p>Get ready to build the next generation Gmail, Facebook, or Meebo, with HTML5 and Server Push, taking advantage of the power and versatility of Java with ExtGWT. Sencha Ext GWT takes GWT to the next level, giving you high-performance widgets, feature-rich templates and layouts, advanced charting, data loaders and stores,&nbsp; accessibility, and much more.<br /><br /><i>ExtGWT Rich Internet Application Cookbook will teach you to quickly build&nbsp; stunning functionality into your own apps with ExtGWT</i>.<br /><br />This is a catalog of practical solutions to get your ExtGWT web app up and running in no time, with tips for persistence and best practices. You begin by playing with panels, windows, and tabs, to learn the essentials. Next, you engage yourself with forms, buttons, toolbars and menus to build on further. Dealing with the UI and the trees will follow to help you make stunning user interfaces. Then you will be taught to work with Listview, Views, and Gridpanels, the more complex problems. The book will then deal with charts, visualization, and drag and drop to take you to the next level. Finally, you will wind up with serialization, persistence, and custom theming. Now, you are an expert!</p>
Table of Contents (22 chapters)
ExtGWT Rich Internet Application Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Event Handling — Making Those GUIs Do Something
Jakarta Commons-FileUpload

Pre-empt users with messages


The GXT toolkit also has a MessageBox class. It is very similar in concept and functionality to the Dialog class, except for its convenience methods for specific displays and the icons associated with these displays (which can be achieved with the Dialog class too, but with a little hair-pulling). It's therefore safe for us to call them (both classes) Dialogs, especially considering them from a presentation perspective, but they are different.

How to do it...

  1. 1. Call MessageBox.alert(), passing in a title, a message to show, and an optional listener as parameters, to display an alert dialog.

  2. 2. Call MessageBox.confirm(), passing in a title, a message to show, and an optional listener as parameters, to display a confirmation dialog.

  3. 3. Call MessageBox.prompt() with a title, a message to show, and an optional listener, to display a prompt dialog.

@Override
public void onModuleLoad() {
// So we can handle your button clicks
Listener<MessageBoxEvent> listener = new Listener<MessageBoxEvent>(){
@Override
public void handleEvent(MessageBoxEvent evt) {
Button btn = evt.getButtonClicked();
Info.display("Recipe Four", "The '{0}' button was pressed", btn.getText());
MessageBoxType msgBoxType = evt.getMessageBox().getType();
if(msgBoxType != null &&
(msgBoxType.equals(MessageBoxType.PROMPT) ||
msgBoxType.equals(MessageBoxType.MULTIPROMPT))){
Info.display("Recipe Four : Prompt", evt.getValue());
}
}
};
// Show alert message
MessageBox.alert("Alert", "Invalid Login Credentials", listener);
// Show confirm message
MessageBox.confirm("Confirm", "Do you intend to logout", listener);
// Show prompt message
MessageBox.prompt("Prompt", "Please tell us your name 'promptly'", listener);
// Show progress message
final MessageBox pBar = MessageBox.progress("Progress", "Calculating your comprehension so far", "wait ...");
pBar.getProgressBar().auto();
Timer pBarTimer = new Timer(){
@Override
public void run() {
pBar.close();
}
};
pBarTimer.schedule(5000);
}

How it works...

For clarity we have segmented our code; the first segment shows how we make a listener, simply to show an info window stating which MessageBox button was clicked — not to cover the concept of events and listeners, but just to see how listeners can be created and attached to MessageBox objects.

It turns out that using a MessageBox object is very easy once you have made up your mind which one to use. To alert the user (of course with a non-obtrusive widget, unlike the standard browser alert dialog, which freezes the entire application), we simply call MessageBox.alert(), passing three parameters — a title, a message to be displayed, and a callback (listener), to handle the user's click action on the OK button. This automatically gets displayed with an alert icon:

We use MessageBox.confirm() to pop up a confirm dialog, also requiring a title, a message, and a listener callback, as parameters. At the end of the call, we get a confirm dialog (as in the next screenshot) posing a question (ideally in response to a user action), which the user can respond to with either the Yes or No buttons:

We also use MessageBox.prompt() to elicit input from the user (see the following screenshot). The call expects the three standard parameters — a title, a message, and a listener callback. The result of this call is a cool prompt dialog with a text field for a single line of text. Although we can allow multiline text entry, that would have required us to pass true as the third parameter, while our callback becomes the fourth parameter to the MessageBox.confirm() call.

The MessageBox class is really handy, especially because of its ease and convenience. The idea of having a fully functional confirm or prompt dialog, kitted with icons and event listener support, and with just one line of code is quite amazing, don't you think?