[SOLVED] Create child nodes automatically when parent is created [message #787320] |
Tue, 31 January 2012 12:55 |
Iban Ayestaran 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 |
Ed Merks 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 #788075 is a reply to message #788019] |
Wed, 01 February 2012 10:19 |
Iban Ayestaran 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
|
|
|
|
Powered by
FUDForum. Page generated in 0.03771 seconds