Java Code Examples for com.google.web.bindery.event.shared.HandlerRegistration#removeHandler()

The following examples show how to use com.google.web.bindery.event.shared.HandlerRegistration#removeHandler() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GroupValidator.java    From gwt-material with Apache License 2.0 5 votes vote down vote up
/**
 * Removes a field from the validation group.
 *
 * @param <T>   the generic type
 * @param field the field
 * @return true, if successful
 */
public <T extends Widget & HasValidators<?>> boolean remove(final T field) {
    fields.remove(field);
    HandlerRegistration reg = registrations.remove(field);
    if (reg != null) {
        reg.removeHandler();
        return true;
    }
    return false;
}
 
Example 2
Source File: HandlerRegistrationCollection.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void removeHandler() {
	for (HandlerRegistration handler : this.handlers) {
		handler.removeHandler();
	}
	this.handlers.clear();
}
 
Example 3
Source File: SerdesManagerImpl.java    From requestor with Apache License 2.0 5 votes vote down vote up
/**
 * Register a serializer/deserializer of the given type.
 *
 * @param serdes    The serializer/deserializer of T.
 * @param <T>       The type of the object to be serialized/deserialized.
 *
 * @return  The {@link HandlerRegistration} object, capable of cancelling this HandlerRegistration
 *          to the {@link SerdesManagerImpl}.
 */
public <T> HandlerRegistration register(Serdes<T> serdes) {
    final HandlerRegistration desReg = register((Deserializer<T>) serdes);
    final HandlerRegistration serReg = register((Serializer<T>) serdes);

    return new HandlerRegistration() {
        @Override
        public void removeHandler() {
            desReg.removeHandler();
            serReg.removeHandler();
        }
    };
}
 
Example 4
Source File: AbstractEventBinder.java    From gwteventbinder with Apache License 2.0 5 votes vote down vote up
@Override
public final HandlerRegistration bindEventHandlers(T target, EventBus eventBus) {
  final List<HandlerRegistration> registrations = doBindEventHandlers(target, eventBus);
  return new HandlerRegistration() {
    @Override
    public void removeHandler() {
      for (HandlerRegistration registration : registrations) {
        registration.removeHandler();
      }
      registrations.clear();
    }
  };
}
 
Example 5
Source File: EventBinderTest.java    From gwteventbinder with Apache License 2.0 5 votes vote down vote up
public void testEventBinder_unbindEventHandlers() {
  EventBus eventBus = new SimpleEventBus();
  TestPresenter presenter = new TestPresenter();
  TestPresenter.MyEventBinder binder = GWT.create(TestPresenter.MyEventBinder.class);
  HandlerRegistration registration = binder.bindEventHandlers(presenter, eventBus);
  assertEquals(0, presenter.firstEventsHandled);
  assertEquals(0, presenter.firstEventsWithoutParameterHandled);
  assertEquals(0, presenter.secondEventsHandled);

  // Before unregistering
  eventBus.fireEvent(new FirstEvent());
  eventBus.fireEvent(new SecondEvent());
  assertEquals(1, presenter.firstEventsHandled);
  assertEquals(1, presenter.firstEventsWithoutParameterHandled);
  assertEquals(1, presenter.secondEventsHandled);
  assertEquals(2, presenter.firstAndSecondEventsHandled);

  // After unregistering
  registration.removeHandler();
  eventBus.fireEvent(new FirstEvent());
  eventBus.fireEvent(new SecondEvent());
  assertEquals(1, presenter.firstEventsHandled);
  assertEquals(1, presenter.firstEventsWithoutParameterHandled);
  assertEquals(1, presenter.secondEventsHandled);
  assertEquals(2, presenter.firstAndSecondEventsHandled);

  // After re-registering
  binder.bindEventHandlers(presenter, eventBus);
  eventBus.fireEvent(new FirstEvent());
  eventBus.fireEvent(new SecondEvent());
  assertEquals(2, presenter.firstEventsHandled);
  assertEquals(2, presenter.firstEventsWithoutParameterHandled);
  assertEquals(2, presenter.secondEventsHandled);
  assertEquals(4, presenter.firstAndSecondEventsHandled);
}
 
Example 6
Source File: Html5ApplicationCache.java    From gwt-appcache with Apache License 2.0 5 votes vote down vote up
private void cacheRemovalCleanup( final ArrayList<HandlerRegistration> registrations )
{
  for ( final HandlerRegistration registration : registrations )
  {
    registration.removeHandler();
  }
  enableAppCache();
}
 
Example 7
Source File: CircuitPresenter.java    From core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected void onUnbind() {
    super.onUnbind();
    for (HandlerRegistration registration : registrations) {
        registration.removeHandler();
    }
}