views:

408

answers:

1

Hi. I have a problem. I made a wrap widget that implements interface HasChangeHandlers

But i just can't fit events to each other.

public HandlerRegistration addChangeHandler( final ChangeHandler handler ) {
 HandlerRegistration registration1 = dateFrom.addValueChangeHandler( handler );// Compile error

 HandlerRegistration registration2 = dateTo.addValueChangeHandler( new ValueChangeHandler<Date>() {
  @Override
  public void onValueChange( ValueChangeEvent<Date> dateValueChangeEvent ) {
              //have to fire handler ??
  }
 } );

 return null; // what i should return here?
}

Thanks in advance !

+1  A: 

A ChangeHandler is not a ValueChangeHandler. You have to make another wrapper class which implements ValueChangeHandler and takes a ChangeHandler as an instance variable. You can then write...

HandlerRegistration registration1 = dateFrom.addValueChangeHandler(new ChangeHandlerWrapper(handler));

Where ChangeHandlerWrapper is a class that implements ValueChangeHandler. For example,

class ChangeHandlerWrapper<T> implements ValueChangeEvent<Date>
{
   private ChangeHandler handler;

   public void onValueChange( ValueChangeEvent<T> changeEvent) {
      handler.onChange(null);
   }
}

Of course, this assumes that you don't need the actual event in your handler. If you do then things will get more complicated.

Pace
ok. and what should be in onValueChange method ?
Konoplianko