Skip to content

Instantly share code, notes, and snippets.

@trung
Created March 18, 2011 01:12
Show Gist options
  • Save trung/875464 to your computer and use it in GitHub Desktop.
Save trung/875464 to your computer and use it in GitHub Desktop.
snippet shows how to remove handler registration within anonymous handler
// http://stackoverflow.com/questions/4715034/gwt-problem-with-handlerregistration/5275448#5275448
final Set<HandlerRegistration> hack = new HashSet<HandlerRegistration>();
((FocusWidget) sourceWidget).setFocus(true);
hack.add(((FocusWidget) sourceWidget).addBlurHandler(new BlurHandler() {
@Override
public void onBlur(BlurEvent event) {
ApplicationUtils.getTipsy().hide();
for (HandlerRegistration hr : hack) {
hr.removeHandler();
}
}
}));
hack.add(((FocusWidget) sourceWidget).addKeyPressHandler(new KeyPressHandler() {
@Override
public void onKeyPress(KeyPressEvent event) {
ApplicationUtils.getTipsy().hide();
for (HandlerRegistration hr : hack) {
hr.removeHandler();
}
}
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment