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
(New page: =Life Cycle= 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 ...)
 
(e4 (Java))
 
(7 intermediate revisions by 2 users not shown)
Line 1: Line 1:
=Life Cycle=
 
 
 
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.
 
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.
  
==Java==
+
==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===
 +
<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)==
 +
Clients can use the @PostConstruct and @PreDestroy [http://jcp.org/en/jsr/detail?id=250 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===
 +
<source lang="java">
 +
@PostConstruct
 +
private void partConstructed() {
 +
  // do stuff
 +
}
 +
</source>
 +
 
 +
===Disposal===
 +
<source lang="java">
 +
@PreDestroy
 +
private void partDestroyed() {
 +
  // do stuff
 +
}
 +
</source>
 +
 
 +
<source lang="java">
 +
import org.eclipse.e4.core.services.IDisposable;
 +
 
 +
public class MyView implements IDisposable {
  
Use JSR-250 annotations @PostConstruct and @PreDestroy to mark methods that should be called by the framework.
+
  public void dispose() {
 +
    // do stuff
 +
  }
  
Alternatively, if a component implements IDisposable, the framework should call IDisposable.dispose().
+
}
 +
</source>
  
==JavaScript==
+
==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.
 
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.

Latest revision as of 14:19, 29 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)

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