How to create a new EMF child object (that is properly linked into the model)? [message #428107] |
Tue, 10 March 2009 17:37  |
Eclipse User |
|
|
|
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 17:47   |
Eclipse User |
|
|
|
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 #428155 is a reply to message #428109] |
Wed, 11 March 2009 17:27   |
Eclipse User |
|
|
|
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] |
Wed, 11 March 2009 20:34  |
Eclipse User |
|
|
|
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?
>>
|
|
|
Powered by
FUDForum. Page generated in 0.12990 seconds