|
|
Re: How to create an object view from an external java action? [message #1732429 is a reply to message #1732419] |
Tue, 17 May 2016 04:52  |
Eclipse User |
|
|
|
Thanks a lot, it works!
Here is the fragment of my final code:
DDiagramEditor editor = (DDiagramEditor) EclipseUIUtil.getActiveEditor();
DSemanticDiagram diagram = (DSemanticDiagram) editor.getRepresentation();
Session session = SessionManager.INSTANCE.getSession(newRelation);
if (newRelation.getEnds().size() == 2) {
EdgeMapping mapping = diagram.getDescription().getDefaultLayer().getEdgeMappings().stream()
.filter(m -> m.getName().equals("Relation"))
.findFirst()
.get();
Concept concept1 = newRelation.getEnds().get(0).getRole().getConcept();
Concept concept2 = newRelation.getEnds().get(1).getRole().getConcept();
DNodeList source = (DNodeList) getDDiagramElement(concept1, diagram);
DNodeList target = (DNodeList) getDDiagramElement(concept2, diagram);
RecordingCommand cmd = new CreateDDiagramElementCommand(session.getTransactionalEditingDomain(), newRelation, mapping, source, target);
session.getTransactionalEditingDomain().getCommandStack().execute(cmd);
}
private DDiagramElement getDDiagramElement(EObject obj, DDiagram diagram) {
return new EObjectQuery(obj)
.getInverseReferences(ViewpointPackage.Literals.DSEMANTIC_DECORATOR__TARGET)
.stream()
.map(el -> (DDiagramElement) el)
.filter(el -> el.getParentDiagram() == diagram)
.findFirst()
.get();
}
|
|
|
Powered by
FUDForum. Page generated in 0.03217 seconds