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/Life Cycle

< E4‎ | EAS

Components (UI or non-UI) very often manage resources that need to be initialized when the component is instantiated, or disposed when the component itself is disposed. This is a long-winded way of saying that a container should call a method after a component is instantiated and ready to go, and call another method just before disposing the component.

Eclipse 3.x API

In Eclipse 3.x, there is the contract for construction and disposal is usually defined via abstract methods or interfaces. For workbench parts, there is the dispose() method and views have an init(IViewSite, IMemento) method whereas editors have an init(IEditorSite, IEditorInput) method.

Initialization

public void init(IViewSite site, IMemento memento) throws PartInitException {
  super.init(site, memento);
  // do other stuff
}
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
  setSite(site);
  setInput(input);
  // do other stuff
}

Disposal

public void dispose() {
  super.dispose();
  // do other stuff
}

e4 (Java)

Clients can use the @PostConstruct and @PreDestroy JSR-250 annotations to mark methods that should be called by the framework. Alternatively, if a component implements IDisposable, the framework will call the object's dispose() method implementation.

Initialization

@PostConstruct
private void partConstructed() {
  // do stuff
}

Disposal

@PreDestroy
private void partDestroyed() {
  // do stuff
}
import org.eclipse.e4.core.services.IDisposable;
 
public class MyView implements IDisposable {
 
  public void dispose() {
    // do stuff
  }
 
}

e4 (JavaScript)

Initialization is often handled by registering an "on load" handler from the script that is evaluated as part of instantiating the component. Not sure if "on unload" is widely used. It would make sense to list functions to call on load and unload in the component metadata.

Back to the top