Well, for one, you could just style it like:
http://www.webappers.com/2007/06/18/simple-round-css-buttons-wii-buttons/ A
more generic approach would be to maintain state in your composite. You're
probably going to need click handlers for the style changes (assuming you
go with a more complicated example).
So something like:
class MyComposite extends Composite implements HasClickHandler {
class MyCompositeHandler implements ClickHandler {
void addDelegatedClickHandler(ClickHandler h) {
// add h to some set or list
}
void removeDelegatedClickHandler(ClickHandler h) {
}
public void onClick(ClickEvent evt) {
// handle MyComposite behaviour
for (ClickHandler delegated : toDelegate) {
delegated.onClick(evt);
}
}
}
MyCompositeHandler handler;
public MyComposite() {
// initialize foo to your composite
initWidget(foo);
handler = new MyCompositeHandler();
button.addClickHandler(handler);
}
public HandlerRegistration addClickHandler(ClickHandler h) {
handler.addDelegatedClickHandler(h);
// return registration with widget that you are adding too. maybe wrap
the result in a handler registration that also removes h from the handler
when it is unregistered.
}
Hope this gives you some ideas (I'm not saying this is the correct or best
way). Just one possible solution.
On Fri, Apr 24, 2009 at 2:39 AM, romant <[email protected]> wrote:
>
> Yes, setEnabled() is the thing which can do the job for a standard gwt
> button. But consider the situation when you want to implement your own
> button (with rounded corners let's say) named RButton. You implement
> it as a new widget which extends Composite class and implements
> ClickHandler interface to get mouse clicks, but here the method
> setEnabled() is not available. So how to implement the setEnabled()
> method in this case? Do you suggest to store the ClickHandler in the
> RButton class itself and remove it in its setEnabled() method, or is
> there any better way?
>
>
>
>
>
>
> On 24 Dub, 06:59, Vitali Lovich <[email protected]> wrote:
> > In general I think you should keep it with the class that does needs to
> > remove the handler. I hope you know about setEnabled/setDisabled -
> that's
> > the proper way to disable a buttons functionality, not to remove the
> > handler. In general, I have only encountered 1 situation where I would
> be
> > interested in removing a handler - more often than not, you will be
> > adding/removing the widget itself which should take care off removing the
> > handlers to free up memory.
> >
> >
> >
> > On Thu, Apr 23, 2009 at 10:50 AM, romant <[email protected]> wrote:
> >
> > > Hi guys,
> > > with GWT 1.6 there is the new handler-based approach for managing
> > > events.
> > > When I register, let's say, a button handler
> >
> > > HandlerRegistration buttonRegistration = button.addClickHandler(new
> > > ClickHandler() {...do something...});
> >
> > > I get an instance of HandlerRegistration. Then, if I want to remove
> > > the button's handler, let's say for a while just to make the button
> > > functionality temporarily unavailable, I just call
> >
> > > buttonRegistration.removeHandler();
> >
> > > But now the point is where to store the buttonHandler instance. With
> > > listeners it was easy, you just called button.removeClickListener()
> > > because the button kept the listener.
> >
> > > If I have a large project with many buttons what is the best approach
> > > for storing and handling the HandlerRegistration instances of my
> > > buttons and other widgets? Is there any recommended design pattern?
> > > This can make a real mess in my application if I do not find some
> > > general solution of this.
> >
> > > Thanks.
> > > Roman- Skrýt citovaný text -
> >
> > - Zobrazit citovaný text -
> >
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---