Lars mentioned that Eric had erected a new extension to the "views" extension point call "e4view" so I was eager to try this out. This is what I did.
Taking Luna for a spin
Pick up a copy of Eclipse Luna from the Platform download page. Look for the 4.4 Integration build link, ignore all the red you see, find the build for your platform and click on "(http)" to get the zip.Then extract the zip and enter that directory to find the Eclipse executable and run it.
Creating the RCP application
With the information from the bug and the mailing list, I asked myself, what is intuitive? My first idea was to create an RCP application with the usual wizards and use the "RCP with a view" template and then extend this application to add an e4 view. This turned out to be exactly how it works.
I took the first step and let Eclipse generate the little RCP application for me. Once the application was generated, I executed it once to see if it worked. As usual, no problems.
I took the first step and let Eclipse generate the little RCP application for me. Once the application was generated, I executed it once to see if it worked. As usual, no problems.
Adding an e4 part
The next thing was to look for the new extension in the views extension point and there it was:
What crossed my mind is that the extension is called "e4view". I could have been called "e4part" since the difference between views and editors is no longer there in e4.
Another note is that Eric could have re-used the "view" extension since they both share the same structure. One thing that you get for free with that approach is the cross referencing in the manifest editor. More about this later.
Creating the part
I clicked the class* link and the editor started the "create new class" wizard. I just pressed enter because the e4 views do not extend ViewPart. After the editor was opened, I re-activated the manifest editor and added the following dependencies to my bundle.
- org.eclipse.e4.ui.di
This contains the @Focus annotation. - javax.annotation
This contains the @PostContruct annotation.
Then I re-actived the java editor and created the following code:
package com.test.plugin.luna; import javax.annotation.PostConstruct; import org.eclipse.e4.ui.di.Focus; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; public class E4view1 { private Button button; public E4view1() { } @PostConstruct public void createPartControl(Composite parent) { GridLayout gridLayout = new GridLayout(1, false); gridLayout.marginWidth = 5; gridLayout.marginHeight = 5; gridLayout.verticalSpacing = 0; gridLayout.horizontalSpacing = 0; parent.setLayout(gridLayout); button = new Button(parent, SWT.PUSH); button.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); button.setText("Push me"); button.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { } }); } @Focus public void setFocus() { button.setFocus(); } }
Adding the e4 view to the perspective
Time to add this nice e4 view to the perspective. But how... I just followed a hunch and added the id of the "e4view" extension to the "perspectiveExtensions" extension point. Referencing the view (by clicking on the "Browse.." button) did not work because of the new name...
I saved all my files, opened the run configuration and added the following directives to the launcher
Then I clicked on the "Plug-ins" tab and pressed "Add Required Plug-ins". Subsequently I added all plugins with "gogo" in the name (3) and I added "org.eclipse.equinox.console".
Then I pressed "Run" and behold; A truly mixed mode application appeared where my dependency injected view co-existed with a traditional e3 view.
Changing the run configuration
- -console
Should be a default option IMO - -clearPersistedState
This will clear the e4 model and rebuild it freshly from the filesystem. I suspected that my view would not be shown otherwise.
Then I clicked on the "Plug-ins" tab and pressed "Add Required Plug-ins". Subsequently I added all plugins with "gogo" in the name (3) and I added "org.eclipse.equinox.console".
Running the mixed mode application.
One small step for [a] man but a giant leap for Eclipse RCP
In my opinion this is the most important step in the history of Eclipse 4. This opens the door to start exploring the new programming paradigm for everyone. This seemingly little change truly is the bridge between old and new and I predict that we are in the rapids. Things could be happening real fast now the platform team has crossed this threshold. Companies can start working on the transformation from old to new, upgrading view by view which will trigger new ideas and changes.photo by Robert J Moffatt |
Why Eclipse 4?
Curious why you should go to Eclipse 4? I have created a blog about this a while ago. You should definitively read it.
Thanks..
Thanks to the platform team for this change and getting up to speed with the mixed mode changes so early in the development cycle of Luna. Great job!
Cheers,
Wim
Thanks Wim for talking this for a test drive. Good times ahead for Eclipse 4.
BeantwoordenVerwijderenGood to see that it is finally possible to add additional views to an application without knowing the application structure. To me this is one of the most important features of eclipse. I was always wondering why something so crucial was not part of the previous e4 releases.
BeantwoordenVerwijderenHi Wim, this is great news for us at Diamond (www.diamond.ac.uk, www.opengda.org.uk and dawnsci.org). There was no way we would have the time to re-write all our products into pure e4.
BeantwoordenVerwijderenPlease keep up the posts on this topic.
Paul
Wim, thanks for the great post(s) ! The reason to use 'e4view' is the 3.x legacy is indeed broken into views / editors with each having its own specific extension point; we'll eventually add an 'e4editor' extension to the org.eclipse.ui.editors extension point (once we figure out how it works...;-).
BeantwoordenVerwijderenBTW, good pickup on the search from the perspectiveExtensions EP not being able to find your views; would you please update the defect with this ?