0

GWT - How to show the wait cursor for long tasks




  Source : http://ui-programming.blogspot.com/2010/01/gwt-how-to-show-wait-cursor-for-long.html

GWT - How to show the wait cursor for long tasks

In case you have a task that takes more than 2 seconds you need to signal to the user that he needs to wait a little longer than usual. This can be done in many ways, here, we are talking about the setting the cursor to a WAIT cursor.

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

Using GWT Event Bus

Simple tutorial on GWT Event Bus.
Tested and it works.

Source : http://stackoverflow.com/questions/6030202/how-to-use-the-gwt-eventbus

When you divide the project into logical parts (for example with MVP) than several different parts sometime need to communicate. Typical communication is sending some status changes, e.g.:
  • user logged-in / loged-out.
  • user navigated directly via URL to page so menu needs to be updated.
Event bus is quite logical to use in this cases.
To use it you instantiate one EventBus per app which is then used by all other classes. To achieve this you use static field, factory or dependency injection (GIN in case of GWT).
Example with you own event types:
 
public class AppUtils{

    public static EventBus EVENT_BUS = GWT.create(SimpleEventBus.class);
}
 
Normally you'd also create your own event types and handlers:
 
public class AuthenticationEvent extends GwtEvent<AuthenticationEventHandler> {
public static Type<AuthenticationEventHandler> TYPE = new Type<AuthenticationEventHandler>();

  @Override
public Type<AuthenticationEventHandler> getAssociatedType() {
    return TYPE;
}
@Override
protected void dispatch(AuthenticationEventHandler handler) {
    handler.onAuthenticationChanged(this);
}
}

and the handler:
 
public interface AuthenticationEventHandler extends EventHandler {
    void onAuthenticationChanged(AuthenticationEvent authenticationEvent);
}

Then you use it like this:

AppUtils.EVENT_BUS.addHandler(AuthenticationEvent.TYPE, new AuthenticationEventHandler()     {
        @Override
        public void onAuthenticationChanged(AuthenticationEvent authenticationEvent) {
            // authentication changed - do something
        }
    });

and fire the event:

AppUtils.EVENT_BUS.fireEvent(new AuthenticationEvent());


0

Choosing the Logger iButton That's Right for You

Article from Maxim. Also for my reference.

http://www.maxim-ic.com/app-notes/index.mvp/id/5405
0

LFRD003: Water Meter Automatic Meter Reading (AMR) Reference Design

 This is for my reference.An article from Maxim.
 
http://www.maxim-ic.com/app-notes/index.mvp/id/5404
 
Copyright © peyotest