Time for action – updating to e4view

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.

  1. Open the SampleView class and remove the extends ViewPart superclass definition. This will introduce some errors in the code, which will be fixed shortly.
  2. Add a @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.
  3. Add a @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.
  4. Open the plugin.xml file and change the view element to e4view for the SampleView entry:
    <e4view class="com.packtpub.e4.migration.views.SampleView" .../>
  5. The final step (for this section) is to comment out the sections that refer to the getView and getViewSite method calls, to fix any remaining compile errors.
  6. Launch the target Eclipse instance and open the Sample View. It should show the list but without any of the local menus:
    Time for action – updating to e4view

What just happened?

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.

Note

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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.221.163