The e4view
extension point allows a view to be loaded into an Eclipse 4.x application without the need of a specific superclass. This allows existing Eclipse 3.x views to be upgraded to an Eclipse 4.x view as follows.
SampleView
class and remove the extends ViewPart
superclass definition. This will introduce some errors in the code, which will be fixed shortly.@PostConstruct
annotation to the createPartControl
method. Use Cmd + Shift + O on macOS or Ctrl + Shift + O on other platforms to automatically add the import javax.annotation.PostConstruct
statement.@Focus
annotation to the setFocus
method. This time, the automatic import won't work, but a quick fix will suggest adding the dependency. Alternatively open the MANIFEST.MF
file, go to the Dependencies tab, and add org.eclipse.e4.ui.di
bundle as a dependency. Now switch back to the SampleView
class, perform the organize imports with the previous keystroke, and import org.eclipse.e4.ui.di.Focus
should be added automatically.plugin.xml
file and change the view
element to e4view
for the SampleView
entry:<e4view class="com.packtpub.e4.migration.views.SampleView" .../>
getView
and getViewSite
method calls, to fix any remaining compile errors.At the moment, the view is not quite as functional as it was before; the view actions are not connected and the code uses the deprecated JFace Action
class instead of commands and handlers. This will be upgraded in the next section.
The view was migrated from extending ViewPart
to one with no superclass, and the relevant Eclipse 4.x annotations of @PostConstruct
and @Focus
were added, as described in Chapter 2, Creating Views with SWT. Since the superclass provided the getSite
and getViewSite
methods, references to those calls had to be commented out.
3.137.221.163