Programmatically add an element to the reference list [message #479314] |
Mon, 10 August 2009 16:37 |
Nikola Milikic Messages: 10 Registered: July 2009 |
Junior Member |
|
|
Hi,
I know there have been some similar questions, but I didn't find them
helpful for my case.
I have class A that can "include" one or more other instances of class A.
In code, the relationship is represented as EList<B>. I want when in my
editor I create connection "include" from instance A1 to A2 (which will
automatically add A2 to A1's includes list) to programmatically add A1 do
A2's includes list.
My question is where to put a code for this?
I suppose that I must use SetRequest for this. And since SetRequest sets
value of domain element's structural feature, and I need just to add
element to a list, I though to do something like this:
public void updateInclude(AEditFeature source, AEditFeature target){
A targetA = (A) target.resolveSemanticElement();
A sourceA = (A) source.resolveSemanticElement();
EList<A> oldIncludess = targetA.getIncludes();
EList<A> newIncludes= new BasicEList<A>();
for (Iterator<A> iterator = oldExcludes.iterator();
iterator.hasNext();) {
newExcludes.add(iterator.next());
}
newExcludes.add(sourceA);
SetRequest reqSet = new SetRequest(target.getEditingDomain(),targetA,
XXXPackage.eINSTANCE.getA_Includes(), newExcludes);
SetValueCommand operation = new SetValueCommand(reqSet);
target.getDiagramEditDomain().getDiagramCommandStack().execu te(new
ICommandProxy(operation));
}
Can anyone tell me is this the right way of doing this.
I appreciate your help,
Nikola
|
|
|
Powered by
FUDForum. Page generated in 0.80974 seconds