Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get a view part instance in an Eclipse e4 application?

Tags:

eclipse

I'm trying to get the instance of a view part in an Eclipse e4 application but I can't find the PlatformUI class. Has the name changed since Eclipse 3 or is it located in a different package?

like image 398
August Karlstrom Avatar asked Dec 05 '22 16:12

August Karlstrom


1 Answers

When looking at Eclipse e4 Parts:

e4 parts

bugs like 371405 can be instructive:

org.eclipse.ui.presentations

This API no longer works in 4.2, and we never intend to make it work.
It is incompatible with the pluggable rendering story in 4.2. Decisions that could once be made by the presentation extensions are now up to the renderer.

Affected API that needs deprecation:

  • Entire API package: org.eclipse.ui.presentations
  • Extension point:org.eclipse.ui.presentationFactories
    org.eclipse.ui.IWorkbenchPreferenceConstants#PRESENTATION_FACTORY_ID
    org.eclipse.ui.IWorkbenchWindowConfigurer#getPresentationFactory
    org.eclipse.ui.IWorkbenchWindowConfigurer#setPresentationFactory

The rest of the Tutorial explains how to declare "parts" (editors or views)


The OP August Karlstrom mentions:

This used to work:

PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView("‌​some view");

Using a singleton like PlatformUI is a bad practice and one of the reason of the introduction, in e4, of Context. See this presentation on Context.


Paul Webster (IBM Eclipse Platform team member) comments:

In Eclipse4 you would use org.eclipse.e4.ui.workbench.modeling.EPartService.findPart(String) to find an MPart by ID.
The MPart contains the injected part in its object property.

As the page Workbench_Services details:

In e4, the notion of a workbench page will not be present.
The part service API will essentially be a merge of the existing 3.x IPartService and WorkbenchPage interfaces.


Note that this isn't ideal, as bug 372488 illustrates (following this thread):

An MPart for an MPartDescriptor is created with EPartService.createPart(descriptor_id), where descriptor_id is the identifier of the MPartDescriptor.
This part can be found again with EPartService.findPart(descriptor_id) -- if there is only one.

The problem is, that one may need do create more than one MPart for one MPartDescriptor.
An editor may be one example: one may want to edit different instances of one and the same kind.

The creation of more than one MPart for a given MPartDescriptor is possible, but there is no convenient method to find these parts.
EPartService.findPart(descriptor_id) will return the first MPart created for a particular MPartDescriptor, even if there is more than one.
So there are three problems, for a given MPartDescriptor:

  1. EPartService.findPart(id) does not tell that there is more than one MPart.
  2. There is no convenient way to get all MParts for this descriptor.
  3. There is no API-way to get the particular MPart for given descriptor and "content" or "reference".

Currently the way to go is using EPartService.getParts() which unfortunately returns all MParts, not only those corresponding to one particular MPartDescriptor.
Then one would need to check, whether there is one MPart for the particular MPartDescriptor having a particular "content".

So something is missing that will find an MPart for a given MPartDescriptor with particular "content" or "reference".

like image 173
VonC Avatar answered May 17 '23 12:05

VonC