GWT removeHandler on first event notification

Posted by Keith on Stack Overflow See other posts from Stack Overflow or by Keith
Published on 2010-04-10T18:05:27Z Indexed on 2010/04/10 18:13 UTC
Read the original article Hit count: 297

Filed under:
|
|

I want to remove a GWT event handler the first time I receive an event. I also want to avoid polluting my class with tracking registration objects that aren't really necessary. I currently have it coded as:

final HandlerRegistration[] registrationRef = new HandlerRegistration[1];
registrationRef[0] = dialog.addFooHandler(new FooHandler()
{
    public void onFoo(FooEvent event)
    {
        HandlerRegistration removeMe = registrationRef[0];
        if(removeMe != null)
        {
            removeMe.removeHandler();
        }

        // do stuff here
    }
});

but the use of registrationRef makes the code less readable. Is there a better way to do this without adding variables to my class?

© Stack Overflow or respective owner

Related posts about gwt

Related posts about events