开发者

Regarding Eclispe EMF Command Frame WorK

开发者 https://www.devze.com 2023-02-09 14:01 出处:网络
Can an开发者_开发问答y one tell me how to use AddCommand rather than `SetCommand\" to do the following.

Can an开发者_开发问答y 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


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消