Regarding Eclispe EMF Command Frame WorK

492 Views Asked by At

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

2

There are 2 best solutions below

0
On BEST ANSWER

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
On

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.