ResourceTreeAndListGroup in eclipse 4 - eclipse-rcp

I have a 3.x RCP that I am now moving to E4 using the compatibility layer.
I am now having an issue trying to use ResourceTreeAndListGroup.getListTable() which has been removed.
I would go for using Reflection to access the listViewer. I was though wondering what is the E4 way of doing it?

A 'pure' e4 RCP only uses the plugins in the org.eclipse.e4.rcp feature (and the EMF features that requires). This feature does not include the org.eclipse.core.resources plugin so you can't use IResource etc. Consequently there is no equivalent to ResourceTreeAndListGroup.
An e4 RCP might use the SWT FileDialog and DirectoryDialog dialogs for file access, or use the jFace TreeViewer and the Java file APIs to build its own dialog.

Related

Making org.eclipse.e4.ui.workbench.swt.E4Application work with org.eclipse.ui.IStartup

I am quite new to the RCP world and need some help.
I want to have E4Application work with IStartup. According to the documentation, I should use the "LifeCycleHandler" approach as in these 2 links.
How to make something on startup in Eclipse E4 application?
and
Eclipse e4 : IStartup extension not working
But I can't use them as I don't want to make code changes to my plugin. So I also went through the link below which talks about "Use the Compatibility Layer" but I could not really understand much. I would be great to have a solution to this since I can't modify the plugin code(may be by putting some plugin in the plugins dir etc).
My RCP is eclipse 4.6.2 based.
Observation: Eclipse 4.6.2 IDE is able to load my plugin but with version 4.6.2 based RCP, its not loading.
TIA
A pure e4 RCP using E4Application cannot use IStartup or any of the other org.eclipse.ui.xxxx extension points and classes. You will have to use the Life Cycle class and rewrite your code.
If you want to use org.eclipse.ui.xxx classes and extension point stick to the traditional Eclipse RCP (which uses 3.x compatibility mode).

Eclipse E4 open Java Editor Programmatically

I would like to know if there is a pure Eclipse E4 way to open programmatically a java editor.
I am migrating my plug-in from Eclipse 3.x to Eclipse E4, and I need to transform the following Eclipse 3.x call into an Eclipse E4 call.
final IWorkbenchPage page = Activator.getActiveEditor().getSite().getPage();
IDE.openEditor(page, (IFile) myResource);
After search and analysis seem there is not an Eclipse E4 equivalent for this call. Is this possible?
This isn't possible in a pure e4 application.
The Java editor is a 3.x compatibility mode component and won't run in an e4 application. The editor depends on many org.eclipse.ui.xxx plugins and things like IFile none of which are available in a plain e4 RCP.
If you still have the compatibility layer around (which I assume must be the case, as JDT requires it), you should be able to execute the org.eclipse.ui.navigate.openResource command with a filePath parameter pointing to your resource. Alas, this command doesn’t give you the guarantee that the Java editor opens – it may just open a plain text editor. But perhaps that’s good enough for you. At least, your code doesn’t touch org.eclipse.ui.* packages directly (safe for the command’s ID).

Is it possible to use a FormEditor in an e4 application?

Is there a way to use a FormEditor in an e4 application? I want to migrate an 3.x Eclipse RCP application to e4 and it would be great if there would be a simple way to reuse existing editors.
No you can't use any editor based on the 3.x EditorPart.
I think you can use the org.eclipse.ui.forms plug-in that contains things like FormToolkit, but I have not tried this. The dependencies for this plug-in only contain optional dependencies on 3.x code.

Reuse standard menus in Eclipse RCP4 application

I want to reuse standard menus from the Eclipse IDE in my RCP4 application (e.g. Windows->Preferences).
In Eclipse RCP3 applications you simply have to add a menuContribution to the plugin.xml to achieve this.
I tried the same for my RCP4 application but without success. Is there another way to add standard menus to a RCP4 application?
For a pure e4 application which is not using the 3.x compatibility layer you have to construct all the menus and dialogs yourself.
For preferences you can use the JFace org.eclipse.jface.preference.PreferenceDialog which is a simpler version of the normal preferences dialog, but you don't get the preference page extension point (or any existing pages) so you have to craft all that yourself.

Eclipse e4 and plug-in development

Is it possible to create Eclipse plug-ins (e.g view parts) using Eclipse e4 incubator?
Or is e4 only useful for 'window-based' applications?
I already checked How can I create a view using the E4 programming model to be a plug-in for Eclipse 4.2 or above?, but this did not give me an useful answer.
Add:
I want to create an Eclipse plug-in and not a standalone rcp application.
I'm not sure what exactly you want to achieve.
Option 1:
You want to write a plug-in for an e4 RCP application:
You can do this (e.g., contribute ViewParts to an e4 application model) via a model fragment.
Basically, instead of extending the org.eclipse.ui.views extension point in Eclipse 3.x you create an application model fragment file in your plug-in and reference this in an extension to the extension point org.eclipse.e4.workbench.model.
In the model fragment, you define the parts, commands, etc. you want to contribute.
See for example these tutorials for more details:
http://eclipsesource.com/blogs/2012/06/26/eclipse-4-e4-tutorial-part-3-extending-the-application-model/
http://www.vogella.com/articles/Eclipse4Modularity/article.html
Option 2:
You want to write a plug-in e4 style for Eclipse itself.
As far as I know this is not possible straightforward, because currently, the Eclipse IDE cannot be enhanced with fragments (at least that is what https://bugs.eclipse.org/bugs/show_bug.cgi?id=376486 indicates ...)
But when that works, see Option 1.
Until then, you'd have to use the classic extension points. You can still write your view using the POJO/Injection approach of e4, but you need to use the 3.x to e4 bridge. You can get some hints from
http://eclipsesource.com/blogs/2012/06/18/migrating-from-eclipse-3-x-to-eclipse-4-e4/ .
In particular, see the paragraph starting "The third option is to use the 3.x e4 bridge from the e4 tools project"