summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjcadavid2014-05-13 05:29:46 (EDT)
committerCamille Letavernier2014-05-21 05:32:51 (EDT)
commit75074ae93465f6c9dc5c723fe0e0de4df393b67a (patch)
treef3d6341130ce509042f81ee40264116b2ed58d6e
parentef639d79ba7af7c958e0205e87f0b0baa14737f0 (diff)
downloadorg.eclipse.papyrus-75074ae93465f6c9dc5c723fe0e0de4df393b67a.zip
org.eclipse.papyrus-75074ae93465f6c9dc5c723fe0e0de4df393b67a.tar.gz
org.eclipse.papyrus-75074ae93465f6c9dc5c723fe0e0de4df393b67a.tar.bz2
422247: [Control Mode] Save as does not work for controlled modelsrefs/changes/34/26434/3
handle() method implemented for resource loading in DiModel, and isControlled() implemented in DiModel and modified in NotationModel, to look for associated resources when asking if it makes part of a controlled submodel. Change-Id: Ie5ea3784ecf4bc264bc565a0dc474b61c7f33976 Signed-off-by: jcadavid <juan.cadavid@cea.fr>
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/sasheditor/DiModel.java69
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/model/NotationModel.java15
2 files changed, 76 insertions, 8 deletions
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/sasheditor/DiModel.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/sasheditor/DiModel.java
index 9276ac4..2a3a0b0 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/sasheditor/DiModel.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/sasheditor/DiModel.java
@@ -14,12 +14,17 @@
*****************************************************************************/
package org.eclipse.papyrus.infra.core.resource.sasheditor;
+import java.util.Collections;
import java.util.Map;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.resource.URIConverter;
import org.eclipse.emf.ecore.xmi.XMIResource;
import org.eclipse.papyrus.infra.core.resource.AbstractModelWithSharedResource;
+import org.eclipse.papyrus.infra.core.resource.IEMFModel;
import org.eclipse.papyrus.infra.core.resource.IModel;
/**
@@ -112,4 +117,68 @@ public class DiModel extends AbstractModelWithSharedResource<EObject> implements
return false; //DiModel is currently an empty model
}
+ @Override
+ public void setModelURI(URI uriWithoutExtension) {
+ for(Resource resource : getResources()) {
+ if(isControlled(resource)) {
+ URI newBaseUri = uriWithoutExtension.trimSegments(1).appendSegment(resource.getURI().lastSegment());
+ resource.setURI(newBaseUri);
+ }
+ }
+ super.setModelURI(uriWithoutExtension);
+
+ }
+
+ @Override
+ public void handle(Resource resource) {
+ super.handle(resource);
+ if(resource == null) {
+ return;
+ }
+
+
+ //If the parameter resource is already a di resource, nothing to do
+ if(!isRelatedResource(resource)) {
+ URI diUri = resource.getURI().trimFileExtension().appendFileExtension(DI_FILE_EXTENSION);
+ ResourceSet resourceSet = getResourceSet();
+
+ boolean diAlreadyLoaded = false;
+ for(Resource loadedResource : resourceSet.getResources()) {
+ if(loadedResource.getURI().equals(diUri)){
+ diAlreadyLoaded = true;
+ }
+ }
+
+ if(resourceSet != null && !diAlreadyLoaded && resourceSet.getURIConverter() != null) {
+ URIConverter converter = resourceSet.getURIConverter();
+ if(converter.exists(diUri, Collections.emptyMap())) {
+ //If the di resource associated to the parameter resource exists, load it
+ getResourceSet().getResource(diUri, true);
+ }
+ }
+ }
+ }
+
+ /**
+ * Notation resources are controlled if their base element is controlled
+ */
+ @Override
+ public boolean isControlled(Resource resource) {
+ for(Resource resourceInModelSet : modelSet.getResources()) {
+ if ( resource.getURI().trimFileExtension().equals(resourceInModelSet.getURI().trimFileExtension()) && !isRelatedResource(resourceInModelSet)){
+ if(!resourceInModelSet.getContents().isEmpty()){
+ EObject eObject = resourceInModelSet.getContents().get(0);
+ IModel iModel = modelSet.getModelFor(eObject);
+ if(iModel instanceof IEMFModel) {
+ if(((IEMFModel)iModel).isControlled(resourceInModelSet)) {
+ return true;
+ }
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+
}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/model/NotationModel.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/model/NotationModel.java
index a035903..d9e7953 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/model/NotationModel.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/model/NotationModel.java
@@ -82,24 +82,23 @@ public class NotationModel extends EMFLogicalModel implements IModel {
/**
* Notation resources are controlled if their base element is controlled
+ * In case the notation resource is empty, we should look at the associated resources and see if one of them is controlled.
*/
@Override
public boolean isControlled(Resource resource) {
- for(EObject rootElement : resource.getContents()) {
- IOpenable openable = (IOpenableWithContainer)Platform.getAdapterManager().getAdapter(rootElement, IOpenable.class);
- if(openable instanceof IOpenableWithContainer) {
- EObject container = EMFHelper.getEObject(((IOpenableWithContainer)openable).getContainer());
- if(container != null) {
- IModel iModel = modelSet.getModelFor(container);
+ for(Resource resourceInModelSet : modelSet.getResources()) {
+ if ( resource.getURI().trimFileExtension().equals(resourceInModelSet.getURI().trimFileExtension()) && !isRelatedResource(resourceInModelSet)){
+ if(!resourceInModelSet.getContents().isEmpty()){
+ EObject eObject = resourceInModelSet.getContents().get(0);
+ IModel iModel = modelSet.getModelFor(eObject);
if(iModel instanceof IEMFModel) {
- if(((IEMFModel)iModel).isControlled(container.eResource())) {
+ if(((IEMFModel)iModel).isControlled(resourceInModelSet)) {
return true;
}
}
}
}
}
-
return false;
}