On 1 avr, 09:28, magbyr <[email protected]> wrote:
> Hello.
>
> I'm having some trouble understanding the new event handlers.
> When creating a composite A containing widgets B and C, I want
> different events from B and C to create a ValueChangeEvent on A. This
> way other widgets using A can handle one event instead of two.
>
> A - ValueChangeHandler
> B - KeyUpHandler
> C - ChangeHandler
>
> What's the best way to do this?

I haven't yet used the new event system, so I might be wrong, but
here's my attempt:

> class A extends Composite implements HasValueChangeHandlers<String> {
>    private Panel container;
>    private TextBox B;
>    private ListBox C;
>
>    A() {
>       B.addKeyUpHandler(

new KeyUpHandler() {
   public void onKeyUp(KeyUpEvent event) {
      fireValueChanged();
   }
}

>       );
>       C.addChangeHandler(

new ChangeHandler() {
   public void onChange(ChangeEvent event) {
      fireValueChanged();
   }
}

>       );
>       container.add(B);
>       container.add(C);
>       initWidget(container);
>    }
>
>    public HandlerRegistration addValueChangeHandler
> (ValueChangeHandler<String> handler) {

    return addHandler(handler, ValueChangeEvent.getType());

>    }


private void fireValueChanged() {
   ValueChangeEvent.fire(this, <your value here>);
}

> }
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to