问题描述
我尝试使用EMF& amp;创建一个简单的图表Eclipse插件中的GMF。我创建了一个带有两个节点和放大器的Ecore。连接。我可以从中生成GMF。当我运行我的应用程序时,我得到了味觉,并且在我的帮助下,我能够绘制GMF图。但我想以编程方式。
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.
我已经从Ecore中创建了一个XML,并成功地将该XML加载到EMF对象中。所以我的EObject具有XML值。现在我想要自动生成GMF图。与打开一个示例RCP视图一样,它应该加载GMF内容。
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.
问题是我是这个GMF和EMF的新手,所以我不知道哪个类我要修改或者我要编写什么。
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.
推荐答案
我有一个解决方案:
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:该图应与您的ecore文件位于同一位置
PS: The diagram should be at the same place as your ecore file
这篇关于以编程方式创建GMF图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!