如何创建对现有模型对象的引用?

发布于 2024-10-01 11:37:03 字数 1103 浏览 6 评论 0原文

我是 MDSD/EMF 的新手,但由于 Eclipse 的支持,我取得了很大的进步。

我昨天按照 awynne 的建议创建了一个玩具模型,而且我已经非常接近了。我只使用 EMF 及其生成的树编辑器。

以下是我的 EMF 元模型的摘要:

- EClass: Widget
  - name

- EClass: WidgetReference
  - aWidgetReference : Widget [0..1] Containment = false

- EClass: WidgetContainer
  - myWidgets : Widget [0..*] Containment = true

- EClass: ReferenceContainer
  - myReferences : WidgetReference [0..*] Containment = true

- EClass: TopLevelClass
  - myWidgetContainer    : [1] WidgetContainer    Containment = true
  - myReferenceContainer : [1] ReferenceContainer Containment = true

现在发生的情况是,在模型的生成树编辑器中,我从 TopLevelClass 开始创建所有内容。我可以在 WidgetContainer 中成功创建多个小部件,并且可以在 ReferenceContainer 中创建单个 WidgetReference 并将其与特定的 Widget 关联。

万一有人遇到这种情况,生成的 EMF 编辑器代码中存在一个错误:

当我尝试向 ReferenceContainer 添加多个 WidgetReference 时,树编辑器仅显示 ReferenceContainer 下的第一个 WidgetReference。如果我单击树中的 WidgetReferences 项,它会在属性视图中显示多个 WidgetReferences。它只是不允许我在树中看到它们,因此不允许我选择它们来更改它们的引用以将其关联到实际的小部件。

解决方法是根据需要创建尽可能多的参考,保存并关闭模型,然后重新打开它。重新打开它后,将显示所有参考文献。

感谢您的任何帮助/指导。

杰夫

I'm new to MDSD/EMF but am making great progress thanks to Eclipse's support.

I created a toy model as answered yesterday as awynne suggested, and I'm very close. I'm only using EMF and its generated tree editor.

Here's a summary of my EMF meta-model:

- EClass: Widget
  - name

- EClass: WidgetReference
  - aWidgetReference : Widget [0..1] Containment = false

- EClass: WidgetContainer
  - myWidgets : Widget [0..*] Containment = true

- EClass: ReferenceContainer
  - myReferences : WidgetReference [0..*] Containment = true

- EClass: TopLevelClass
  - myWidgetContainer    : [1] WidgetContainer    Containment = true
  - myReferenceContainer : [1] ReferenceContainer Containment = true

What's happening now is that in the generated tree editor for the model, I create everything starting from the TopLevelClass. I can successfully create multiple widgets in the WidgetContainer, and I can create a single WidgetReference in the ReferenceContainer and associate it with a specific Widget.

In case anyone runs into this, there is a bug in the generated EMF editor code:

When I try to add more than one WidgetReference to the ReferenceContainer, the tree editor only shows the first WidgetReference under the ReferenceContainer. If I click on the WidgetReferences item in the tree, it does show multiple WidgetReferences in the properties view. It just won't let me see them in the tree, and therefore won't let me select them to change their reference to associate it to an actual widget.

The workaround to this is to create as many references as you need, save and close the model, and then re-open it. Upon re-opening it, all of the references will be shown.

Thanks for any help/guidance.

Jeff

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

吹梦到西洲 2024-10-08 11:37:03

我认为你的问题的答案与“遏制”的概念有关。任何对子对象具有包含引用(EMF 元模型中的 containment=true)的父对象都会管理该子对象的生命周期。因此,当创建子对象时,父对象会自动引用该对象。如果引用不是包含类型 (containment=false),则您可以将该引用指向正确类型的任何现有模型对象。我认为您需要将引用设置为containment=false。

我没有使用过 Acceleo,所以让我们使用 EMF 树编辑器作为示例(这个概念也适用于 GMF 编辑器): 在树编辑器中,如果父对象具有对子对象的包含引用,则用户能够创建通过右键单击父对象并选择“new-->child-->ChildObject”来创建子对象。如果对子对象的引用不是包含类型,则用户将能够通过单击父对象的属性窗口中的相应子属性来选择模型中已存在的该对象的实例。

这有帮助吗?如果此描述令人困惑,那么创建带有一些非包含引用的玩具模型并为其生成 EMF 编辑器可能会有所帮助。

I think the answer to your question is related to the idea of "containment." Any parent object which has a containment reference (containment=true in the EMF metamodel) to a child object manages the lifecycle of that child. So when the child is created, the parent's reference to that object is made automatically. If the reference is not of type containment (containment=false), then you can point the reference to any existing model object of the correct type. I think you need to set your reference as containment=false.

I have not used Acceleo so let's use the EMF tree editor as an example (the concept also applies to the GMF editior): In the tree editor, if the parent object has a containment reference to a child, the user is able to create the child by right-clicking the parent and choosing "new-->child-->ChildObject." If the reference to the child is NOT of type containment , the user will be able to choose instances of that object that already exist in the model by clicking the appropriate child property in the properties window of the parent object.

Does that help? If this description is confusing, it may help to create a toy model with some non-containment references and generate the EMF editor for it.

薄荷→糖丶微凉 2024-10-08 11:37:03

我不确定 EMF 中模型之间引用的概念是否是您所描述的内容。但是,在一个模型中,您可以引用其他模型中的元素。在创建模型实例的通用 EMF 编辑器中,您可以单击右键,然后选择“加载资源...”。该新资源可以是与您的模型相关的任何其他模型(您的元模型引用其他模型的元模型)。

您也可以在元模型级别实现这一点。在图形化的 Ecore 编辑器中,您可以从其他元模型中拖放类。他们将保持同步。

不过,我不确定这是否是您所要求的。

I'm not sure the concept of referencing between models in EMF is what you describe. However, in a model you do can reference elements in other models. In the Generic EMF editor with you create model instances, you can click the right button and then select "Load Resource...". That new resource can be any other model that is related to your model (your metamodel references the other model's metamodel).

You can to that as well at the meta-model level. In the graphical Ecore editor, you can drag and drop classes from other metamodels. They will keep in synch.

I'm not sure, however, if this is what you're asking.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文