GWT - How to show the wait cursor for long tasks
For this reason we have wrote 2 static functions to set the cursor to wait and then to put it back when the long task is over.
public static void showWaitCursor() { DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "wait"); } public static void showDefaultCursor() { DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "default"); }
Here are the possible types of the HTML cursors, which can be used in different cases:
Example of how to use the functions to change HTML cursor for long task:
/**
* create the long task instance, which in our case extends:
* interface Function { execute(); }
*/
final Task longTask = new Task();
/** shows the wait cursor */
showWaitCursor();
/** launch the long task in a separate thread */
DeferredCommand.addCommand (new Command() {
@Override
public void execute () {
try {
longTask.execute();
} finally {
/* when task finishes (successful, or with failure) set back the default cursor */
showDefaultCursor();
}
}
});
That's pretty much all.
Cheers!
0 comments:
Post a Comment