Eclipse 4 Application Platform – contributorURI vs contributionURI


All Eclipse 4 applications (from the Eclipse 4.x IDE to your simple e4 RCP) leverage the Eclipse 4 application model who is a representation of your whole application in a well defined and typesafe EMF-Model (you can somehow compare it to your browsers DOM).

The model itself is not static but a so called live model and you can interact with it through your preferred VM-Language eg to add new elements. One of the things done most often is to programmatically add MPart instances to represent your UI-Component.

The code below is taken from the e(fx)clipse code editor component library

public static class DefaultEditorOpener implements EditorOpener {
  @Inject
  EModelService modelService;

  @Inject
  @Service
  List<FileIconProvider> fileIconProvider;

  @Override
  public boolean openEditor(String uri) {
    // .....
    MPart part = modelService.createModelElement(MPart.class);
    part.setCloseable(true);
    part.setLabel(URI.create(uri).lastSegment());
    part.setContributionURI("bundleclass://org.eclipse.fx.code.editor.fx/org.eclipse.fx.code.editor.fx.TextEditor");
    part.setContributorURI("platform:/plugin/org.eclipse.fx.code.editor.fx.e4");

    String iconUri = fileIconProvider
      .stream()
      .filter( f -> f.test(uri))
      .findFirst()
      .map( f -> f.getFileIconUri(uri))
      .orElse("platform:/plugin/org.eclipse.fx.code.editor.fx.e4/icons/file_16.png");
    part.setIconURI(iconUri);
    part.getPersistedState().put(Constants.DOCUMENT_URL, uri);
    part.getTags().add(EPartService.REMOVE_ON_HIDE_TAG);
    // .....
  }
}

While most of the code is straight forward most developers stumble upon the 2 very similar MPart attributes:

  • contributionURI: URI to identify the class that is responsible to create the MParts UI
  • contributorURI: URI to identify the bundle who create the model element

Even worse most developers only use contributionURI and never set the contributorURI value which might lead to problems for example if the value is to be translated because the information in the contributorURI is used to retrieve the ResourceBundle through the BundleLocalization-Service.

Advertisement
This entry was posted in e(fx)clipse, e4. Bookmark the permalink.

1 Response to Eclipse 4 Application Platform – contributorURI vs contributionURI

  1. Pingback: Creation of Eclipse 4 Application Model elements in efxclipse 2.2.0 | Tomsondev Blog

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.