Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolas FAUVERGUE2019-08-06 08:35:20 -0400
committerPatrick Tessier2019-08-20 08:37:56 -0400
commitfc697c6c175c7fcf25773eb7afb5e4d5855c78d4 (patch)
treeb5756ac87ece640ccd4f1678ae1d9469e6bf8188 /plugins
parent913779f376f820c5443142fe9f363e3fa5dc28fa (diff)
downloadorg.eclipse.papyrus-fc697c6c175c7fcf25773eb7afb5e4d5855c78d4.tar.gz
org.eclipse.papyrus-fc697c6c175c7fcf25773eb7afb5e4d5855c78d4.tar.xz
org.eclipse.papyrus-fc697c6c175c7fcf25773eb7afb5e4d5855c78d4.zip
Bug 549816: [Core] Papyrus shall provide an efficient
ProxyModificationTrackingAdapter Mark the resources of ResourceSet as modified instead of checking the usages of modified object(s). Change-Id: I8990f2dc4eb0dfa67960c4fd5fa46625d4b680ac Signed-off-by: Nicolas FAUVERGUE <nicolas.fauvergue@cea.fr>
Diffstat (limited to 'plugins')
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/ProxyModificationTrackingAdapter.java64
1 files changed, 41 insertions, 23 deletions
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/ProxyModificationTrackingAdapter.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/ProxyModificationTrackingAdapter.java
index 923e397439c..79daae0f3ff 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/ProxyModificationTrackingAdapter.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/ProxyModificationTrackingAdapter.java
@@ -12,7 +12,8 @@
* Mathieu Velten (Atos) mathieu.velten@atos.net - Initial API and implementation
* Christian W. Damus (CEA) - bug 432753
* Christian W. Damus (CEA) - bug 437052
- * Calin Glitia (Esterel Technologies) calin.glitia@esterel-technologies.com - bug 480209
+ * Calin Glitia (Esterel Technologies) calin.glitia@esterel-technologies.com - bug 480209
+ * Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Bug 549816
*
*****************************************************************************/
package org.eclipse.papyrus.infra.core.resource;
@@ -22,13 +23,15 @@ import java.util.Collections;
import java.util.List;
import org.eclipse.emf.common.notify.Notification;
-import org.eclipse.emf.common.util.TreeIterator;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.EStructuralFeature.Setting;
import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.util.EContentAdapter;
import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.emf.edit.domain.IEditingDomainProvider;
/**
* This adapter handles "modified" flag of resources for tricky cases :
@@ -88,14 +91,7 @@ public class ProxyModificationTrackingAdapter extends EContentAdapter {
if (n.getEventType() == Notification.SET && n.getFeatureID(Resource.class) == Resource.RESOURCE__URI) {
r.setModified(true);
-
- TreeIterator<Object> properContents = EcoreUtil.getAllProperContents(r, false);
- while (properContents.hasNext()) {
- Object obj = properContents.next();
- if (obj instanceof EObject) {
- setReferencingResourcesAsModified((EObject) obj);
- }
- }
+ setOtherResourcesAsModified(r);
} else {
List<?> objects;
@@ -121,19 +117,7 @@ public class ProxyModificationTrackingAdapter extends EContentAdapter {
if (r.isLoaded() && !r.isLoading()) {
if (!objects.isEmpty()) {
r.setModified(true);
- }
-
- for (Object o : objects) {
- if (o instanceof EObject) {
- setReferencingResourcesAsModified((EObject) o);
- TreeIterator<Object> properContents = EcoreUtil.getAllProperContents((EObject) o, false);
- while (properContents.hasNext()) {
- Object obj = properContents.next();
- if (obj instanceof EObject) {
- setReferencingResourcesAsModified((EObject) obj);
- }
- }
- }
+ setOtherResourcesAsModified(r);
}
}
}
@@ -154,4 +138,38 @@ public class ProxyModificationTrackingAdapter extends EContentAdapter {
}
}
}
+
+ /**
+ * This allows to mark other resources of resource set as modified if needed.
+ *
+ * @param resource
+ * The current resource.
+ * @since 3.1
+ */
+ protected void setOtherResourcesAsModified(final Resource resource) {
+ // Get the resource set to loop through resources
+ final ResourceSet resourceSet = resource.getResourceSet();
+ EditingDomain domain = null;
+
+ // Get the editing domain to determinate if a resource is read only
+ if (resourceSet instanceof ModelSet) {
+ domain = ((ModelSet) resourceSet).getTransactionalEditingDomain();
+ } else if (resourceSet instanceof IEditingDomainProvider) {
+ domain = ((IEditingDomainProvider) resourceSet).getEditingDomain();
+ } else if (resourceSet != null) {
+ IEditingDomainProvider editingDomainProvider = (IEditingDomainProvider) EcoreUtil.getExistingAdapter(resourceSet, IEditingDomainProvider.class);
+ if (editingDomainProvider != null) {
+ domain = editingDomainProvider.getEditingDomain();
+ }
+ }
+
+ // Loop through resources to determinate if this is needed to mark it as modified
+ for (final Resource subResource : resourceSet.getResources()) {
+ if (subResource instanceof Resource.Internal && subResource.isLoaded() && !((Resource.Internal) subResource).isLoading()) {
+ if (null == domain || !domain.isReadOnly(subResource)) {
+ subResource.setModified(true);
+ }
+ }
+ }
+ }
}

Back to the top