Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » Is it possible to modify/delete an eReference from an EObject?
Is it possible to modify/delete an eReference from an EObject? [message #755636] Wed, 09 November 2011 07:49 Go to next message
Theo Andersen is currently offline Theo AndersenFriend
Messages: 3
Registered: November 2011
Junior Member
I'm working on a project were i need to modify/delete an eReference (or other EStructuralFeature's) from an EObject?

Im able to find an eReference from the EObjects eClass, but using this i don't seem to be able to remove the eReference from the eObject or modify it in any way.

It dosen't exist in the eContents, and using eGet() with the eReference found from the eClass i get a dynamic list of the EObject the reference points to, and not the reference it self.

Is it at all possible to modify or delete an eReference from an EObject?

How would i go about doing this?

I'm having difficulties finding details on this in the ecore api documentation.

Thanks Smile

/Theo
Re: Is it possible to modify/delete an eReference from an EObject? [message #755643 is a reply to message #755636] Wed, 09 November 2011 08:15 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Theo,

Comments below.

On 09/11/2011 8:49 AM, Theo Andersen wrote:
> I'm working on a project were i need to modify/delete an eReference
> (or other EStructuralFeature's) from an EObject?
>
> Im able to find an eReference from the EObjects eClass, but using this
> i don't seem to be able to remove the eReference from the eObject or
> modify it in any way.
You mean via eSet?
>
> It dosen't exist in the eContents,
Is it a containment reference? A cross reference will appear in
eCrossReferences().
> and using eGet() with the eReference found from the eClass i get a
> dynamic list of the EObject the reference points to, and not the
> reference it self.
If it's multi-valued, you use eGet to get the list and then you can use
remove on the list itself.
>
> Is it at all possible to modify or delete an eReference from an EObject?
Of course. How would the generated editor be able to support delete
without it?
>
> How would i go about doing this?
>
> I'm having difficulties finding details on this in the ecore api
> documentation.
I assume you're trying to use reflection. Have a look at
EcoreUtil.remove to get the idea.
>
> Thanks :)
>
> /Theo


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Is it possible to modify/delete an eReference from an EObject? [message #755880 is a reply to message #755643] Wed, 09 November 2011 23:58 Go to previous messageGo to next message
Theo Andersen is currently offline Theo AndersenFriend
Messages: 3
Registered: November 2011
Junior Member
Thanks for the response.

My example has got an object with a containment reference which has got 4 objects. But when looking at the parent object, it's got 0 items in the eCrossRefernces EList.

If i use eGet with the reference i can find from the eClass, i get a List of EObjects with 4 elements.. the four elements are the elements which the parent contains.
I can remove an item from this list fine using Ecoreutil, but it fails when i try to use eSet(eRef, newListWithElementRemoved) with "Could not find object in the basemodel".

Is there any reason my EObject would have no items in the eCrossReferences, if thats where the containment-references are supposed to be?

Does anybody know why i can eGet an eReference, but it can't find it when i try to eSet it?

Is there any examples / documentation about these things that make it more clear?

Thanks a lot for the help
/Theo
Re: Is it possible to modify/delete an eReference from an EObject? [message #755919 is a reply to message #755880] Thu, 10 November 2011 08:06 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Theo,

Comments below.

On 10/11/2011 12:58 AM, Theo Andersen wrote:
> Thanks for the response.
>
> My example has got an object with a containment reference which has
> got 4 objects. But when looking at the parent object,
I.e., the object that has a containment reference with 4 things in it?
It should have those four things in the eContents().
> it's got 0 items in the eCrossRefernces EList.
>
> If i use eGet with the reference i can find from the eClass, i get a
> List of EObjects with 4 elements.. the four elements are the elements
> which the parent contains.
So those should also appear in the eContents() given they're in the
containment reference...
> I can remove an item from this list fine using Ecoreutil, but it fails
> when i try to use eSet(eRef, newListWithElementRemoved) with "Could
> not find object in the basemodel".
I don't recognize that error message? Of course when you call
eObject.eSet(eRef,...) it must typically be the case that
eObject.eClass().getEAllStructuralFeatures().contains(eRef)...
>
> Is there any reason my EObject would have no items in the
> eCrossReferences,
If there are no non-containment references you'd not expect any...
> if thats where the containment-references are supposed to be?
No, the containment ones appear in the eContents().
>
> Does anybody know why i can eGet an eReference, but it can't find it
> when i try to eSet it?
Of course you're doing something not quite right, but without code,
stack traces, or other details, one can only guess...
>
> Is there any examples / documentation about these things that make it
> more clear?
Is it clear what EcoreUtil.remove is doing? The code is very simple.
Did you understand what I meant about fetching the list and modifying
the list (as EcoreUtil.remove does in the isMany case)?
>
> Thanks a lot for the help
> /Theo


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Is it possible to modify/delete an eReference from an EObject? [message #756102 is a reply to message #755919] Thu, 10 November 2011 22:17 Go to previous messageGo to next message
Theo Andersen is currently offline Theo AndersenFriend
Messages: 3
Registered: November 2011
Junior Member
Hi again.

Thanks for the comments. I'm sorry but i'm not allowed to disclose the code at this time, but i greatly appreciate the help in understanding the api.

I've now managed to understand, and use eGet and eSet on a reference look an manipulate the object on which it points. By using this list of eObjects (the one i get when using eGet(eReference)) and then using eSet(), i can change how many objects the reference points to. (notice that i do not want to remove the objects, as other references in the meta-model might still need them).

Another similar issue is with wanting to not only reset a structuralFeature which is a slot on an object to its default value, but entirely remove the slot (structural feature) from the list.

Is there a way i can remove a particular structural feature from an eObject, and not just the value which it holds (referenced objects with references, or ex. an 'int' if its a slot containing an int).
Or is it only possibly to modify the contents of the structural features on eObjects?

Thanks
/Theo
Re: Is it possible to modify/delete an eReference from an EObject? [message #756129 is a reply to message #756102] Fri, 11 November 2011 06:58 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Theo,

Comments below.

On 10/11/2011 11:17 PM, Theo Andersen wrote:
> Hi again.
>
> Thanks for the comments. I'm sorry but i'm not allowed to disclose the
> code at this time, but i greatly appreciate the help in understanding
> the api.
>
> I've now managed to understand, and use eGet and eSet on a reference
> look an manipulate the object on which it points. By using this list
> of eObjects (the one i get when using eGet(eReference)) and then using
> eSet(),
Note that you don't generally need to use eSet for multi-valued
features. Changing the list is all that's needed.
> i can change how many objects the reference points to. (notice that i
> do not want to remove the objects, as other references in the
> meta-model might still need them).
>
> Another similar issue is with wanting to not only reset a
> structuralFeature which is a slot on an object to its default value,
> but entirely remove the slot (structural feature) from the list.
I'm having a hard time parsing this. Structural features are part of
the Ecore model but you use the term here as if it were data actually in
a multi-valued feature's list in your instance...
>
> Is there a way i can remove a particular structural feature from an
> eObject, and not just the value which it holds (referenced objects
> with references, or ex. an 'int' if its a slot containing an int).
If I'm understanding the question correctly, no, you can't modify the
Ecore model for existing instances.
> Or is it only possibly to modify the contents of the structural
> features on eObjects?
Yes, it's only possible to edit the instances, not the model that
describes their structure. (Just as in Java, you can't just add or
remove fields from classes at runtime and still have things continue to
work.)
>
> Thanks
> /Theo


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:[Edapt]
Next Topic:[EMF] Inheritance across two ecore-files
Goto Forum:
  


Current Time: Fri Mar 29 15:08:39 GMT 2024

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

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

Back to the top