Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Eclipse4/RCP/FAQ
Contents
- 1 How do I adopt the Eclipse 4 Application Platform?
- 2 Why won't my application start?
- 3 Dependency Injection & Contexts
- 3.1 What services are available for injection?
- 3.2 How can I override a provided object?
- 3.3 How do I provide singleton objects?
- 3.4 Why am I getting a new instance of an object?
- 3.5 Why is my widget/part not displaying? Why am I getting a new Shell?
- 3.6 Why am I being injected with null?
- 3.7 What is the difference between IEclipseContext#set and IEclipseContext#modify?
- 4 UI
How do I adopt the Eclipse 4 Application Platform?
Accessing the status line |
|
Eclipse 3.x | Eclipse 4.0 |
getViewSite() .getActionsBars() .getStatusLineManager() .setMessage(msg); |
@Inject IStatusLineManager statusLine; ... statusLine.setMessage(msg); |
Associating help context with a control |
getSite() .getWorkbenchWindow() .getWorkbench() .getHelpSystem().setHelp( viewer.getControl(), some_id) |
@Inject IWorkbenchHelpSystem helpSystem; ... helpSystem.setHelp( viewer.getControl(), some_id); |
Handling errors and exceptions |
try { ... } catch (Exception ex) { IStatus status = new Status( IStatus.ERROR, "plugin-id", "Error while ...", ex); StatusManager.getManager() .handle(status, StatusManager.SHOW); } |
@Inject StatusReporter statusReporter; ... try{ ... } catch (Exception ex) { statusReporter.show("Error while ...", ex); } |
Accessing preference values |
IPreferenceStore store = IDEWorkbenchPlugin.getDefault() .getPreferenceStore(); boolean saveBeforeBuild = store .getBoolean(SAVE_BEFORE_BUILD); |
@Inject @Preference(SAVE_BEFORE_BUILD) boolean saveBeforeBuild; |
IPreferenceStore store = IDEWorkbenchPlugin.getDefault() .getPreferenceStore(); store.putBoolean(SAVE_BEFORE_BUILD, false); |
FIXME: there's way to do this... @Inject @Preference(SAVE_BEFORE_BUILD) Provider<Boolean> saveBeforeBuild; ... saveBeforeBuild.set(false); |
Why won't my application start?
E4AP products require having the following plugins:
- org.eclipse.equinox.ds (must be started)
- org.eclipse.equinox.event (must be started)
Note that org.eclipse.equinox.ds must be explicitly started. In your product file, you should have a section:
<configurations> <plugin id="org.eclipse.core.runtime" autoStart="true" startLevel="2" /> <plugin id="org.eclipse.equinox.ds" autoStart="true" startLevel="3" /> <plugin id="org.eclipse.equinox.event" autoStart="true" startLevel="3" /> </configurations>
Dependency Injection & Contexts
What services are available for injection?
See the list of provided services
How can I override a provided object?
FIXME For example, to provide an alternative StatusReporter or Logger
How do I provide singleton objects?
FIXME is there / do we support @Singleton?
Approach: use IContextFunctiin that checks and sets a value in top context
Why am I getting a new instance of an object?
The injector attempts to resolve objects in the context. If they are not found in the context, but the class exists, then the injector will instantiate and return a new instance providing that its injectable dependencies can be resolved.
Why is my widget/part not displaying? Why am I getting a new Shell?
The fix is to annotate the use with "@Named(ACTIVE_SHELL)".
Why am I being injected with null?
What is the difference between IEclipseContext#set and IEclipseContext#modify?
UI
How do I enable Drag N Drop (DND) of parts?
The DND addon is found in the org.eclipse.e4.ui.workbench.addons.swt plugin. However it requires the compatibility layer and is not available for native E4AP applications.