Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Create Child programmatically
Create Child programmatically [message #486007] Tue, 15 September 2009 21:19 Go to next message
Artur Kronenberg is currently offline Artur KronenbergFriend
Messages: 159
Registered: August 2009
Senior Member
Hi,

I have the following problem:

I created an EMF editor that is handeling a specific task in itself. As
soon as the element is created (through mouseclicking) the editor
synchronizes perfectly and everything works just fine.

The problem is, that I need the Child created programmatically by a right
click on my gmf editor.

I have no problem getting the name for the child Element. I know I can
create a child element with my FactoryImpl.createChildElement() and set
the name on the returned object.
But how can I add the element to the model of the EMF editor so it gets
updated, undo is supported and so on..

basically I try to use the action that is give through the UI by
rightclicking on a node, creating a child but only programmatically.

Is there a way to do that?

Best regards,
Artur
Re: Create Child programmatically [message #486034 is a reply to message #486007] Wed, 16 September 2009 02:57 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Artur,

You could use CreateChildCommand and execute it on the command stack.
Or just use an AddCommand directly (also executing it on the command stack).


Artur Kronenberg wrote:
> Hi,
>
> I have the following problem:
>
> I created an EMF editor that is handeling a specific task in itself.
> As soon as the element is created (through mouseclicking) the editor
> synchronizes perfectly and everything works just fine.
>
> The problem is, that I need the Child created programmatically by a
> right click on my gmf editor.
>
> I have no problem getting the name for the child Element. I know I can
> create a child element with my FactoryImpl.createChildElement() and
> set the name on the returned object. But how can I add the element to
> the model of the EMF editor so it gets updated, undo is supported and
> so on..
>
> basically I try to use the action that is give through the UI by
> rightclicking on a node, creating a child but only programmatically.
>
> Is there a way to do that?
> Best regards,
> Artur
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Create Child programmatically [message #486142 is a reply to message #486034] Wed, 16 September 2009 13:47 Go to previous messageGo to next message
Artur Kronenberg is currently offline Artur KronenbergFriend
Messages: 159
Registered: August 2009
Senior Member
Hi Ed,

thank you for your fast reply. I tried using the CreateChildrenCommand by
getting a command from the AdapterFactoryEditingDomain but it somehow did
not work out for me. I don't quite get how to use those commands exactly
to achieve what I need.

If I would use the
AdapterFactoryEditingDomain.createCinnabd(CreateChildCommand .class, new
CommandParameters(owner, feature, collection<?>) what would be the
parameters for the CommandParameters.

I have my Editor and therefor I could access everything in it. I still
couldn't figure out how to get the owner for my new object (i supposed
this should be the parent node?) If I thate the resourceset from my editor
and iterate through its contents then I can get my rootNodeImpl and get
all the childNodes and find out where to put my new created node, but this
seems to be kind of a weird way to achieve this?

Also, what would be the feature atribute I would have to set there? From
debuggin I think the collection I have to pass the commandParameters I can
get by calling getNewChildDescriptors from my editingDomain?

Thank you for your help.

Best regards,
Artur

Ed Merks wrote:

> Artur,

> You could use CreateChildCommand and execute it on the command stack.
> Or just use an AddCommand directly (also executing it on the command stack).


> Artur Kronenberg wrote:
>> Hi,
>>
>> I have the following problem:
>>
>> I created an EMF editor that is handeling a specific task in itself.
>> As soon as the element is created (through mouseclicking) the editor
>> synchronizes perfectly and everything works just fine.
>>
>> The problem is, that I need the Child created programmatically by a
>> right click on my gmf editor.
>>
>> I have no problem getting the name for the child Element. I know I can
>> create a child element with my FactoryImpl.createChildElement() and
>> set the name on the returned object. But how can I add the element to
>> the model of the EMF editor so it gets updated, undo is supported and
>> so on..
>>
>> basically I try to use the action that is give through the UI by
>> rightclicking on a node, creating a child but only programmatically.
>>
>> Is there a way to do that?
>> Best regards,
>> Artur
>>
Re: Create Child programmatically [message #486145 is a reply to message #486142] Wed, 16 September 2009 14:02 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------000408040507020509000606
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Artur,

Probably it's easier to look at using an AddCommand. If you look at the
Javadoc, it shows that an AddCommand will do the equivalent of this:

*
((EList)((EObject)owner).eGet((EStructuralFeature)feature)). addAll(index,
(Collection)collection);

Or in terms of generated code it's equivalent to

owner.getFoo().addAll(listOfFoos).

In the end, you do have to determine which object you're adding stuff
to (the owner), which feature you're adding it to (foo), and what's
being added...


Artur Kronenberg wrote:
> Hi Ed,
>
> thank you for your fast reply. I tried using the CreateChildrenCommand
> by getting a command from the AdapterFactoryEditingDomain but it
> somehow did not work out for me. I don't quite get how to use those
> commands exactly to achieve what I need.
>
> If I would use the
> AdapterFactoryEditingDomain.createCinnabd(CreateChildCommand .class,
> new CommandParameters(owner, feature, collection<?>) what would be the
> parameters for the CommandParameters.
>
> I have my Editor and therefor I could access everything in it. I still
> couldn't figure out how to get the owner for my new object (i supposed
> this should be the parent node?) If I thate the resourceset from my
> editor and iterate through its contents then I can get my rootNodeImpl
> and get all the childNodes and find out where to put my new created
> node, but this seems to be kind of a weird way to achieve this?
> Also, what would be the feature atribute I would have to set there?
> From debuggin I think the collection I have to pass the
> commandParameters I can get by calling getNewChildDescriptors from my
> editingDomain?
> Thank you for your help.
>
> Best regards,
> Artur
>
> Ed Merks wrote:
>
>> Artur,
>
>> You could use CreateChildCommand and execute it on the command
>> stack. Or just use an AddCommand directly (also executing it on the
>> command stack).
>
>
>> Artur Kronenberg wrote:
>>> Hi,
>>>
>>> I have the following problem:
>>>
>>> I created an EMF editor that is handeling a specific task in itself.
>>> As soon as the element is created (through mouseclicking) the editor
>>> synchronizes perfectly and everything works just fine.
>>>
>>> The problem is, that I need the Child created programmatically by a
>>> right click on my gmf editor.
>>>
>>> I have no problem getting the name for the child Element. I know I
>>> can create a child element with my FactoryImpl.createChildElement()
>>> and set the name on the returned object. But how can I add the
>>> element to the model of the EMF editor so it gets updated, undo is
>>> supported and so on..
>>>
>>> basically I try to use the action that is give through the UI by
>>> rightclicking on a node, creating a child but only programmatically.
>>>
>>> Is there a way to do that?
>>> Best regards,
>>> Artur
>>>
>
>

--------------000408040507020509000606
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Artur,<br>
<br>
Probably it's easier to look at using an AddCommand.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Create Child programmatically [message #486155 is a reply to message #486145] Wed, 16 September 2009 14:29 Go to previous messageGo to next message
Artur Kronenberg is currently offline Artur KronenbergFriend
Messages: 159
Registered: August 2009
Senior Member
Ed,

that worked very nice. The AddCommand added my child element to the tree
and set the editor dirty. Also the undo stuff works.

One last question :)

To create the command I need the owner which would be a category Node for
my model. So currently I am doing this to get the owner (which I think is
not the right way):

I get the EMF editor and get the EditingDomain. From the editingDomain I
get the Resourceset and from that I get the resources. Then I iterate
through the resources and find the XMIResourceImpl. After this I iterate
through those contents and find my root node. From that node I get the
owner.

Is there a more sane way of doing this?

Best regards,
Artur

Ed Merks wrote:

> Artur,

> Probably it's easier to look at using an AddCommand. If you look at the
> Javadoc, it shows that an AddCommand will do the equivalent of this:

> *
> ((EList)((EObject)owner).eGet((EStructuralFeature)feature)). addAll(index,
> (Collection)collection);

> Or in terms of generated code it's equivalent to

> owner.getFoo().addAll(listOfFoos).

> In the end, you do have to determine which object you're adding stuff
> to (the owner), which feature you're adding it to (foo), and what's
> being added...


> Artur Kronenberg wrote:
>> Hi Ed,
>>
>> thank you for your fast reply. I tried using the CreateChildrenCommand
>> by getting a command from the AdapterFactoryEditingDomain but it
>> somehow did not work out for me. I don't quite get how to use those
>> commands exactly to achieve what I need.
>>
>> If I would use the
>> AdapterFactoryEditingDomain.createCinnabd(CreateChildCommand .class,
>> new CommandParameters(owner, feature, collection<?>) what would be the
>> parameters for the CommandParameters.
>>
>> I have my Editor and therefor I could access everything in it. I still
>> couldn't figure out how to get the owner for my new object (i supposed
>> this should be the parent node?) If I thate the resourceset from my
>> editor and iterate through its contents then I can get my rootNodeImpl
>> and get all the childNodes and find out where to put my new created
>> node, but this seems to be kind of a weird way to achieve this?
>> Also, what would be the feature atribute I would have to set there?
>> From debuggin I think the collection I have to pass the
>> commandParameters I can get by calling getNewChildDescriptors from my
>> editingDomain?
>> Thank you for your help.
>>
>> Best regards,
>> Artur
>>
>> Ed Merks wrote:
>>
>>> Artur,
>>
>>> You could use CreateChildCommand and execute it on the command
>>> stack. Or just use an AddCommand directly (also executing it on the
>>> command stack).
>>
>>
>>> Artur Kronenberg wrote:
>>>> Hi,
>>>>
>>>> I have the following problem:
>>>>
>>>> I created an EMF editor that is handeling a specific task in itself.
>>>> As soon as the element is created (through mouseclicking) the editor
>>>> synchronizes perfectly and everything works just fine.
>>>>
>>>> The problem is, that I need the Child created programmatically by a
>>>> right click on my gmf editor.
>>>>
>>>> I have no problem getting the name for the child Element. I know I
>>>> can create a child element with my FactoryImpl.createChildElement()
>>>> and set the name on the returned object. But how can I add the
>>>> element to the model of the EMF editor so it gets updated, undo is
>>>> supported and so on..
>>>>
>>>> basically I try to use the action that is give through the UI by
>>>> rightclicking on a node, creating a child but only programmatically.
>>>>
>>>> Is there a way to do that?
>>>> Best regards,
>>>> Artur
>>>>
>>
>>
Re: Create Child programmatically [message #486166 is a reply to message #486155] Wed, 16 September 2009 14:50 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Artur,

It sounds reasonable. You need to traverse to the object from the
resource set, if you have no other way of knowing which object to access....

Artur Kronenberg wrote:
> Ed,
>
> that worked very nice. The AddCommand added my child element to the
> tree and set the editor dirty. Also the undo stuff works.
>
> One last question :)
> To create the command I need the owner which would be a category Node
> for my model. So currently I am doing this to get the owner (which I
> think is not the right way):
>
> I get the EMF editor and get the EditingDomain. From the editingDomain
> I get the Resourceset and from that I get the resources. Then I
> iterate through the resources and find the XMIResourceImpl. After this
> I iterate through those contents and find my root node. From that node
> I get the owner.
>
> Is there a more sane way of doing this?
> Best regards,
> Artur
>
> Ed Merks wrote:
>
>> Artur,
>
>> Probably it's easier to look at using an AddCommand. If you look at
>> the Javadoc, it shows that an AddCommand will do the equivalent of this:
>
>> *
>> ((EList)((EObject)owner).eGet((EStructuralFeature)feature)). addAll(index,
>> (Collection)collection);
>
>> Or in terms of generated code it's equivalent to
>
>> owner.getFoo().addAll(listOfFoos).
>
>> In the end, you do have to determine which object you're adding
>> stuff to (the owner), which feature you're adding it to (foo), and
>> what's being added...
>
>
>> Artur Kronenberg wrote:
>>> Hi Ed,
>>>
>>> thank you for your fast reply. I tried using the
>>> CreateChildrenCommand by getting a command from the
>>> AdapterFactoryEditingDomain but it somehow did not work out for me.
>>> I don't quite get how to use those commands exactly to achieve what
>>> I need.
>>>
>>> If I would use the
>>> AdapterFactoryEditingDomain.createCinnabd(CreateChildCommand .class,
>>> new CommandParameters(owner, feature, collection<?>) what would be
>>> the parameters for the CommandParameters.
>>>
>>> I have my Editor and therefor I could access everything in it. I
>>> still couldn't figure out how to get the owner for my new object (i
>>> supposed this should be the parent node?) If I thate the resourceset
>>> from my editor and iterate through its contents then I can get my
>>> rootNodeImpl and get all the childNodes and find out where to put my
>>> new created node, but this seems to be kind of a weird way to
>>> achieve this?
>>> Also, what would be the feature atribute I would have to set there?
>>> From debuggin I think the collection I have to pass the
>>> commandParameters I can get by calling getNewChildDescriptors from
>>> my editingDomain?
>>> Thank you for your help.
>>>
>>> Best regards,
>>> Artur
>>>
>>> Ed Merks wrote:
>>>
>>>> Artur,
>>>
>>>> You could use CreateChildCommand and execute it on the command
>>>> stack. Or just use an AddCommand directly (also executing it on
>>>> the command stack).
>>>
>>>
>>>> Artur Kronenberg wrote:
>>>>> Hi,
>>>>>
>>>>> I have the following problem:
>>>>>
>>>>> I created an EMF editor that is handeling a specific task in
>>>>> itself. As soon as the element is created (through mouseclicking)
>>>>> the editor synchronizes perfectly and everything works just fine.
>>>>>
>>>>> The problem is, that I need the Child created programmatically by
>>>>> a right click on my gmf editor.
>>>>>
>>>>> I have no problem getting the name for the child Element. I know I
>>>>> can create a child element with my
>>>>> FactoryImpl.createChildElement() and set the name on the returned
>>>>> object. But how can I add the element to the model of the EMF
>>>>> editor so it gets updated, undo is supported and so on..
>>>>>
>>>>> basically I try to use the action that is give through the UI by
>>>>> rightclicking on a node, creating a child but only programmatically.
>>>>>
>>>>> Is there a way to do that?
>>>>> Best regards,
>>>>> Artur
>>>>>
>>>
>>>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Apply EMF Compare Diffs in command stack
Next Topic:xml transformation?
Goto Forum:
  


Current Time: Fri Apr 26 08:42:15 GMT 2024

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

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

Back to the top