4

I'm trying to use Gin in MVP GWT 2.4. In my module, I have:

import com.google.web.bindery.event.shared.EventBus;
import com.google.web.bindery.event.shared.SimpleEventBus;

    @Override
      protected void configure() {
        bind(EventBus.class).to(SimpleEventBus.class).in(Singleton.class);
        ...
      }

The above code uses the new com.google.web.bindery.event.shared.EventBus. The problem comes when I want to inject the event bus in MVP Activities that implement Activity:

package com.google.gwt.activity.shared;

import com.google.gwt.event.shared.EventBus;
import com.google.gwt.user.client.ui.AcceptsOneWidget;

public interface Activity {

  ...

  void start(AcceptsOneWidget panel, EventBus eventBus);
}

Activity uses the deprecated com.google.gwt.event.shared.EventBus. How can I reconcile the two? Obviously, if I ask for the deprecated type of EventBus, then Gin will complain because I didn't specify a binding for it.

Update: This will allow the app to build, but now there are two different EventBuss, which is awful:

 protected void configure() {
    bind(com.google.gwt.event.shared.EventBus.class).to(
        com.google.gwt.event.shared.SimpleEventBus.class).in(Singleton.class);
    bind(EventBus.class).to(SimpleEventBus.class).in(Singleton.class);
    ...
Nick Heiner
  • 119,074
  • 188
  • 476
  • 699

4 Answers4

2

There is a current issue logged for this: http://code.google.com/p/google-web-toolkit/issues/detail?id=6653

Suggested work around is unfortunately to just stick with the deprecated EventBus in your code for now.

Strelok
  • 50,229
  • 9
  • 102
  • 115
2

I asked a similar question: Which GWT EventBus should I use?

You don't need the deprecated event bus, since it extends the WebBindery one.

Create a base Activity that your activities all extend with this code:

// Forward to the web.bindery EventBus instead
@Override
@Deprecated
public void start(AcceptsOneWidget panel, com.google.gwt.event.shared.EventBus eventBus) {
   start(panel, (EventBus)eventBus);
}

public abstract void start(AcceptsOneWidget panel, EventBus eventBus);
Community
  • 1
  • 1
checketts
  • 14,167
  • 10
  • 53
  • 82
1

I think a cleaner solution is this:

public class GinClientModule extends AbstractGinModule {

    @Override
    protected void configure() {
        bind(EventBus.class).to(SimpleEventBus.class).in(Singleton.class);
        ...
    }

    @Provides
    @Singleton
    public com.google.gwt.event.shared.EventBus adjustEventBus(
            EventBus busBindery) {
        return (com.google.gwt.event.shared.EventBus) busBindery;
    }

...

Please refer to my answer here

Community
  • 1
  • 1
Christian Achilli
  • 5,547
  • 2
  • 25
  • 24
0

I have found that binding both the new and old versions to the same instance helps.

    /*
     * bind both versions of EventBus to the same single instance of the
     * SimpleEventBus
     */
    bind(SimpleEventBus.class).in(Singleton.class);
    bind(EventBus.class).to(SimpleEventBus.class);
    bind(com.google.gwt.event.shared.EventBus.class).to(SimpleEventBus.class);

Now whenever your code needs an EventBus inject the one that the code requires and avoid the deprecation warnings.

pillingworth
  • 3,238
  • 2
  • 24
  • 49