Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian W. Damus2015-11-24 18:45:12 +0000
committerChristian W. Damus2015-11-24 20:35:38 +0000
commit6e99ae12c6453caeebf232da1c6a9f7dadab08e3 (patch)
treeada3c534c81141f466f95918f48ce41035cd139e /plugins/infra/core
parent35196434a6c6f8a52e17a03b224d46004525e8a1 (diff)
downloadorg.eclipse.papyrus-6e99ae12c6453caeebf232da1c6a9f7dadab08e3.tar.gz
org.eclipse.papyrus-6e99ae12c6453caeebf232da1c6a9f7dadab08e3.tar.xz
org.eclipse.papyrus-6e99ae12c6453caeebf232da1c6a9f7dadab08e3.zip
Bug 482949: Problems with ResourceAdapter.Transactional
https://bugs.eclipse.org/bugs/show_bug.cgi?id=482949 Fix ResourceAdapter.Transactional adding itself to the editing domain instead of removing itself on uninstall. Ensure JUnit coverage on par with the non-transactional variant.
Diffstat (limited to 'plugins/infra/core')
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/ResourceAdapter.java80
1 files changed, 74 insertions, 6 deletions
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/ResourceAdapter.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/ResourceAdapter.java
index 454dc5ea26f..ea15d69ab94 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/ResourceAdapter.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/ResourceAdapter.java
@@ -11,10 +11,16 @@
* Christian W. Damus - bug 399859
* Christian W. Damus - bug 465416
* Eike Stepper (CEA) - bug 466520
+ * Christian W. Damus - bug 482949
*
*/
package org.eclipse.papyrus.infra.core.resource;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Predicate;
+
import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notification;
@@ -82,9 +88,9 @@ public abstract class ResourceAdapter extends AdapterImpl {
case Notification.SET:
case Notification.UNSET:
if (msg.getNewBooleanValue()) {
- handleResourceLoaded((Resource) notifier);
+ handleResourceLoaded0((Resource) notifier);
} else {
- handleResourceUnloaded((Resource) notifier);
+ handleResourceUnloaded0((Resource) notifier);
}
break;
}
@@ -171,7 +177,7 @@ public abstract class ResourceAdapter extends AdapterImpl {
// Don't report addition of roots when loading nor removal of roots when unloading
// because loading and unloading are semantically more significant events
- if (resource.isLoaded() && !resource.isLoading()) {
+ if (resource.isLoaded() && !isLoading(resource)) {
switch (msg.getEventType()) {
case Notification.ADD: {
Object newValue = msg.getNewValue();
@@ -226,10 +232,22 @@ public abstract class ResourceAdapter extends AdapterImpl {
// Pass
}
+ void handleResourceLoaded0(Resource resource) {
+ handleResourceLoaded(resource);
+ }
+
+ boolean isLoading(Resource.Internal resource) {
+ return resource.isLoading();
+ }
+
protected void handleResourceLoaded(Resource resource) {
// Pass
}
+ void handleResourceUnloaded0(Resource resource) {
+ handleResourceUnloaded(resource);
+ }
+
protected void handleResourceUnloaded(Resource resource) {
// Pass
}
@@ -258,6 +276,11 @@ public abstract class ResourceAdapter extends AdapterImpl {
private final NotificationFilter filter = NotificationFilter.NOT_TOUCH.and(createFilter());
+ private List<Notification> notifications;
+
+ /** Because we are invoked after the fact, we need to emulate the is-loading state. */
+ private Map<Resource, Boolean> loadingState;
+
/**
* Initializes me as a post-commit resource notification handler.
*/
@@ -308,12 +331,12 @@ public abstract class ResourceAdapter extends AdapterImpl {
@Override
public void resourceSetChanged(ResourceSetChangeEvent event) {
- handleResourceSetChangeEvent(event);
+ handleResourceSetChangeEvent0(event);
}
@Override
public Command transactionAboutToCommit(ResourceSetChangeEvent event) throws RollbackException {
- handleResourceSetChangeEvent(event);
+ handleResourceSetChangeEvent0(event);
return null;
}
@@ -358,7 +381,17 @@ public abstract class ResourceAdapter extends AdapterImpl {
}
}
} finally {
- editingDomain.addResourceSetListener(this);
+ editingDomain.removeResourceSetListener(this);
+ }
+ }
+
+ protected void handleResourceSetChangeEvent0(ResourceSetChangeEvent event) {
+ try {
+ notifications = event.getNotifications();
+ handleResourceSetChangeEvent(event);
+ } finally {
+ notifications = null;
+ loadingState = null;
}
}
@@ -387,5 +420,40 @@ public abstract class ResourceAdapter extends AdapterImpl {
protected final void removeAdapter(Notifier notifier) {
// Pass
}
+
+ @Override
+ boolean isLoading(Resource.Internal resource) {
+ return getLoadingState().computeIfAbsent(resource,
+ r -> notifications.stream().anyMatch(isLoadOf(r)));
+ }
+
+ private Predicate<Notification> isLoadOf(Resource resource) {
+ return msg -> (msg.getNotifier() == resource)
+ && (msg.getFeatureID(Resource.class) == Resource.RESOURCE__IS_LOADED)
+ && msg.getNewBooleanValue();
+ }
+
+ Map<Resource, Boolean> getLoadingState() {
+ if (loadingState == null) {
+ loadingState = new HashMap<>();
+ }
+ return loadingState;
+ }
+
+ void setLoading(Resource resource, boolean loading) {
+ getLoadingState().put(resource, loading);
+ }
+
+ @Override
+ void handleResourceLoaded0(Resource resource) {
+ setLoading(resource, true);
+ super.handleResourceLoaded0(resource);
+ }
+
+ @Override
+ void handleResourceUnloaded0(Resource resource) {
+ setLoading(resource, false);
+ super.handleResourceUnloaded0(resource);
+ }
}
}

Back to the top