Create GMF diagram programmatically

只愿长相守 提交于 2019-12-04 23:17:11

I have a solution:

    ResourceSet resourceSet = new ResourceSetImpl();
    Diagram diagram = NotationFactory.eINSTANCE.createDiagram();
    diagram.setMeasurementUnit(MeasurementUnit.PIXEL_LITERAL);
    diagram.getStyles().add(NotationFactory.eINSTANCE.createDiagramStyle());
    diagram.setElement(object); //your EObject that should be referenced to this diagram (probably an ecore file)
    diagram.setType("Ecore");
    URI diagUri = URI.createFileURI(yourPathToECoreFile + "_diagram");
    Resource diagramResource = resourceSet.createResource(diagUri);
    diagramResource.getContents().add(diagram);

It works for me... after many hours of research

PS: The diagram should be at the same place as your ecore file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!