关于 Eclispe EMF 命令框架工作

发布于 2024-10-16 23:21:26 字数 271 浏览 8 评论 0原文

谁能告诉我如何使用 AddCommand 而不是 `SetCommand" 来执行以下操作。

我有一个这样的类:

class Profile {
    List achievements;
    List grades;
    List extracurrics;
}

现在,假设我需要向此 Profile 对象添加一个成绩对象,如何才能我仅通过使用 AddCommand 来实现此目的

Can any one tell me how to use AddCommand rather than `SetCommand" to do the following.

I have a class like this:

class Profile {
    List achievements;
    List grades;
    List extracurrics;
}

Now, suppose I need to add a grade object to this Profile object,how can I achieve this by using AddCommand only

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

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

发布评论

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

评论(2

╰沐子 2024-10-23 23:21:26

SetCommand基本上用于在EMF模型中设置值,而AddCommand用于在EMF模型中修改集合值,因此一般情况下使用AddCommand应该没有问题。

您可以使用 AddCommand 中的静态创建函数来创建新的 AddCommand:

AddCommand.create(EditingDomain domain, EObject owner, EStructuralFeature feature, java.lang.Object value) 

给定值的说明:

domain: the editing domain your model lives in
owner: element you are doing the modifications to
feature: feature in model, that should be given to you by the EPackage of your model.
         So this case is the Grades list feature
value: the new object you add to the list

add 命令中有许多不同的创建助手,因此如果您需要定义列表索引,也是可行的。

我这里没有运行 EMF,因此我无法提供任何直接来源,但如果这不起作用,请告诉我。

SetCommand is basically used to set values in EMF model, and AddCommand is used to modify collection values inside EMF model, so in general it should not be a problem to use AddCommand.

You can create new AddCommand using static creation function in AddCommand:

AddCommand.create(EditingDomain domain, EObject owner, EStructuralFeature feature, java.lang.Object value) 

Explanation of given values:

domain: the editing domain your model lives in
owner: element you are doing the modifications to
feature: feature in model, that should be given to you by the EPackage of your model.
         So this case is the Grades list feature
value: the new object you add to the list

There are many different create helpers in add command, so if you need to define index to list, it is also doable.

I don't have EMF running here, so I cannot provide any direct sources, but let me know if that didn't do the trick.

丶情人眼里出诗心の 2024-10-23 23:21:26

它应该看起来像这样:

Profile p = ...;
Grade g = ...;
Command add = AddCommand.create(domain,p, YourProfilePackage.Literals.PROFILE__GRADES, Collections.singleton(g));

YourProfilePackage 应该位于从 EMF 模型自动生成的代码中。

It should look something like this:

Profile p = ...;
Grade g = ...;
Command add = AddCommand.create(domain,p, YourProfilePackage.Literals.PROFILE__GRADES, Collections.singleton(g));

where YourProfilePackage should be in the code generated automatically from your EMF model.

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