如何在 ECORE 中创建运行时可用的 Has-A 引用(包含)?
嘿, 我是 EMF/ECORE 新手。我想对 Has-A 参考(遏制)进行建模,但遏制 应该在运行时可用。所以:
我有不同的课程,都有一定的容量。因此体积在类中建模:
MyVolume
- depth: EDouble
- height: EDouble
- width: EDouble
- volume()
MyClass
- name: EString
- volume: MyVolume
如果使用 .genmodel 创建编辑器,我可以将体积添加到类中。但我希望 volumne 是 Class 的一部分,以便用户可以使用 Class Volume 作为名称等属性,而无需先创建它。深度、高度和宽度的显示方式应与编辑器属性视图中的属性名称相同。
应该设置模型中的哪个属性或者是否有其他方法来存档目标?
提前感谢
Steffen,
我想出了一个“解决方案”:
- 我创建了类 MyVolume,然后
- 创建了一个使用 My.impl.MyAttributeImpl 作为实例类名称的数据类型 MyVolume。
- 然后在MyClass中创建一个属性卷:MyVolume(Datatype)。
- 所以我可以像这样在源代码中访问深度:fixture.getVolume().getDepth();
- 但编辑器的属性视图中仅显示音量。
还有更多想法吗?
史蒂芬
Hey,
I am new to EMF/ECORE. I want to model a Has-A reference (Containment), but the containment
should be available at runtime. So:
I have different classes that have a volume. so the volume is modeled in a class:
MyVolume
- depth: EDouble
- height: EDouble
- width: EDouble
- volume()
MyClass
- name: EString
- volume: MyVolume
If a create an Editor with the .genmodel, I can add to Class a Volume. but I want that volumne is a part of Class, so that the user can use the Class Volume as an attribute like name without creating it first. And depth, height and width should be displayed the same way as the attribute name in the properties view of the Editor.
Which property in model should be set or is there another way to archive the goal?
Thanks in advance
Steffen
I figured out a "solution":
- I created the class MyVolume, and then
- a datatype MyVolume that use My.impl.MyAttributeImpl as Instance Class Name.
- Then created in MyClass an attribute volume: MyVolume (Datatype).
- So I can acccess depth in the source code like this fixture.getVolume().getDepth();
- But only volume is show in the properties views in the Editor.
Any more ideas?
Steffen
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么不简单地让
MyClass
扩展MyVolume
,而不是拥有一个属性呢?我认为你想要的这种联盟不会以任何其他方式得到支持。Why not simple make
MyClass
extendMyVolume
, instead of having an attribute? I don't think this kind of union that you want is supported in any other way.您还可以覆盖项目提供程序,以便在创建“MyClass”时自动创建 MyVolume 的实例。
EMF 书中有大量这样的示例,这里是 EMF.Edit 框架的总体介绍,看一下“覆盖命令”部分。
You could also override the item provider to automatically create an instance of MyVolume when you create a "MyClass".
The EMF Book has tons of examples like that, here is the general presentation of the EMF.Edit framework, have a look on the "overriding commands" part.