Home » Modeling » EMF » Where is the add (to a list) method?
|
Re: Where is the add (to a list) method? [message #421865 is a reply to message #421864] |
Fri, 15 August 2008 09:20 |
Eclipse User |
|
|
|
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 |
Marc Moser 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 #421872 is a reply to message #421869] |
Fri, 15 August 2008 11:49 |
Christophe Bouhier 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 |
Ed Merks Messages: 33152 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 |
Christophe Bouhier 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
|
|
|
Goto Forum:
Current Time: Mon May 27 01:39:10 GMT 2024
Powered by FUDForum. Page generated in 0.04018 seconds
|