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 UIcontributorURI
: 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.
Pingback: Creation of Eclipse 4 Application Model elements in efxclipse 2.2.0 | Tomsondev Blog