Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Where is the add (to a list) method?
Where is the add (to a list) method? [message #421864] Fri, 15 August 2008 08:57 Go to next message
Christophe Bouhier is currently offline Christophe BouhierFriend
Messages: 937
Registered: July 2009
Senior Member
Hi,

Suppose I have a model object with a child attribute which can occur
multiple times. (In .xsd defined with maxOccurs="unbounded"). I can see
a method is generated returning the list EList getMyAttributes() but
where is the add method: addAtrribute(...)?

I am now adding using the "editing domain".getNewChildDescriptors(Object
parent, Object child) and then creating a command. (For UNDO to work, I
guess).

Is it possible to directly write/add in the model and skip the editing
domain? (Would this be the eSet methods?).

Thanks ? Christophe
Re: Where is the add (to a list) method? [message #421865 is a reply to message #421864] Fri, 15 August 2008 09:20 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: un1c0.email.it

Christophe Bouhier wrote:

> Hi,
>
> Suppose I have a model object with a child attribute which can occur
> multiple times. (In .xsd defined with maxOccurs="unbounded"). I can see
> a method is generated returning the list EList getMyAttributes() but
> where is the add method: addAtrribute(...)?
>
> I am now adding using the "editing domain".getNewChildDescriptors(Object
> parent, Object child) and then creating a command. (For UNDO to work, I
> guess).
>
> Is it possible to directly write/add in the model and skip the editing
> domain? (Would this be the eSet methods?).
>
> Thanks ? Christophe

I think the most direct way to add an element to a list attribute is:
someEObject.getMyAttributes().add(objectToAdd)

Roberto Zanon
Re: Where is the add (to a list) method? [message #421866 is a reply to message #421864] Fri, 15 August 2008 09:25 Go to previous messageGo to next message
Marc Moser is currently offline Marc MoserFriend
Messages: 66
Registered: July 2009
Member
Hi,

There is not "addXXX()"-method generated for multi-valued features,
but you can simply use the generated getter and then use the add()
method of the EList.

As an example, if you have a multi-valued feature that is called
"myAttributes", you could write something like:

getMyAttributes().add(attibuteToBeAddedToTheList)

As you noted, things like undo will not work when using this approach.

Best,
Marc

On Fri, 15 Aug 2008 10:57:19 +0200, Christophe Bouhier
<dzonekl@gmail.com> wrote:

>Hi,
>
>Suppose I have a model object with a child attribute which can occur
>multiple times. (In .xsd defined with maxOccurs="unbounded"). I can see
>a method is generated returning the list EList getMyAttributes() but
>where is the add method: addAtrribute(...)?
>
>I am now adding using the "editing domain".getNewChildDescriptors(Object
>parent, Object child) and then creating a command. (For UNDO to work, I
>guess).
>
>Is it possible to directly write/add in the model and skip the editing
>domain? (Would this be the eSet methods?).
>
>Thanks ? Christophe
Re: Where is the add (to a list) method? [message #421869 is a reply to message #421864] Fri, 15 August 2008 11:09 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33147
Registered: July 2009
Senior Member
Christophe,

As others have indicated, for multi-valued features, you can directly
modify the list returned by the getter. There are commands like
AddCommand and RemoveCommand for adding to and removing from lists in an
undoable way and others


Christophe Bouhier wrote:
> Hi,
>
> Suppose I have a model object with a child attribute which can occur
> multiple times. (In .xsd defined with maxOccurs="unbounded"). I can
> see a method is generated returning the list EList getMyAttributes()
> but where is the add method: addAtrribute(...)?
>
> I am now adding using the "editing
> domain".getNewChildDescriptors(Object parent, Object child) and then
> creating a command. (For UNDO to work, I guess).
>
> Is it possible to directly write/add in the model and skip the editing
> domain? (Would this be the eSet methods?).
>
> Thanks ? Christophe


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Where is the add (to a list) method? [message #421872 is a reply to message #421869] Fri, 15 August 2008 11:49 Go to previous messageGo to next message
Christophe Bouhier is currently offline Christophe BouhierFriend
Messages: 937
Registered: July 2009
Senior Member
Thanks everyone, I am actually studying the behaviour when using the
collection.add() or .addAll() methods. In case of the EMF Editor, Is
there a notification fired,
when using these methods? ( I mean, is the change notified to the
Resource, so setModified() is called?) What would be the right way
to also update the associated resource. (Or do I also need to add
explicitly to the Resource).

Cheers / Christophe


Ed Merks wrote:
> Christophe,
>
> As others have indicated, for multi-valued features, you can directly
> modify the list returned by the getter. There are commands like
> AddCommand and RemoveCommand for adding to and removing from lists in an
> undoable way and others
>
>
> Christophe Bouhier wrote:
>> Hi,
>>
>> Suppose I have a model object with a child attribute which can occur
>> multiple times. (In .xsd defined with maxOccurs="unbounded"). I can
>> see a method is generated returning the list EList getMyAttributes()
>> but where is the add method: addAtrribute(...)?
>>
>> I am now adding using the "editing
>> domain".getNewChildDescriptors(Object parent, Object child) and then
>> creating a command. (For UNDO to work, I guess).
>>
>> Is it possible to directly write/add in the model and skip the editing
>> domain? (Would this be the eSet methods?).
>>
>> Thanks ? Christophe
Re: Where is the add (to a list) method? [message #421873 is a reply to message #421872] Fri, 15 August 2008 11:58 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33147
Registered: July 2009
Senior Member
Christophe,

Comments below.

Christophe Bouhier wrote:
> Thanks everyone, I am actually studying the behaviour when using the
> collection.add() or .addAll() methods. In case of the EMF Editor, Is
> there a notification fired,
> when using these methods?
Of course, all changes to features of an EObject produce notifications.
> ( I mean, is the change notified to the Resource, so setModified() is
> called?)
It is if the resource has tracking notification turned on.
> What would be the right way
> to also update the associated resource. (Or do I also need to add
> explicitly to the Resource).
If you add to a containment reference then indirectly your object will
be contained by the resource because EObject.eContainer will become
non-null and EObject.eResource() will ==
EObject.eContainer().eResource(). If you add to a non-containment
reference and the object is not already contained somewhere else then
that object needs to be added either to a resource or to some other
containment reference.
>
> Cheers / Christophe
>
>
> Ed Merks wrote:
>> Christophe,
>>
>> As others have indicated, for multi-valued features, you can directly
>> modify the list returned by the getter. There are commands like
>> AddCommand and RemoveCommand for adding to and removing from lists in
>> an undoable way and others
>>
>>
>> Christophe Bouhier wrote:
>>> Hi,
>>>
>>> Suppose I have a model object with a child attribute which can occur
>>> multiple times. (In .xsd defined with maxOccurs="unbounded"). I can
>>> see a method is generated returning the list EList getMyAttributes()
>>> but where is the add method: addAtrribute(...)?
>>>
>>> I am now adding using the "editing
>>> domain".getNewChildDescriptors(Object parent, Object child) and then
>>> creating a command. (For UNDO to work, I guess).
>>>
>>> Is it possible to directly write/add in the model and skip the
>>> editing domain? (Would this be the eSet methods?).
>>>
>>> Thanks ? Christophe


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Where is the add (to a list) method? [message #421876 is a reply to message #421873] Fri, 15 August 2008 12:23 Go to previous message
Christophe Bouhier is currently offline Christophe BouhierFriend
Messages: 937
Registered: July 2009
Senior Member
Thank you, very helpful!

Ed Merks wrote:
> Christophe,
>
> Comments below.
>
> Christophe Bouhier wrote:
>> Thanks everyone, I am actually studying the behaviour when using the
>> collection.add() or .addAll() methods. In case of the EMF Editor, Is
>> there a notification fired,
>> when using these methods?
> Of course, all changes to features of an EObject produce notifications.
>> ( I mean, is the change notified to the Resource, so setModified() is
>> called?)
> It is if the resource has tracking notification turned on.
>> What would be the right way
>> to also update the associated resource. (Or do I also need to add
>> explicitly to the Resource).
> If you add to a containment reference then indirectly your object will
> be contained by the resource because EObject.eContainer will become
> non-null and EObject.eResource() will ==
> EObject.eContainer().eResource(). If you add to a non-containment
> reference and the object is not already contained somewhere else then
> that object needs to be added either to a resource or to some other
> containment reference.
>>
>> Cheers / Christophe
>>
>>
>> Ed Merks wrote:
>>> Christophe,
>>>
>>> As others have indicated, for multi-valued features, you can directly
>>> modify the list returned by the getter. There are commands like
>>> AddCommand and RemoveCommand for adding to and removing from lists in
>>> an undoable way and others
>>>
>>>
>>> Christophe Bouhier wrote:
>>>> Hi,
>>>>
>>>> Suppose I have a model object with a child attribute which can occur
>>>> multiple times. (In .xsd defined with maxOccurs="unbounded"). I can
>>>> see a method is generated returning the list EList getMyAttributes()
>>>> but where is the add method: addAtrribute(...)?
>>>>
>>>> I am now adding using the "editing
>>>> domain".getNewChildDescriptors(Object parent, Object child) and then
>>>> creating a command. (For UNDO to work, I guess).
>>>>
>>>> Is it possible to directly write/add in the model and skip the
>>>> editing domain? (Would this be the eSet methods?).
>>>>
>>>> Thanks ? Christophe
Previous Topic:xyzItemProviderAdapterFactory
Next Topic:EMF 2.4 and Eclipse 3.3
Goto Forum:
  


Current Time: Sun May 12 16:38:55 GMT 2024

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

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

Back to the top