In E3 this was one of the basic use cases: we want to open an editor (or view or part, whatever you want to call it) based on some model object, back then wrapped in IEditorInput
.
In E4 this seems to be one of the features that got removed without replacement. However you can reinvent the wheel:
public static final String DATA_MODEL = "model";
@Inject
private EPartService partService;
@Inject
private EPartService partService;
@Inject
private MApplication application;
public void open(String editorId, Object editorInput) {
MPart part = this.partService.createPart(editorId);
part.getTransientData().put(DATA_MODEL, editorInput);
this.partService.showPart(part, PartState.ACTIVATE);
PartStack editorStack = (MPartStack)
this.modelService.find("org.acme.application.stack", this.application);
editorStack.setVisible(true);
editorStack.getChildren().add(part);
}
(Please correct me if I'm wrong. This seems way to ugly and overcomplicated to be the right way™.)
So, what if there is already an editor with the input? In E3 the editor was just brought to the top and activated. In E4... well, since there are no editors anymore, it's no surprise the application can't handle that case.
So we added the following to the top of the above method:
for (final MPart part : this.partService.getParts()) {
if (part.getElementId().equals(editorId)
&& Objects.equals(editorId, part.getTransientData().get(DATA_MODEL)))
this.partService.showPart(part, PartState.ACTIVATE);
return;
}
It works, no problem here. It's just so much work for basic functionality, so now we figure we don't really understand how E4 is supposed to work.
Are we missing something? Is this really the correct way to handle parts with input? Is there no framework support at all for this standard use case?
来源:https://stackoverflow.com/questions/43782165/open-editor-part-in-e4