Package com.google.web.bindery.event.shared

Examples of com.google.web.bindery.event.shared.HandlerRegistration


public abstract class AbstractEventBinder<T> implements EventBinder<T> {

  @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();
        }
View Full Code Here


  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);
View Full Code Here

  public HandlerRegistration register(PlaceController placeController, EventBus eventBus, Place defaultPlace) {
    this.placeController = placeController;
    this.eventBus = eventBus;
    this.defaultPlace = defaultPlace;

    final HandlerRegistration bind = bind();

    final HandlerRegistration handlerRegistration = historyObserver.bind(eventBus, defaultHistoryHandler);

    return new HandlerRegistration() {
      public void removeHandler() {

        bind.removeHandler();
        handlerRegistration.removeHandler();
      }
    };
  }
View Full Code Here

    };
  }

  protected HandlerRegistration bind() {

    final HandlerRegistration popHandler = historian.addPopStateHandler(new PopStateHandler() {

      @Override
      public void onPopStateEvent(PopStateEvent event) {
        onPopStateEventOccured(event.getData());
      }
    });

    final HandlerRegistration placeChangeHandler = eventBus.addHandler(PlaceChangeEvent.TYPE, new PlaceChangeEvent.Handler() {

      @Override
      public void onPlaceChange(PlaceChangeEvent event) {
        onPlaceChangeEvent(event);

      }
    });

    return new HandlerRegistration() {
      public void removeHandler() {
        MGWTPlaceHistoryHandler.this.defaultPlace = Place.NOWHERE;
        MGWTPlaceHistoryHandler.this.placeController = null;
        popHandler.removeHandler();
        placeChangeHandler.removeHandler();
      }
    };

  }
View Full Code Here

            popupChildren.remove(i);
        }
    }

    private void registerVisibleHandler(HandlerInformation<EventHandler> handlerInformation) {
        HandlerRegistration handlerRegistration = addHandler(handlerInformation.type, handlerInformation.eventHandler);
        visibleHandlerRegistrations.add(handlerRegistration);
    }
View Full Code Here

     * @param type    The event type
     * @param handler The handler to register.
     * @param <H>     The handler type
     */
    protected <H> void addRegisteredHandler(GwtEvent.Type<H> type, H handler) {
        HandlerRegistration registration = eventBus.addHandler(type, handler);
        handlerContainer.registerHandler(registration);
    }
View Full Code Here

    this.wrapped = wrapped;
  }

  @Override
  public <H> HandlerRegistration addHandler(Type<H> type, H handler) {
    final HandlerRegistration superReg = wrapped.addHandler(type, handler);
    handlerCounts.increment(type);
    return makeReg(type, superReg);
  }
View Full Code Here

    return makeReg(type, superReg);
  }

  @Override
  public <H> HandlerRegistration addHandlerToSource(final Type<H> type, Object source, H handler) {
    final HandlerRegistration superReg = wrapped.addHandlerToSource(type, source, handler);
    handlerCounts.increment(type);
    return makeReg(type, superReg);
  }
View Full Code Here

  public int getHandlerCount(Type<?> type) {
    return handlerCounts.getCount(type);
  }

  private <H> HandlerRegistration makeReg(final Type<H> type, final HandlerRegistration superReg) {
    return new HandlerRegistration() {
      public void removeHandler() {
        handlerCounts.decrement(type);
        superReg.removeHandler();
      }
    };
View Full Code Here

    super.setUp();
    eventBus = new CountingEventBus(new SimpleEventBus());
  }

  public void testAddAndRemoveMultipleHandlers() {
    HandlerRegistration fooReg = eventBus.addHandler(FooEvent.TYPE, fooHandler1);
    checkHandlerCount(1, FooEvent.TYPE);

    HandlerRegistration barReg1 = eventBus.addHandler(BarEvent.TYPE, barHandler1);
    HandlerRegistration barReg2 = eventBus.addHandler(BarEvent.TYPE, barHandler2);
    checkHandlerCount(2, BarEvent.TYPE);

    fooReg.removeHandler();
    checkHandlerCount(0, FooEvent.TYPE);

    barReg2.removeHandler();
    checkHandlerCount(1, BarEvent.TYPE);

    barReg1.removeHandler();
    checkHandlerCount(0, BarEvent.TYPE);
  }
View Full Code Here

TOP

Related Classes of com.google.web.bindery.event.shared.HandlerRegistration

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.