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:
- 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"); }
- Publishing is done with
@PostConstruct public void init(org.eclipse.fx.core.event.EventBus eventBus) { eventBus.publish( MY_TOPIC, "Hello World!", true ); }
- 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
Pingback: Why I think @UIEventTopic / @EventTopic have been a bad idea | Tomsondev Blog