Eclipse E4 open Java Editor Programmatically - eclipse

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).

Related

How to Configure Eclipse Content Assist so that it will suggest JavaFX components first?

I am using Eclipse to develop a JavaFX application. Whenever i press Ctrl + Space, Eclipse would suggest me components from AWT or Swing rather than from JavaFX. It happens also to List where instead of the java.util.List, it gives the List from other absurd modules. It doesn't also seem to learn my usage.
How can I configure my content assist preferences?
UPDATE:
Using
jdk1.8.0_101,
Eclipse Photon,
Windows

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).

ResourceTreeAndListGroup in eclipse 4

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.

Can I use Eclipse Dependency injection (DI) in normal Java Model?

I am trying to write Java model which will act as model for Eclipse RCP. This model I should be able to run without UI also (i.e in command line). I wanted to use (Explore, I am new to this) DI supported by e4. Can any one guide me on this?
As described in Eclipse bug 323075 the e4 RCP startup currently always wants to create a Window. So it does not look like you can use it for a 'headless' RCP.

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"