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

Difference between revisions of "E4/EAS/Life Cycle"

< E4‎ | EAS
(Eclipse 3.x API)
Line 2: Line 2:
  
 
==Eclipse 3.x API==
 
==Eclipse 3.x API==
In Eclipse 3.x, there is the contract for construction and disposal is usually defined via abstract methods or interfaces.
+
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===
 +
<source lang="java">
 +
public void init(IViewSite site, IMemento memento) throws PartInitException {
 +
  super.init(site, memento);
 +
  // do other stuff
 +
}
 +
</source>
 +
 
 +
<source lang="java">
 +
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
 +
  setSite(site);
 +
  setInput(input);
 +
  // do other stuff
 +
}
 +
</source>
 +
 
 +
===Disposal===
 +
<source lang="java">
 +
public void dispose() {
 +
  super.dispose();
 +
  // do other stuff
 +
}
 +
</source>
  
 
==e4 (Java)==
 
==e4 (Java)==

Revision as of 13:45, 26 October 2009

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)

Use JSR-250 annotations @PostConstruct and @PreDestroy to mark methods that should be called by the framework.

Alternatively, if a component implements IDisposable, the framework should call IDisposable.dispose().

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