Skip to main content

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.

Jump to: navigation, search

E4/EAS/Eventing System

< E4‎ | EAS
Revision as of 09:16, 26 October 2009 by Remysuen.ca.ibm.com (Talk | contribs) (New page: 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 eve...)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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.

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);

Back to the top