Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Programmatically add an element to the reference list
Programmatically add an element to the reference list [message #479314] Mon, 10 August 2009 16:37
Nikola Milikic is currently offline Nikola MilikicFriend
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
Previous Topic:GMF 2.2 Validation with former oAW Check Language
Next Topic:additional properties tab only for certain elements
Goto Forum:
  


Current Time: Thu Sep 19 18:26:37 GMT 2024

Powered by FUDForum. Page generated in 0.80974 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top