Migrating Entry Editor in Eclipse E4

This section talks about how to use a Part to display information related to a particular entry

Entry Editor Extension Point

In Eclipse 3.x version, GRITS defined an entry editor extension point which all the editors registered to. This extension point was used to identify the matching editor to display a particular entry. This extension point is deprecated and should not be used for plugins using eclipse e4 architecture.

Part Descriptor in e4xmi file

A Part Descriptor is a generic description of a part that might be instantiated multiple number of times with different objects. For each entry editor, we create a "Part Descriptor" in the "Part Descriptors" section of the Application.e4xmi file. If your plugin does not define the application model, then you contribute to the application model through the fragment.e4xmi file.

Contributing Part Descriptor through Model Fragment

Add a Model Fragment to Model Fragments in the fragemnt.e4xmi file and set the following values for the fragment

  • Extended Element ID - org.grits.toolbox.core.application
  • Feature Name - descriptors

Add child to this Model Fragment by selecting PartDescriptor. Set the values to this PartDescriptor

  • You can re-use the ID, Label, Tooltip and Icon URI from the previous entry editor for this part descriptor
  • For the Class URI create a new Plain Old Java Object (POJO) class that would be the counterpart of the EntryEditor class
  • Select the Dirtyable, Closeable, Multiple option
    • unless you don't need these in your editor
  • In the Category section add the type of the entry property that this part descriptor would display information for
    • for a project entry it would be
  • In the Binding Contexts add Entry Binding Context
    • this is used to identify a part that is a candidate for displaying entry information
    • counterpart for entry editor extension point
  • See documentation on Entry Part Descriptor

Below is a screenshot for creating the Part descriptor in fragment.e4xmi file.

Part Descriptor in the Application.e4xmi file

Class implementing the Part

Use similar approach described in the documentation for migrating view to part.

  • Put @PostConstruct annotation in the method that creates ui component
    • Add all the control member variables like Text or TreeViewer from the previous Entry editor
  • Inject some of the variables in the entry part that you will use later
    • MDirtyable would be used for setting and resetting part dirty
    • ESelectionService would be used for injecting the current selection to be used anywhere else
      	@Inject private MDirtyable dirtyable = null;
      	@Inject private ESelectionService selectionService = null;
  • Put @Persist annotation in the method that saves the dirty editor
  • Put @Focus annotation in the method for getting focus

Initializing the Entry object

When an entry is being opened from the project explorer, the current selection is the entry object that is being opened. So in the constructor itself use this selection object and initialize its member variable with it. Here is an example code for initializing it in the constructor.

	private Entry projectEntry = null;

	// constructor
	public ProjectEntryPart(@Named(IServiceConstants.ACTIVE_SELECTION) Entry entry,
			@Named(IServiceConstants.ACTIVE_PART) MPart part)
		if(entry != null && ProjectExplorerPart.PART_ID.equals(part.getElementId()))
		  this.projectEntry = entry;
		    // do rest of initialization stuff here

Last modified 4 years ago Last modified on 06/10/2016 05:41:08 PM

Attachments (3)

Download all attachments as: .zip