Create GMF diagram programmatically

旧时模样 提交于 2019-12-10 00:03:32

问题


I trying to create one simple diagram using EMF & GMF in Eclipse plug-ins. I have created one Ecore with two node & connection. I am able to generate GMF out of that. When I run my application I am getting the palate and with the help of that I am able to draw the GMF diagram. But I want that programmatically.

I have created one XML out of that Ecore and successfully able to load that XML into the EMF object. So my EObject is having that XML values. Now I want a GMF diagram out of that automatically. like with the opening of one sample RCP view it should load the GMF content.

The problem is that I am new to this GMF and EMF, so I don't know which class I have to modify or what I have to write.


回答1:


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



来源:https://stackoverflow.com/questions/19055311/create-gmf-diagram-programmatically

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