Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » How to create a new EMF child object (that is properly linked into the model)?
How to create a new EMF child object (that is properly linked into the model)? [message #428107] Tue, 10 March 2009 21:37 Go to next message
Kyle is currently offline KyleFriend
Messages: 16
Registered: July 2009
Junior Member
I have an object that is JobListType and I want to create another
object that is JobType and get it properly inserted in my EMF model
with the JobListType object as its parent.

In the example below, my model is called TestExplorer, and "object" is
of type JobListTypeImpl

// get the adapter factory
TestExplorerItemProviderAdapterFactory af =

(TestExplorerItemProviderAdapterFactory)adapterFactory.getFa ctoryForType(object);

// get the item provider
JobListTypeItemProvider ip =
(JobListTypeItemProvider)af.createJobListTypeAdapter();

// create the new JobType item
JobType newJobFile = TestExplorerFactory.eINSTANCE.createJobType();
I see that this just created a new item, but did not make "object" its
parent. How do I get object associated with it? I searched around
and found commands like CreateChildAction and CreateChildCommand, but
I couldn't find any examples of how they are used--and it was asking
for a bunch of parameters I didn't know how to fill in.

There must be a simple way to create a new child object from another
object--could someone point me in the right direction?
Re: How to create a new EMF child object (that is properly linked into the model)? [message #428109 is a reply to message #428107] Tue, 10 March 2009 21:47 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
Kyle,

Comments below.


Kyle J Nolan wrote:
> I have an object that is JobListType and I want to create another
> object that is JobType and get it properly inserted in my EMF model
> with the JobListType object as its parent.
>
> In the example below, my model is called TestExplorer, and "object" is
> of type JobListTypeImpl
>
> // get the adapter factory
> TestExplorerItemProviderAdapterFactory af =
>
> (TestExplorerItemProviderAdapterFactory)adapterFactory.getFa ctoryForType(object);
>
object is an instance? I'm not sure this makes sense...
> // get the item provider
> JobListTypeItemProvider ip =
> (JobListTypeItemProvider)af.createJobListTypeAdapter();
>
Hmmm.
> // create the new JobType item
> JobType newJobFile = TestExplorerFactory.eINSTANCE.createJobType();
> I see that this just created a new item, but did not make "object" its
> parent.
Of course not. The create method creates a blank new object that's not
related in any way to any other objects, yet.
> How do I get object associated with it?
Is there some object.getJobs().add(newJobFile) you can use?
> I searched around
> and found commands like CreateChildAction and CreateChildCommand, but
> I couldn't find any examples of how they are used--and it was asking
> for a bunch of parameters I didn't know how to fill in.
>
It's odd that you seem to be mixing the EMF Edit stuff with the basic
model manipulation stuff....
> There must be a simple way to create a new child object from another
> object--could someone point me in the right direction?
>
I'd expect that object, being of type job list would have a getJobs()
method that returns a list and that you could add a newJobFile to it.
Of course in the generated editor, you'd have the option to create a new
child job for it, right?


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: How to create a new EMF child object (that is properly linked into the model)? [message #428155 is a reply to message #428109] Wed, 11 March 2009 21:27 Go to previous messageGo to next message
Kyle is currently offline KyleFriend
Messages: 16
Registered: July 2009
Junior Member
Thanks,

It looks like using the following does what I wanted:

((JobListTypeImpl)object).getJob().add(newJobFile);


On Tue, 10 Mar 2009 17:47:44 -0400, Ed Merks <Ed.Merks@gmail.com>
wrote:

>Kyle,
>
>Comments below.
>
>
>Kyle J Nolan wrote:
>> I have an object that is JobListType and I want to create another
>> object that is JobType and get it properly inserted in my EMF model
>> with the JobListType object as its parent.
>>
>> In the example below, my model is called TestExplorer, and "object" is
>> of type JobListTypeImpl
>>
>> // get the adapter factory
>> TestExplorerItemProviderAdapterFactory af =
>>
>> (TestExplorerItemProviderAdapterFactory)adapterFactory.getFa ctoryForType(object);
>>
>object is an instance? I'm not sure this makes sense...
>> // get the item provider
>> JobListTypeItemProvider ip =
>> (JobListTypeItemProvider)af.createJobListTypeAdapter();
>>
>Hmmm.
>> // create the new JobType item
>> JobType newJobFile = TestExplorerFactory.eINSTANCE.createJobType();
>> I see that this just created a new item, but did not make "object" its
>> parent.
>Of course not. The create method creates a blank new object that's not
>related in any way to any other objects, yet.
>> How do I get object associated with it?
>Is there some object.getJobs().add(newJobFile) you can use?
>> I searched around
>> and found commands like CreateChildAction and CreateChildCommand, but
>> I couldn't find any examples of how they are used--and it was asking
>> for a bunch of parameters I didn't know how to fill in.
>>
>It's odd that you seem to be mixing the EMF Edit stuff with the basic
>model manipulation stuff....
>> There must be a simple way to create a new child object from another
>> object--could someone point me in the right direction?
>>
>I'd expect that object, being of type job list would have a getJobs()
>method that returns a list and that you could add a newJobFile to it.
>Of course in the generated editor, you'd have the option to create a new
>child job for it, right?
Re: How to create a new EMF child object (that is properly linked into the model)? [message #428158 is a reply to message #428155] Thu, 12 March 2009 00:34 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
Kyle,

Remove the Impl

Kyle J Nolan wrote:
> Thanks,
>
> It looks like using the following does what I wanted:
>
> ((JobListTypeImpl)object).getJob().add(newJobFile);
>
>
> On Tue, 10 Mar 2009 17:47:44 -0400, Ed Merks <Ed.Merks@gmail.com>
> wrote:
>
>
>> Kyle,
>>
>> Comments below. f
>>
>>
>> Kyle J Nolan wrote:
>>
>>> I have an object that is JobListType and I want to create another
>>> object that is JobType and get it properly inserted in my EMF model
>>> with the JobListType object as its parent.
>>>
>>> In the example below, my model is called TestExplorer, and "object" is
>>> of type JobListTypeImpl
>>>
>>> // get the adapter factory
>>> TestExplorerItemProviderAdapterFactory af =
>>>
>>> (TestExplorerItemProviderAdapterFactory)adapterFactory.getFa ctoryForType(object);
>>>
>>>
>> object is an instance? I'm not sure this makes sense...
>>
>>> // get the item provider
>>> JobListTypeItemProvider ip =
>>> (JobListTypeItemProvider)af.createJobListTypeAdapter();
>>>
>>>
>> Hmmm.
>>
>>> // create the new JobType item
>>> JobType newJobFile = TestExplorerFactory.eINSTANCE.createJobType();
>>> I see that this just created a new item, but did not make "object" its
>>> parent.
>>>
>> Of course not. The create method creates a blank new object that's not
>> related in any way to any other objects, yet.
>>
>>> How do I get object associated with it?
>>>
>> Is there some object.getJobs().add(newJobFile) you can use?
>>
>>> I searched around
>>> and found commands like CreateChildAction and CreateChildCommand, but
>>> I couldn't find any examples of how they are used--and it was asking
>>> for a bunch of parameters I didn't know how to fill in.
>>>
>>>
>> It's odd that you seem to be mixing the EMF Edit stuff with the basic
>> model manipulation stuff....
>>
>>> There must be a simple way to create a new child object from another
>>> object--could someone point me in the right direction?
>>>
>>>
>> I'd expect that object, being of type job list would have a getJobs()
>> method that returns a list and that you could add a newJobFile to it.
>> Of course in the generated editor, you'd have the option to create a new
>> child job for it, right?
>>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Children or real containment
Next Topic:[teneo] is it easy to add @CacheSize hibernate annotation feature
Goto Forum:
  


Current Time: Tue Apr 16 11:20:02 GMT 2024

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

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

Back to the top