On 15 mai, 01:43, rjcarr <[email protected]> wrote:
> I don't often fire off programmatic events but there are a couple
> cases where I need to and I can't figure out how to make it happen
> since I've been transition to 1.6.
>
> Before, as an example, I'd have something like this:
>
> class MyClass implements ClickListener {
> public MyClass() {
> Button b = new Button("", this);
> onClick(b); // programmatic click
> }
>
> public void onClick(Widget w) { ... }
>
> }
This is not what I call "fir[ing] off programmatic events", you're
just calling *one* ClickListener's onClick with some specific Button
as an argument.
> But now in 1.6 I'm not sure how to make this happen.
For someting as simple as simulating the click on a Button, you could
just do:
ButtonElement.as(b.getElement()).click();
> Looking at
> creating my own ClickEvent object the constructor, says this:
>
> "Protected constructor, use DomEvent.fireNativeEvent
> (com.google.gwt.dom.client.NativeEvent,
> com.google.gwt.event.shared.HasHandlers) to fire click events."
>
> But looking up that method I can't figure out what it is asking for.
> Could someone help me out with an example?
DomEvent.fireNativeEvent(Document.get().createClickEvent(...), b);
(and I don't why Alyxandor says fireNativeEvent is deprecated:
http://code.google.com/p/google-web-toolkit/source/browse/trunk/user/src/com/google/gwt/event/dom/client/DomEvent.java#89
)
> I searched through all the samples but nobody ever calls
> fireNativeEvent. Thanks!
In your case, you could eventually just call your ClickHandler's
onClick method with a ClickEvent subclass, overriding getSource() to
return your Button instance... (or just 'null' as the ClickEvent)
..or, probably better, refactor your code so that your logic isn't in
a ClickHandler but another interface/class that do not mandate passing
a DomEvent's subclass (such as ClickEvent) as an argument...
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---