This Bugzilla instance is deprecated, and most Eclipse projects now use GitHub or Eclipse GitLab. Please see the deprecation plan for details.
Bug 372488 - [Model] Enhancement of EPartService API for finding multiple parts
Summary: [Model] Enhancement of EPartService API for finding multiple parts
Status: RESOLVED WORKSFORME
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.2   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Lars Vogel CLA
QA Contact: Eric Moffatt CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-02-24 09:22 EST by Karl Weber CLA
Modified: 2015-02-03 09:56 EST (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Karl Weber CLA 2012-02-24 09:22:49 EST
Build Identifier: 4.2  I20120209-1230

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".

A first improvement would be to have a method EPartService.findParts(descriptor_id) which would return all MParts that are in the model and that have been created for an MPartDescriptor with identifier descriptor_id.

In order to find the MPart for a particular content one may flag the MPart for example like

MPart part = partService.createPart(descriptor_id);
part.getContext().modify("input", content_id);

One could then loop through all MParts returned by EPartService.findParts(descriptor_id) for the one which has "input" with content_id (or even content : Object).

A second improvement would be to have this already in the API, i.e. to have a method EPartService.findPart(descriptor_id, content_id) which would return the MPart that has been created for an MPartDescriptor with descriptor_id and that has content with content_id.

The second suggestion for the e4 API is only a rough idea. It may not be in line with the e4 model architecture. There might also be a better approach -- or even none at all...

Reproducible: Always
Comment 1 Remy Suen CLA 2012-02-24 14:16:15 EST
The EMS has a findElements(*) method that you could use instead. Though yes, that requires the passing of a root element unlike the EPS.
Comment 2 Karl Weber CLA 2012-02-24 14:58:33 EST
I have not tried it but it could solve the first problem through a two step search:

The MPart has to be added somewhere. I added a string "someString" as tag to a particular MPartStack and as category to one or more MPartDescriptor(s) in the application.e4xmi. As a result the MParts are added to that particular MPartStack. Hence I could use EMS findElements to first find the root based on the tag "someString" and then to find all MParts for a given id.

This would solve the first problem, although it does not look elegant. And one would have to hard wire the string "someString" into code, which does not look good either.

The second problem remains anyway.
Comment 3 Lars Vogel CLA 2014-05-06 18:17:08 EDT
We currently don't keep a reference to the part descriptor. If you want to find a group of parts you can use the ModelService with one of this find methods and use a tag on the part descriptor. I think that works fine and solves your problems.