How to customize workbench in a plugin for Eclipse 4 application - eclipse

We are using an Eclipse application, currently developed on Eclipse 3 architecture. We have developed a custom plugin for that application. We are now upgrading this application to a new version that's based on Eclipse 4 architecture. I am tasked with migrating the custom plugin from Eclipse 3 to Eclipse 4 architecture to be used with the upgraded version of the application. I have bit of Eclipse plugin development experience, but migrating from Eclipse 3 to Eclipse 4 architecture is my first. So, excuse me while I explain/ask my questions.
I found one existing question - eclipse rcp 4 - customize workbench. But that question is not answered.
The plugin on Eclipse 3 architecture customizes the workbench, to provide tabs for open and commonly used perspectives (as shown in screenshot), by:
Defined an extension for org.eclipse.core.runtime.applications. Implementation of this extension is in CustomApplication class. CustomApplication class extends the application class from the Eclipse application.
Inside the CustomApplication class, called PlatformUI.createAndRunWorkbench() by passing custom implementation of WorkbenchAdvisor - CustomWorkbenchAdvisor class.
Inside the createWorkbenchWindowAdvisor() method of the CustomWorkbenchAdvisor, created custom WorkbenchWindowAdvisor - CustomWorkbenchWindowAdvisor class.
Inside the createWindowContents() method of the CustomWorkbenchWindowAdvisor, created a custom CustomPerspectiveHeader class to manage those tabs. This class creates tab representation of open & commonly used perspectives. This allows user to switch perspective just by clicking on the tab instead of going through Windows menu. It also provides important information on the perspective header space - such as the user name and group/role that user has logged in. When user clicks on a tab, that perspective opens below.
Eclipse 4 has new mechanism to customize windows layout using application model (via e4xmi file), and createWindowContents() method of the WorkbenchWindowAdvisor is deprecated.
I don't understand how to create/setup/configure e4xmi file for my custom plugin to provide for the Perspective Header space on top of the application UI. I followed tutorial from https://www.vogella.com/ but those tutorials refer to application model in the context of new Eclipse application develipment and not in the context of plugin development for an existing application.
Using application model (e4xmi file) can I just add my plugin workbench changes (the perspective header) on top of what the application provides or do I need to provide the entire workbench layout in my plugin application model?

Related

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

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

What type of Eclipse 4 customization should I choose - Application or Plugin?

I would like to create an Eclipse 4 customization, but I'm new to this aspect of Eclipse development.
As a result, I would like to ask the community what they would recommend based on the following requirements for an SDK-style custom component/project:
show up as a new project type with it's own Wizard
the wizard may use some of the built-in java source/path dialogs, but would also provide some custom dialogs of its own
based on the user selection, the wizard would generate starter code from some template(s)
once the project has been created, it will be similar to a Java project. IN FACT, I would like to allow someone the ability to compile select java code into different jars if they want - all within this one project
finally, when in these new project types inside the project explorer, I need to be able to execute custom commands (with UI support) - such as "Prepare Custom Extension", which will create JARs (if applicable) and copy all relevant source/folders into a prep location, then zip it up
Thanks and let me know if I need to clarify anything!
Bob

How to add plugin with perspective and view to my own RCP app

I have a very basic RCP application (e3.7.1) with only one (Hello World) plugin. For reasons of code control I want to develop all perspectives and views in separate plugins. I have now set up one plugin with a perspective and a view. How do I get them into my main RCP plugin, e.g., where do I configure which extensions/extension points? I want the perspective and view to appear in the Perspective Menu as well.
How did you create you RCP application, did you create a .product definition ? did you create a feature ?
Basically Eclipse is based around plugins (OSGI bundles) and you can create view and perspective in different plugins. As long as your plugin is part of you RCP .product definition either as a plain plugin or into a feature definition, you should be able to export your RCP application with all the desired plugins.
If you are just talking about how to run them from Eclipse, you need to edit the run configuration and add all the plugin you need to activate in the Eclipse Application run configuration. This configuration is the on you use to launch the RCP application.
The set of view and perspective shortcuts in those menus is specific to current perspective.
If the perspective on which you want to make those shortcuts available is your own, then you need to call IPageLayout methods addShowViewShortcut() and addPerspectiveShortcut() from your IPerspectiveFactory. If you want to make those shortcuts available on someone else's perspective then use org.eclipse.ui.perspectiveExtensions extension point.