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

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


  public void testAddAndRemoveSourcedHandlers() {
    Object source1 = new Object();
    Object source2 = new Object();
   
    HandlerRegistration fooReg1 = eventBus.addHandlerToSource(FooEvent.TYPE, source1, fooHandler1);
    checkHandlerCount(1, FooEvent.TYPE);

    HandlerRegistration fooReg2 = eventBus.addHandlerToSource(FooEvent.TYPE, source2, fooHandler2);
    checkHandlerCount(2, FooEvent.TYPE);

    fooReg2.removeHandler();
    checkHandlerCount(1, FooEvent.TYPE);

    fooReg1.removeHandler();
    checkHandlerCount(0, FooEvent.TYPE);
  }
View Full Code Here


    });
  }

  public void testFetchsAfterCreateDontUpdate() {
    final int[] count = {0};
    final HandlerRegistration registration =
        EntityProxyChange.registerForProxyType(req.getEventBus(), SimpleFooProxy.class,
            new EntityProxyChange.Handler<SimpleFooProxy>() {
              @Override
              public void onProxyChange(EntityProxyChange<SimpleFooProxy> event) {
                count[0]++;
              }
            });
    delayTestFinish(TEST_DELAY);
    SimpleFooRequest context = req.simpleFooRequest();
    SimpleFooProxy proxy = context.create(SimpleFooProxy.class);
    context.persistAndReturnSelf().using(proxy).fire(new Receiver<SimpleFooProxy>() {
      @Override
      public void onSuccess(SimpleFooProxy response) {
        // Persist and Update events
        assertEquals(2, count[0]);
        req.find(response.stableId()).fire(new Receiver<SimpleFooProxy>() {
          @Override
          public void onSuccess(SimpleFooProxy response) {
            // No new events
            assertEquals(2, count[0]);
            registration.removeHandler();
            finishTestAndReset();
          }
        });
      }
    });
View Full Code Here

   * A second fetch for an unchanged object should not result in any update
   * event.
   */
  public void testMultipleFetchesDontUpdate() {
    final int[] count = {0};
    final HandlerRegistration registration =
        EntityProxyChange.registerForProxyType(req.getEventBus(), SimpleFooProxy.class,
            new EntityProxyChange.Handler<SimpleFooProxy>() {
              @Override
              public void onProxyChange(EntityProxyChange<SimpleFooProxy> event) {
                count[0]++;
              }
            });
    delayTestFinish(TEST_DELAY);
    req.simpleFooRequest().findSimpleFooById(999L).fire(new Receiver<SimpleFooProxy>() {
      @Override
      public void onSuccess(SimpleFooProxy response) {
        assertEquals(1, count[0]);

        final EntityProxyId<SimpleFooProxy> stableId = response.stableId();
        req.find(stableId).fire(new Receiver<SimpleFooProxy>() {

          @Override
          public void onSuccess(SimpleFooProxy returnedProxy) {
            assertEquals(1, count[0]);
            registration.removeHandler();
            finishTestAndReset();
          }
        });
      }
    });
View Full Code Here

  }

  public void testLinkTraversal() {
    final String testHistoryToken = TEST_HISTORY_TOKEN;
    Hyperlink link = new Hyperlink("foobar", testHistoryToken);
    HandlerRegistration registration = null;
    try {
      RootPanel.get().add(link);
      registration = History.addValueChangeHandler(new ValueChangeHandler<String>() {
        @Override
        public void onValueChange(ValueChangeEvent<String> event) {
          assertEquals(testHistoryToken, event.getValue());
          assertEquals(testHistoryToken, History.getToken());
        }
      });
      Document document = Document.get();
      NativeEvent event = document.createClickEvent(1, 0, 0, 0, 0, false, false, false, false);
      link.getElement().dispatchEvent(event);
    } finally {
      RootPanel.get().remove(link);
      if (registration != null) {
        registration.removeHandler();
      }
    }
  }
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

     * @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

        }
        slot = null;
    }

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

    @Test
    public void unbindingMultipleTimesRemoveHandlersOnlyOnce(
            HandlerContainerImpl handlerContainer) {
        // Given
        HandlerRegistration mockHandlerRegistration = mock(HandlerRegistration.class);
        handlerContainer.registerHandler(mockHandlerRegistration);

        // When
        handlerContainer.unbind();
        handlerContainer.bind();
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.