Wednesday, June 30, 2010

Re: GWTEvent, sinking own events



On Wed, Jun 30, 2010 at 4:41 AM, Johan Rydberg <johan.rydberg@edgeware.tv> wrote:
On 6/30/10 11:57 AM, Roy wrote:If the answer is that View A *will* catch its own event, any

recommendations on how to identify the event in such a way that View A
knows it was the originator?
 
Maybe you can use this;

http://google-web-toolkit.googlecode.com/svn/javadoc/2.0/com/google/gwt/event/shared/GwtEvent.html#getSource()

If the event source isn't a widget, the result will be null.

Consider adding a parameter to the event that identifies the event source. For example:

eventBus.fireEvent(new MyEvent(MyIndentifier myIndentifier));

Perhaps MyIdentifier is an enum.

Then, in the event class:

public void MyEvent(MyIdentifier myIdentifier) {
this.myIdentifier = myIdentifier;
}

public MyIdentifier getMyIdentifier() {
return myIdentifier;
}

Then, in the event handler:

switch e.getMyIdentifier {
 case MYIDENTIFIER1: break;
 ....
}

Also, see the current thread subject "How to simplify your GwtEvent classes and have fun doing it!" for another implementation technique.

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

No comments:

Post a Comment