Index of model element with in a container [message #1779432] |
Sun, 07 January 2018 18:49 |
Manoj Keshavaprakash Messages: 4 Registered: October 2017 |
Junior Member |
|
|
Hi,
I am working on EMF for a couple of months now. I have a small concern regarding the index of the element position within a container.
Eg.
Company ABC
-------Employee 1
-------Employee 2
Now I want to know the index of Employee 2. I am working on a scenario of handling the movement of elements within a container and I need to know the index of the element to capture the move.
Appreciate your help in advance.
Regards,
Manoj
[Updated on: Sun, 07 January 2018 18:50] Report message to a moderator
|
|
|
Re: Index of model element with in a container [message #1779442 is a reply to message #1779432] |
Mon, 08 January 2018 05:03 |
Ed Merks Messages: 33142 Registered: July 2009 |
Senior Member |
|
|
Assuming there are no feature maps involved in the model, then for any EObject x, if x.eContainer() != null && x.eContainerFeature() .isMany() you can get the index via ((List<?>)x.eContainer().eGet(x.eContainmentFeature())).indexOf(x) to compute its index within the container's containment feature that contains the object. Note that a move notification has the information about the old and the new index of any moves you might do...
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Powered by
FUDForum. Page generated in 0.03168 seconds