Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » [SOLVED] Create child nodes automatically when parent is created
[SOLVED] Create child nodes automatically when parent is created [message #787320] Tue, 31 January 2012 12:55 Go to next message
Iban Ayestaran is currently offline Iban AyestaranFriend
Messages: 58
Registered: September 2011
Member
Hello,

I want to create automatically a child node 'Trigger' when I define a node 'task', so I customized my TaskCreateCommand as follows:

/**
 * @generated NOT
 */
protected CommandResult doExecuteWithResult(IProgressMonitor monitor,
		IAdaptable info) throws ExecutionException {
	GioLike.Task newElement = GioLike.GioLikeFactory.eINSTANCE.createTask();

	GioLike.FIMode childHolder = (GioLike.FIMode) getElementToEdit();
	childHolder.getTasks().add(newElement);

	//custom code:	
	GioLike.Trigger newTrigger = GioLike.GioLikeFactory.eINSTANCE.createTrigger();
	newElement.setTrigger(newTrigger);
	
	doConfigure(newElement, monitor, info);

	((CreateElementRequest) getRequest()).setNewElement(newElement);
	return CommandResult.newOKCommandResult(newElement);
}


In principle it seems to work , because it creates the trigger inside the Task. However, when I save the diagram the trigger is not saved, so when I close and open the diagram it has dissapeared.

Does anybody know what am I doing wrong?

[Updated on: Wed, 01 February 2012 13:07]

Report message to a moderator

Re: Create child nodes automatically when parent is created [message #787368 is a reply to message #787320] Tue, 31 January 2012 13:56 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33218
Registered: July 2009
Senior Member
Iban,

Comments below.

On 31/01/2012 1:55 PM, Iban Mising name wrote:
> Hello,
>
> I want to create automatically a child node 'Trigger' when I define a
> node 'task', so I customized my TaskCreateCommand as follows:
>
> /**
> * @generated NOT
> */
> protected CommandResult doExecuteWithResult(IProgressMonitor monitor,
> IAdaptable info) throws ExecutionException {
> GioLike.Task newElement =
> GioLike.GioLikeFactory.eINSTANCE.createTask();
Are you using GioLike as an EPackage name? Using upper case letters in
package names is a bad idea.
>
> GioLike.FIMode childHolder = (GioLike.FIMode) getElementToEdit();
> childHolder.getTasks().add(newElement);
>
> //custom code:
> GioLike.Trigger newTrigger =
> GioLike.GioLikeFactory.eINSTANCE.createTrigger();
> newElement.setTrigger(newTrigger);
Is the Task.trigger a containment reference? This Trigger instance
will need to be contained somewhere if not here.
>
> doConfigure(newElement, monitor, info);
>
> ((CreateElementRequest) getRequest()).setNewElement(newElement);
> return CommandResult.newOKCommandResult(newElement);
> }
>
> In principle it seems to work , because it creates the trigger inside
> the Task. However, when I save the diagram the trigger is not saved,
> so when I close and open the diagram it has dissapeared.
>
> Does anybody know what am I doing wrong?


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Create child nodes automatically when parent is created [message #787442 is a reply to message #787368] Tue, 31 January 2012 15:33 Go to previous messageGo to next message
Iban Ayestaran is currently offline Iban AyestaranFriend
Messages: 58
Registered: September 2011
Member
Ok, I changed 'GioLike' into 'giolike', I didn´t know that could be a source of problems.
And yes, the Trigger is a containment reference of Task. How can I define it then?
Thanks in advance!
Re: Create child nodes automatically when parent is created [message #787511 is a reply to message #787442] Tue, 31 January 2012 17:04 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33218
Registered: July 2009
Senior Member
Iban,

I wouldn't expect a contained object not to be saved if the thing that
contains it is properly saved. Can you tell if the Task appears in the
XML and there isn't a nested element corresponding to the Trigger being
saved?


On 31/01/2012 4:33 PM, Iban Mising name wrote:
> Ok, I changed 'GioLike' into 'giolike', I didn´t know that could be a
> source of problems.
> And yes, the Trigger is a containment reference of Task. How can I
> define it then?
> Thanks in advance!


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Create child nodes automatically when parent is created [message #788019 is a reply to message #787320] Wed, 01 February 2012 08:52 Go to previous messageGo to next message
Ralph Gerbig is currently offline Ralph GerbigFriend
Messages: 702
Registered: November 2009
Senior Member
Hi,

did you try to realize this scenario via the gmfmap model? There you can use FeatureSeqInitializer together with ReferenceNewElementSpec.

Ralph
Re: Create child nodes automatically when parent is created [message #788075 is a reply to message #788019] Wed, 01 February 2012 10:19 Go to previous messageGo to next message
Iban Ayestaran is currently offline Iban AyestaranFriend
Messages: 58
Registered: September 2011
Member
Hi both,
I still haven´t fixed the problem.
When I save the diagram file, triggers do appear in the diagram file, but they do not appear in the XML model file!! And if I close the diagram file and open it again, they have disapeared also in the diagram file. It is very strange, isn´t it?

I also tried the FeatureSeqInitializer as Ralph suggested, but it doesn´t work either. Does what I did:
- Node Mapping <Task/Task>
---- Feature Seq Initializer <Task(trigger)>
------- Reference New Element Spec <trigger:=new Trigger[1]>
---------- Feature Seq Initializer<new Trigger()>

The result in this second case is exactly the same as in the first one (modifying code by hand).

Can anybody help me?

[Updated on: Wed, 01 February 2012 10:19]

Report message to a moderator

Re: Create child nodes automatically when parent is created [message #788185 is a reply to message #788075] Wed, 01 February 2012 13:07 Go to previous message
Iban Ayestaran is currently offline Iban AyestaranFriend
Messages: 58
Registered: September 2011
Member
I got it!!
The problem was not the code. The thing is that the relationship 'trigger' was set to 'Transient = true' in my ecore file. So I changed it to false and it works.
So I will set the topic as solved.
Thanks!!

[Updated on: Wed, 01 February 2012 13:07]

Report message to a moderator

Previous Topic:Cloning / Duplicating nodes
Next Topic:[solved]How get and set features values on drag and drop ?
Goto Forum:
  


Current Time: Wed Sep 25 17:56:55 GMT 2024

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

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

Back to the top