e(fx)clipse 2.2.0 – Typesafe EventBus


With e(fx)clipse we ship as part of our core-bundle (the one able to run in any OSGi and Plain-Java-Env) since 2.1 an org.eclipse.fx.core.event.EventBus which we enhanced in 2.2.0 to provide a certain level of typesafety.

Useage is straight forward:

  1. Define a Topic-Instance
    public class Constants {
      public static final org.eclipse.fx.core.event.Topic<String> MY_TOPIC 
        = new org.eclipse.fx.core.event.Topic<>("my/sample/Topic");
    }
    
  2. Publishing is done with
    @PostConstruct
    public void init(org.eclipse.fx.core.event.EventBus eventBus) {
      eventBus.publish( MY_TOPIC, "Hello World!", true );
    }
    
  3. Subscribing to events
    import static my.sample.Constants.MY_TOPIC;
    import static org.eclipse.fx.core.event.EventBus.data;
    
    @PostConstruct
    public void init(org.eclipse.fx.core.event.EventBus eventBus) {
      eventBus.subscribe( MY_TOPIC, data(this::handleTopic) );
    }
    
    private void handleTopic(String data) {
      // ...
    }
    

If you are interested in other new features of 2.2.0 look at this overview page

This entry was posted in e(fx)clipse. Bookmark the permalink.

1 Response to e(fx)clipse 2.2.0 – Typesafe EventBus

  1. Pingback: Why I think @UIEventTopic / @EventTopic have been a bad idea | Tomsondev Blog

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.