Each plugin can define its own content (via PartDescriptor
) that should be added to specific location in my application (into PartStashContainer
).
There could be always just one Part
from plugins visible in that PartStashContainer
.
I can't find what is the preferred way how to achieve this. Should i somehow replace the currently visible Part
with the new Part
from plugin? Or just setup somehow the content of already visible Part
(maybe via setContributionUri
?).
I looked at EPartService
. It looks it can instantiate Part
according to PartDescriptor
, but it has just some methods to make new Part
visible. I need to add the new Part
into existing PartStashContainer
and possibly remove the old Part
.
You can use EPartService
and EModelService
for this.
If you are only going to have one instance of a part with a particular id you can use a 'Part' in the application model as a child of the 'PartStack' and just mark it as 'not rendered'. If you want to create multiple parts with the same id you can use a 'PartDescriptor'.
If you have a 'Part' in your application model marked as 'not rendered' you can show it like this:
partService.showPart("part id", PartState.ACTIVATE);
If you want to create a part from a 'PartDescriptor' and place it in a part stack use:
@Inject
MApplication app;
MPart part = partService.createPart("part descriptor id");
MPartStack stack = modelService.find("part stack id", app);
stack.getChildren().add(part);
partService.showPart(part, PartState.ACTIVATE);
To hide a part use:
MPart part = partService.findPart("part id");
partService.hidePart(part);