Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
E4/EAS/Eventing System
Components should be able to listen to any kind of events they may be interested in. It should be possible for this pattern to be extended without too much trouble or code for both the event publisher and the subscriber. This should help reduce code bloat and consequently make the code more readable and accessible to new developers.
Contents
Eclipse 3.x API
In Eclipse 3.x, there are a lot of listeners. IPerspectiveListener alone has four permutations, IPerspectiveListener, IPerspectiveListener2, IPerspectiveListener3, and IPerspectiveListener4, and it's quite possible that there will be many more down the road.
Listening for part activation events
workbenchPage.addPartListener(new IPartListener() { public void partActivated(IWorkbenchPart part) { // do something } /* Other code not shown here */ });
e4 (Java)
In e4, a new IEventBroker API has been introduced. See bug 288999 and the event processing wiki page for more information.
Listening for part activation events
IEventBroker eventBroker = (IEventBroker) eclipseContext.get( IEventBroker.class.getName()); eventBroker.subscribe(IUIEvents.ElementContainer.Topic, null, new EventHandler() { public void handleEvent(Event event) { if (event.getProperty(IUIEvents.EventTags.AttName) .equals(IUIEvents.ElementContainer.ActiveChild)) { Object newPart = event.getProperty(IUIEvents.EventTags.NewValue); if (newPart instanceof MPart) { // do something } } } }, /* headless */ false);