How to replace MouserListener in GWT 1.6

504 views
Skip to first unread message

Paul van Hoven

unread,
May 17, 2009, 1:00:39 PM5/17/09
to Google Web Toolkit
I imported an GWT 1.5 app for transforming it to a GWT 1.6 app. Every
listener is now marked as deprecated, so i'm currently replacing all
these. Anyway i do not know how to replace my MouseListener
implementations. Concretly speaking i use the folling implementations

public void onMouseEnter(Widget sender) {
//..do s.th. here
}

public void onMouseLeave(Widget sender) {
//..do s.th. here
}

that are demanded by the MouseListener interface. But i have not
figured out yet how to replace these with the new handler interfaces.
Does somebody know how to accomplish this?

Salvador Diaz

unread,
May 17, 2009, 2:03:42 PM5/17/09
to Google Web Toolkit

Mark Renouf

unread,
May 17, 2009, 9:05:24 PM5/17/09
to Google Web Toolkit
I've been doing this so much lately I've memorized the code. Using
eclipse you'll quickly get proficient at it I'm sure:

class Handlers implements HasMouseOverHandlers, HasMouseOutHandlers {
public void onMouseOver(MouseOverEvent e) {
}
public void onMouseOut(MouseOutEvent e) {
}
}

If you're implementing a new Widget:

class Foo extends Widget implements HasMouseOverHandlers,
HasMouseOutHandlers {
public HandlerRegistration addMouseOverHandler(MouseOverHandler
handler) {
return addDomHandler(handler, MouseOverHandler.getType());
}

public HandlerRegistration addMouseOutHandler(MouseOutHandler
handler) {
return addDomHandler(handler, MouseOutHandler.getType());
}
}

That's it! No more onBrowserEvent, no more sinkEvents. It's all
automatic. Sweet huh?
As for what to do with the HandlerRegistration, read the docs ;-)

Oh, on a related note/warning: I really think GWT should WARN if you
call addHandler with an event type that implements HasNativeEvent. If
you call addHandler instead of addDomHandler, nothing happens and no
events will ever be fired because the events don't get listeners
added. This has already bit me a couple times. Worth filing a bug for
this?


On May 17, 2:03 pm, Salvador Diaz <diaz.salva...@gmail.com> wrote:
> onMouseLeave:http://google-web-toolkit.googlecode.com/svn/javadoc/1.6/com/google/g...
>
> onMouseEnter (I don't know which so you'll have to try them out):http://google-web-toolkit.googlecode.com/svn/javadoc/1.6/com/google/g...
> orhttp://google-web-toolkit.googlecode.com/svn/javadoc/1.6/com/google/g...

Salvador Diaz

unread,
May 18, 2009, 3:36:16 AM5/18/09
to Google Web Toolkit
> This has already bit me a couple times. Worth filing a bug for
> this?

I don't think it's worth filing an issue just for this single
documentation "imprecision" (it is briefly mentioned in the the
"What's new" section of the developer documentation and the javadocs
do say that addDomHandler should be used for native browser events). I
do think however, that the coexistence of handlers and listeners in
the javadoc make it more difficult for the beginners to get a grip of
GWT event handling. I don't know what could be done to solve this
though, apart from recommending that beginners should be familiar with
dhtml and javascript basics.

Of course, that's just my opinion, What do other people think of this?

Cheers,

Salvador
Reply all
Reply to author
Forward
0 new messages