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

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.

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 migrating 3.x plugin to 4.x?

I have been working with Eclipse RCP for over a week now, and I've now been given an Eclipse plugin written in 3.x, which I need to migrate to 4.x. I'm using a book called Eclipse 4 RCP by Lars Vogel which has a small section on this, but I can't for the life of me figure out what I'm to do.
I'm trying to do this throught the use of the compatiblity layer. It mentions to add a couple of features for this (org.eclipse.rcp, org.eclipse.emf.ecore, org.eclipse.emf.common) and your ready to go, but I don't exactly know what I'm to do here. Like do I add these to the existing product file of the 3.x plugin I've been given, or do I create a separate e4 project and point to that. Many of the tutorials I read are a bit vague with the details and its a shame there's no proper step by step guide for beginners with this. Any help would be great.
Probably, you should be creating a separate e4 plug-in project for this. And where you have to configure your extensions/extension points in e4 ways.
Basically, like creating a new project.
If you want to migrate your Eclipse 3.x RCP application to the Eclipse 4 programming model, you can't directly reuse existing plugin.xml based user interface components, e.g. Views or Editors based on the definition in plugin.xml .
Components based on the plugin.xml file must be adjusted to avoid inheritance of Eclipse classes and to use the programming model based on #Inject . They also must be contributed to the application model.
Components which are not directly based on the plugin.xml file must be adjusted if they use Eclipse 3.x singletons, as for example Platform or PlatformUI , to access Eclipse API
you may want to take a look at this page: https://www.eclipse.org/community/eclipse_newsletter/2013/february/article3.php

Eclipse RCP: NullPointer on getSite().setSelectionProvider(...)

As I have done the following tutorials:
http://www.vogella.com/tutorials/EclipseRCP/article.html
http://www.vogella.com/tutorials/EclipseJFaceTable/article.html
http://www.vogella.com/tutorials/EclipseJFaceTableAdvanced/article.html
I wanted to combine the JFace table viewer (plugin from 2nd and 3rd tutorial) and the ToDo application from the first tutorial. In the JFace table example(s) there is a View extended from a ViewPart. In this the call:
getSite().setSelectionProvider(view)
inside the createPartControl method is fine and works.
But when I do the same in the other tutorial it does not work, I get a NullPointerException. The first article creates a plugin and then transform it using features and products into an Eclipse 4 application. So the classes in the application are not derived from a 'Part'. They are referenced using the application model and only use the annotation #PostConstruct.
Why is it that I get this NullPointerException?
And really, how can I get the SelectionProvider service linked to the Workbench?
I also tried to use PlatformUI.getWorkbench() but it says that the workbench does not yet exist.
Any help highly appreciated.
Thanks.
Eclipse 4 (e4) applications are completely different from traditional Eclipse 3.x style applications.
In an e4 application you cannot use a lot of things that are used in a Eclipse 3.x application - so you need to check which style the example you are using is based on. The e4 application has access to a lot of new features that are not available in a 3.x application.
In an e4 application you inject the ESelectionService to get and set the current selection.

How to create Eclipse RCP application that behaves like a wizard?

I want create a installer by using Eclipse RCP. I need to give the user a wizard-like installer. This means user can do some options then click next. Or they can go back to previous page by click previous. Or they can cancel the installation by clicking cancel.
Here is my problem:
I don't know how to switch between views when clicking "next","previous". I need to create something like WizardPages and i can change between these pages?
I can't use JFace wizard because I'm required not to pop up any dialog.
I'm totally new to Eclipse RCP so please help!
thanks.
Maybe "StackLayout" is what you need.
Consider whether you actually want/need Eclipse RCP in this context. Eclipse RCP shines in complex applications with an extensive business domain and complex user interface.
An installer wizard, however, is very straightforward and static. I cannot imagine you requiring more than two or three user inputs. Your question is a bit like "I want to hear beautiful music. How do I program a robot to play the piano?"
It is much easier to limit yourself to using SWT and JFace. Use the JFace WizardDialog to make a nice installation wizard. You will find you will have never needed the Eclipse RCP framework.
See http://www.vogella.com/tutorials/EclipseWizards/article.html for a nice tutorial.
If you do think you need the features of the Eclipse RCP runtime framework, I suggest you follow the path below instead:
Create an RCP application (e.g. the sample 'Mail' application). A class will be created that is the main entry point in your application. This class will launch the Eclipse Workbench. Delete this code, and instead launch the WizardDialog.
A lot of things will not be available, such as menu's, views with drag-and-drop functionality, keybindings, etc. I cannot imagine you will need those things. However, you will benefit from the following Eclipse RCP features:
Eclipse launch framework. Ability to create a self-contained product including the JRE.
OSGi framework. Ability to easily add new plugins. Ability to use services, blueprint, etc.
JFace framework.
EMF (if you have a very complicated installation wizard)
All other eclipse plugins, although a lot of them may not work outside of the context of the Eclipse Workbench.
If you are convinced you need the full Eclipse Workbench, you can always do the following:
Define a 'base' perspective that is 'locked down'.
Use a Command to move from one perspective to the other. This will allow you to keep the previous wizard views open in other (hidden) perspectives.
Use Eclipse Contexts to hide all the standard Eclipse Workbench functionality, menu's, etc.
Since you are new to Eclipse RCP, I do not recommend learning the framework in the particular usecase of an Installation Wizard. You already need good knowledge of Eclipse RCP to be able to hack it this way, and it will not be a clean or nice implementation :-)

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"