Hmm.. I looked at GWT's code, and went all the way upto
http://google-web-toolkit.googlecode.com/svn/javadoc/1.5/com/google/gwt/user/client/ui/FocusWidget.html
code.

Button is a sub-subclass of FocusWidget, and this is what happens.
Whenever a clickListener is added to a Button for the first time,
"Event.Click" event is sunk in for the newly instantiated Button
instance, and the clickListener added to ClickListenerCollection.
Next, whenever an onBrowserEvent(Event event) method is triggered, the
onClick() method is called for each of the clickListener registered in
ClickListenerCollection.

So, as far as managing a large number of ClickListeners goes, if we go
by using EButton, the number of ClickListeners is equal to the number
of anonymous abstract classes made out of EButton.

I think a more thinking point would be to consider "public void
sinkEvents(int eventBitsToAdd)" method of UIObject class, which
happens to be a superclass of FocusWidget. This method is called
whenever a ClickListener is added to an instance for the first time.
Thus, it does not matter whether the ClickListener interface being
added is the same reference as the anonymous abstract class of
Ebutton, or a central wrapper ClickListener (per component, as is
being talked about).

Thus, in a nutshell, if we create an anonyous abstract class of
EButton :

1. We ensure tight coupling, in the sense that the widget, and its
"action-on-click" are bound together.

2. Since we do not require any external ClickListener (remember that
EButton is a clickListener to itself), memory leak is not a problem;
whenever the anonymous instance goes out of scope, that is the end. In
other words, there is no chance of a dangling reference in the
"WrapperWidget"'s onClick method.

3. There is no extra overhead of maintaining any extra ClickListener
references, as the number of ClickListener references is equal to the
number of anonymous instances.


Your thoughts ..??


On Feb 2, 11:17 pm, gregor <greg.power...@googlemail.com> wrote:
> > This case requires one class ( anonymous extended EButton) creation.
>
> > Your thoughts ..??
>
> Yes, but you are not reducing the number of event listeners by doing
> this. Each button is now itself a separate click event listener. So I
> don't think this answers the warning given in the link about large
> numbers of event listeners. Also I doubt if there would be much
> material difference if any in the javascript generated between your
> EButton and a normal Button with an anonymous ClickListener, or none
> that would have any effect on performance anyway - you can always
> compile with -PRETTY and check.
--~--~---------~--~----~------------~-------~--~----~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to