com.google.web.bindery.event.shared.binder.EventHandler Java Examples

The following examples show how to use com.google.web.bindery.event.shared.binder.EventHandler. 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: HelloWorldViewEventHandler.java    From gwt-boot-samples with Apache License 2.0 5 votes vote down vote up
@EventHandler
void onChangeViewed(ChangeViewEvent event) {
	logger.info("ChangeViewEvent triggered: " + event.getWidgetName() + " - Source: " + event.getSource());
	Notify.notify("ChangeViewEvent triggered: " + event.getWidgetName() + " - Source: " + event.getSource());

	filterPerson(event.getWidgetName());

	// https://demo-gwt-springboot.herokuapp.com/demogwt/v1/personsFilter?nameSuggestBox=test
	Notify.notify("REST API called: v1/personsFilter.");
}
 
Example #2
Source File: EventBinderWriter.java    From gwteventbinder with Apache License 2.0 5 votes vote down vote up
void writeDoBindEventHandlers(JClassType target, SourceWriter writer, TypeOracle typeOracle)
    throws UnableToCompleteException {
  writeBindMethodHeader(writer, target.getQualifiedSourceName());
  for (JMethod method : target.getInheritableMethods()) {
    EventHandler annotation = method.getAnnotation(EventHandler.class);
    if (annotation != null) {
      writeHandlerForBindMethod(annotation, writer, method, typeOracle);
    }
  }
  writeBindMethodFooter(writer);
}
 
Example #3
Source File: EventBinderWriterTest.java    From gwteventbinder with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private JMethod newMethod(String name, JType[] params, Class[] events) {
  EventHandler eventHandler = mock(EventHandler.class);
  when(eventHandler.handles()).thenReturn(events);

  JMethod method = mock(JMethod.class);
  when(method.getAnnotation(EventHandler.class)).thenReturn(eventHandler);
  when(method.getName()).thenReturn(name);
  when(method.getParameterTypes()).thenReturn(params);
  return method;
}
 
Example #4
Source File: ContactsPresenter.java    From gwteventbinder with Apache License 2.0 5 votes vote down vote up
@EventHandler
void onContactsLoaded(ContactsLoadedEvent event) {
  view.clear();
  for (String contactName : event.getContactNames()) {
    view.add(new Label(contactName));
  }
}
 
Example #5
Source File: ServerProxy.java    From gwteventbinder with Apache License 2.0 5 votes vote down vote up
@EventHandler
void onContactsScreenOpened(ContactScreenOpenedEvent event) {
  // Pretend to make a server request
  Scheduler.get().scheduleFixedDelay(new RepeatingCommand() {
    @Override
    public boolean execute() {
      LinkedList<String> results = new LinkedList<String>();
      results.add("John Doe");
      results.add("Jane Doe");
      eventBus.fireEvent(new ContactsLoadedEvent(results));
      return false;
    }
  }, 1000);
}
 
Example #6
Source File: PersonUtil.java    From demo-gwt-springboot with Apache License 2.0 4 votes vote down vote up
@EventHandler
public void onEvent(FilterEvent event) {
	logger.info("Get Event: " + event);
	Bootbox.alert("FilterEvent is received in PersonUtil...");
}
 
Example #7
Source File: PersonUtil.java    From demo-gwt-springboot with Apache License 2.0 4 votes vote down vote up
@EventHandler
public void onEvent(SearchEvent event) {
	logger.info("Get Event: " + event);
	Bootbox.alert("SearchEvent is received in PersonUtil...");
}
 
Example #8
Source File: MainPanelView.java    From demo-gwt-springboot with Apache License 2.0 4 votes vote down vote up
@EventHandler
void onChangeViewed(ChangeViewEvent event) {
	logger.info("ChangeViewEvent triggered: " + event.getWidgetName()
			+ " - Source: " + event.getSource());
	showAndStartWidget(event.getWidgetName());
}
 
Example #9
Source File: PersonPanelView.java    From demo-gwt-springboot with Apache License 2.0 4 votes vote down vote up
@EventHandler
public void onEvent(FilterEvent event) {
	logger.info("Get Event:" + event);
	Bootbox.alert("FilterEvent is received in PersonPanelView...");
}
 
Example #10
Source File: NotificationPanel.java    From bitcoin-transaction-explorer with MIT License 4 votes vote down vote up
@EventHandler
public void onNotification(final NotificationEvent event) {
  add(new NotificationWidget(event.getValue()));
}
 
Example #11
Source File: EventBinderWriter.java    From gwteventbinder with Apache License 2.0 4 votes vote down vote up
private void writeHandlerForBindMethod(EventHandler annotation, SourceWriter writer,
    JMethod method, TypeOracle typeOracle) throws UnableToCompleteException {
  JClassType eventParameter = null;
  if (method.getParameterTypes().length == 1) {
    eventParameter = method.getParameterTypes()[0].isClassOrInterface();
  }
  if (annotation.handles().length == 0 && !isAConcreteGenericEvent(eventParameter)) {
    logger.log(Type.ERROR, "Method " + method.getName()
        + " annotated with @EventHandler without event classes must have exactly "
        + "one argument of a concrete type assignable to GenericEvent");
    throw new UnableToCompleteException();
  }

  List<String> eventTypes = new ArrayList<String>();
  if (annotation.handles().length != 0) {
    for (Class<? extends GenericEvent> event : annotation.handles()) {
      String eventTypeName = event.getCanonicalName();
      JClassType eventClassType = typeOracle.findType(eventTypeName);
      if (eventClassType == null) {
        logger.log(Type.ERROR, "Can't resolve " + eventTypeName);
        throw new UnableToCompleteException();
      }
      if (eventParameter != null && !eventClassType.isAssignableTo(eventParameter)) {
        logger.log(Type.ERROR, "Event " + eventTypeName + " isn't assignable to "
            + eventParameter.getName() + " in method: " + method.getName());
        throw new UnableToCompleteException();
      }
      eventTypes.add(eventClassType.getQualifiedSourceName());
    }
  } else {
    eventTypes.add(eventParameter.getQualifiedSourceName());
  }

  for (String eventType : eventTypes) {
    writer.println("bind(eventBus, registrations, %s.class, new GenericEventHandler() {",
        eventType);
    if (eventParameter != null) {
      writer.indentln("public void handleEvent(GenericEvent event) { target.%s((%s) event); }",
          method.getName(), eventType);
    } else {
      writer.indentln("public void handleEvent(GenericEvent event) { target.%s(); }", 
          method.getName());
    }
    writer.println("});");
  }
}
 
Example #12
Source File: ContactsPresenter.java    From gwteventbinder with Apache License 2.0 4 votes vote down vote up
@EventHandler
void onContactsScreenOpened(ContactScreenOpenedEvent event) {
  view.clear();
  view.add(new Label("Please wait..."));
}