|
Re: Deleting many eobjects [message #1703827 is a reply to message #1703745] |
Wed, 05 August 2015 08:47 |
Ed Merks Messages: 33217 Registered: July 2009 |
Senior Member |
|
|
Andreas,
I suppose a deleteAll method would be good. Of course one would want it
to be more general without assumptions. What you show below should be
okay given the assumption holds. Of course you'd want to augment the
"remove(eObject);" call to remove all the objects from their container...
On 04/08/2015 5:56 PM, Andreas Graf wrote:
> Dear EMF gurus,
>
> we have the situation that we need to delete more than one element
> from an EMF model with EcoreUtil.delete(). However, we would like to
> avoid that EcoreUtil tries to find the references again for each
> invocation. Since EcoreUtil.delete with boolean flag recursive set to
> true, it seems that the code can handle more than one object.
>
> The idea is to have a custom implementation of EcoreUtil.delete() that
> starts like this:
>
> /**
> * Warning: ASSUMPTION is that all objects are either under the
> same root Object
> * or in the same resource set.
> * * @param eObjects
> * @param recursive
> */
> public static void delete(List<EObject> inList, boolean recursive) {
> if (inList.isEmpty())
> return;
> if (recursive) {
> EObject rootEObject =
> EcoreUtil.getRootContainer(inList.get(0));
> Resource resource = rootEObject.eResource();
>
> Set<EObject> eObjects = new HashSet<EObject>();
> Set<EObject> crossResourceEObjects = new HashSet<EObject>();
> eObjects.addAll(inList);
> for(EObject eObject : inList ) {
> for (@SuppressWarnings("unchecked")
> TreeIterator<InternalEObject> j =
> (TreeIterator<InternalEObject>) (TreeIterator<?>) eObject
> .eAllContents(); j.hasNext();) {
> InternalEObject childEObject = j.next();
> if (childEObject.eDirectResource() != null) {
> crossResourceEObjects.add(childEObject);
> } else {
> eObjects.add(childEObject);
> }
> }
> }
>
> That basically means, not only collecting the descendents of one
> object, but of a list of objects that is being passed as argument.
>
> Am I missing any inner workings of EMF that would break this?
>
> Regards,
>
> Andreas
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Powered by
FUDForum. Page generated in 0.05835 seconds