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.
Difference between revisions of "E4/EAS/Life Cycle"
(→e4 (Java)) |
|||
(6 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
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. | ||
− | == | + | ==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> | ||
− | ==JavaScript== | + | ===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 { | ||
+ | |||
+ | public void dispose() { | ||
+ | // do stuff | ||
+ | } | ||
+ | |||
+ | } | ||
+ | </source> | ||
+ | |||
+ | ==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.
Contents
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.