TEA provides a bridge from its own TaskingLifeCycleListener mechanism to the E41 event bus mechanism. This allows for some advanced integration in a more Eclipse-ish fashion. Actually, the Tasking Live View is implemented based on this mechanism. It is a plain E4 view part that requests TEA events from the Eclipse event bus.
The Event Bridge
The bridge is implemented in org.eclipse.tea.core.ui.internal.listeners.EventBrokerBridge. It is quite straightforward since it broadcasts an event for every TaskingLifeCycleListener method possible to the Eclipse IEventBroker. TEA uses the org/eclipse/tea/* topic namespace for this.
Note
You can spy on these events using Eclipse’s E4 tools, which can be found in the marketplace.2 Figure 11-1 shows an example of this. Once installed (in the TEA workspace, not the runtime workspace), the event spy can be accessed from (in the runtime workspace, when using the TEA-Book-Samples launch configuration) Window ➤ Spies ➤ Event Spy.
Subscribing to and Processing TEA Events
In a typical E4 application (or Eclipse plug-in), you will likely implement E4 objects that can use DI to obtain the IEventBroker for the application. In this example, we’re using an OSGi service that is activated on plug-in activation (due to the immediate attribute). Right there in the @Activate method (another OSGi declarative service annotation), we subscribe to all TEA events (providing the service itself as event handler).
The handleEvent method is now called for every event that matches the filter given to the IEventBroker when calling the subscribe method . We briefly check whether the Event instance looks like we expect it. Then we create a child context of the associated context. (This is the current IEclipseContext in use by TEA. Depending on the event, this can be either of the previously described IEclipseContext levels in the context stack used by TEA.) We need this context to be able to add things to it without interfering with TEA itself. Now we can stuff the current Event instance in the child context and use E4’s DI mechanism to invoke the process method by telling the framework to invoke a method annotated with @Execute on this.
This trick allows us to get back to TEA’s dependency injection mechanism because we’re using the actual context (as parent of our child context). This will allow us to inject whatever is injectable with TEA as well as the current Event instance (as we added that to the context).
With the conclusion of this chapter, we have covered all technical concepts of TEA core (and core UI) as seen in Figure 3-2 back in Chapter 3. We’ll now move on to the TEA library, which contains TEA component implementations for advanced use cases.