Time for action – creating a model fragment

Eclipse 4.x applications use a model fragment to define the UI. It is necessary to create a model fragment to define the part descriptors, handlers, and commands to simplify the code shown previously. To start with, the e4view extension will be replaced by a part descriptor in the fragment.

  1. Comment (or delete) the e4view extension from the plugin.xml to prevent it from being loaded.
  2. Select the project, navigate to the File | New... menu, and choose New Model Fragment from the dialog.
    Time for action – creating a model fragment
  3. In the newly opened fragment.e4xmi file, click on Model Fragments and click on Add to add a new fragment.
  4. Enter org.eclipse.e4.legacy.ide.application as the Extended Element ID and descriptors as the Feature Name.
  5. Select PartDescriptor from the drop-down menu and click on Add to add a new Part Descriptor with the following fields:
    1. ID: com.packtpub.e4.migration.views.SampleView
    2. Label: Sample View
    3. Icon URI: platform:/plugin/com.packtpub.e4.migration/icons/sample.gif (the Find … button will allow the plug-in's contents to be browsed through a graphical user interface and the file selected instead of typing it in)
    4. Class URI: bundleclass://com.packtpub.e4.migration/com.packtpub.e4.migration.views.SampleView (the Find … button will allow the plug-in's classes to be browsed through a graphical user interface instead of typing it in)
    5. The ToolBar checkbox should be selected
    6. The Closeable checkbox should be selected
    7. Category: Sample Category
  6. The part descriptor should now look like:
    Time for action – creating a model fragment
  7. Switch to the Supplementary tab of the part descriptor, and add a tag by typing in View and clicking on the Add button:
    Time for action – creating a model fragment
  8. Now run the Eclipse instance and navigate to the Window | Show View | Other | Sample Category | Sample View menu. The Sample View should be displayed.

What just happened?

The Eclipse 3.x way of defining views was through a view extension point. To facilitate migration towards Eclipse 4.x APIs, an e4view extension was created. This allows a view to participate in the dependency injection provided by the Eclipse 4.x platform but in a simple way.

However, it is more appropriate to declare views with an Eclipse 4.x fragment and a part descriptor. The part descriptor represents the logical view (similar to an object class) whilst the part represents the actual instance shown in a window (similar to an object instance).

Parts in Eclipse 4.x are more flexible than views; they can have properties such as whether they are closable or not, or whether there can be multiple copies of them at one time. These options can be configured in the fragment rather than code.

Tip

To ensure that the view is presented in the Show View menu, a tag with the value View must be added in the Supplementary part of the fragment editor. If this is omitted or a different case is used, then the view will not show up and it will not be displayed in the Show View menu.

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

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