diff options
| author | Mickael LANOE | 2015-03-24 14:28:39 +0000 |
|---|---|---|
| committer | Pierre-Charles David | 2015-04-14 08:39:33 +0000 |
| commit | 8c5caf0cf3e82e8820afa597e3f6aade21e8e9ae (patch) | |
| tree | ac3065722398733a30ffa114bbc4d41029e62adf | |
| parent | e74bd1221bfe814bf556dc4f3e913fae45e5f689 (diff) | |
| download | org.eclipse.sirius-8c5caf0cf3e82e8820afa597e3f6aade21e8e9ae.tar.gz org.eclipse.sirius-8c5caf0cf3e82e8820afa597e3f6aade21e8e9ae.tar.xz org.eclipse.sirius-8c5caf0cf3e82e8820afa597e3f6aade21e8e9ae.zip | |
[458822] Do not remove the cross referencer on already attached element
Avoid removing the cross referencer on elements that are already
attached to another containers with the same adapter.
Indeed, the removal or the addition of the cross referencer performs a
full iteration through the content of the element.
Bug: 458822
Change-Id: I77071bda520936c1cd917d6bf7c89699087ac407
Signed-off-by: Mickael LANOE <mickael.lanoe@obeo.fr>
| -rw-r--r-- | plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/util/LazyCrossReferencer.java | 36 |
1 files changed, 31 insertions, 5 deletions
diff --git a/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/util/LazyCrossReferencer.java b/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/util/LazyCrossReferencer.java index 519c89ea8d..516dbd17d4 100644 --- a/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/util/LazyCrossReferencer.java +++ b/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/util/LazyCrossReferencer.java @@ -25,7 +25,9 @@ import com.google.common.collect.Iterables; * <BR> * This cross referencer also reacts to {@link EObject} removal from their * containing reference : it removes itself automatically from their adapters - * and recursively from those of their contents. <BR> + * and recursively from those of their contents. If the new container is already + * set and also has the cross referencer, in this case cross referencer is not + * removed. <BR> * <BR> * This cross referencer also provide a way to disable the resolution of proxy. * This can be useful to avoid reloading of a resource during the unloading of @@ -39,6 +41,7 @@ import com.google.common.collect.Iterables; * * @author mchauvin */ +@SuppressWarnings("restriction") public class LazyCrossReferencer extends ECrossReferenceAdapterWithUnproxyCapability { /** * Flag to know if the LazyCrossReferencer has been initialized. @@ -132,8 +135,6 @@ public class LazyCrossReferencer extends ECrossReferenceAdapterWithUnproxyCapabi super.unsetTarget(target); } - - /** * Look at all EObjects of this resource and resolve proxy cross reference * that reference these EObjects. @@ -174,13 +175,13 @@ public class LazyCrossReferencer extends ECrossReferenceAdapterWithUnproxyCapabi case Notification.REMOVE: Object oldValue = notification.getOldValue(); if (oldValue instanceof Notifier) { - removeAdapter((Notifier) oldValue); + removeAdapterIfNecessary(notification, (Notifier) oldValue); } break; case Notification.REMOVE_MANY: for (Notifier oldVal : Iterables.filter((Collection<?>) notification.getOldValue(), Notifier.class)) { - removeAdapter(oldVal); + removeAdapterIfNecessary(notification, oldVal); } break; @@ -188,4 +189,29 @@ public class LazyCrossReferencer extends ECrossReferenceAdapterWithUnproxyCapabi break; } } + + /** + * This method does not remove the adapter from the notification old value + * if its new container is already set and also has the adapter. + * + * @param notification + * a containment notification + * @param oldValue + * notification old value on which the adapter may be removed + */ + private void removeAdapterIfNecessary(Notification notification, Notifier oldValue) { + boolean toRemove = true; + + if (oldValue instanceof EObject) { + EObject currentContainer = ((EObject) oldValue).eContainer(); + + if (currentContainer != null && currentContainer != notification.getNotifier() && currentContainer.eAdapters().contains(this)) { + toRemove = false; + } + } + + if (toRemove) { + removeAdapter(oldValue); + } + } } |
