Eclipse e4 allows to create application elements dynamically. The following is a small example how to create a part dynamically in a handler. This assumes that you have a class “de.vogella.e4.modelservice.part.NewPart” defined in plugin “de.vogella.e4.modelservice”.
@Execute
public void execute(EPartService partService, MApplication application,
EModelService modelService) {
MPart part = MBasicFactory.INSTANCE.createPart();
part.setLabel("New Part");
part.setContributionURI("platform:/plugin/de.vogella.e4.modelservice/de.vogella.e4.modelservice.part.NewPart");
List<MPartStack> stacks = modelService.findElements(application, null,
MPartStack.class, null);
stacks.get(0).getChildren().add(part);
partService.showPart(part, PartState.ACTIVATE);
}
The nice thing of this example is that it demonstrates how you can use the dynamic creating of application elements together with the part and the model service. Via the model service with use for a stack and this part is assigned to the first stack found.
You find more information in my Eclipse e4 tutorial.
When I see this sample, I have the feeling that e4 replaced something cumbersome by something… just as cumbersome, but different. Now it’s EMF based. Is it supposed to be good because modelling is nice?
I’m playing the devil’s advocate,here, but I’m still not totally convinced that the new way to manage the workbench is really better.
@Maxime: I think the extension mechanism is indeed a bit to complex (which is not part of this blog entry). I hope that this can be simplified in the future.