Get widget variable name from event?

18 views
Skip to first unread message

membersound

unread,
Dec 28, 2012, 6:38:17 AM12/28/12
to google-we...@googlegroups.com
Hi,

is it possible to retrieve the name of an element that triggers an event?
For example, if I have a FocusPanel which triggers a MouseOverEvent, can I get the variable name of that panel somehow from the event?


@UiField
FocusPanel panel;

@UiHandler("panel")
void mouseOver(MouseOverEvent ev) {
    Window.alert("you clicked the element named 'panel'"); //how could I use the 'ev' to get the name 'panel'?
}

Jens

unread,
Dec 28, 2012, 7:33:23 AM12/28/12
to google-we...@googlegroups.com
No you can't.

All you can do is

Object source = event.getSource();
if(source == panel) {
  //event fired by specific panel
}

But this only makes sense if you have multiple event sources for a single method, e.g.

@UiHandler({"panel1", "panel2"})
void onMouseOver(MouseOverEvent event) {
  //dispatch event source here.
}

The above code is pretty much the same as

MouseOverHandler handler = new MouseOverHandler() { //implement... }
panel1.addMouseOverHandler(handler);
panel2.addMouseOverHandler(handler);

-- J.
Reply all
Reply to author
Forward
0 new messages