summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoradaussy2013-11-22 08:51:07 (EST)
committeradaussy2013-11-22 08:51:07 (EST)
commitc4f66e4724e5a63e9190c9626203a9828b8e3077 (patch)
tree0fbed297ceea12c9d2ced9a6f634fc381bbb7a19
parent2d67de15a8b4403807717052dd33eecde39d762c (diff)
downloadorg.eclipse.papyrus-c4f66e4724e5a63e9190c9626203a9828b8e3077.zip
org.eclipse.papyrus-c4f66e4724e5a63e9190c9626203a9828b8e3077.tar.gz
org.eclipse.papyrus-c4f66e4724e5a63e9190c9626203a9828b8e3077.tar.bz2
Bug 410462 - [Control Mode] ControlModeRequest.getSourceResource()
returns target resource https://bugs.eclipse.org/bugs/show_bug.cgi?id=410462 Complete the request with informations: Source and target resources are now filled into the request
-rw-r--r--plugins/core/org.eclipse.papyrus.controlmode/src/org/eclipse/papyrus/controlmode/commands/CreateControlResource.java10
-rw-r--r--plugins/core/org.eclipse.papyrus.controlmode/src/org/eclipse/papyrus/controlmode/request/ControlModeRequest.java46
2 files changed, 54 insertions, 2 deletions
diff --git a/plugins/core/org.eclipse.papyrus.controlmode/src/org/eclipse/papyrus/controlmode/commands/CreateControlResource.java b/plugins/core/org.eclipse.papyrus.controlmode/src/org/eclipse/papyrus/controlmode/commands/CreateControlResource.java
index 5634cae..f5e8c0b 100644
--- a/plugins/core/org.eclipse.papyrus.controlmode/src/org/eclipse/papyrus/controlmode/commands/CreateControlResource.java
+++ b/plugins/core/org.eclipse.papyrus.controlmode/src/org/eclipse/papyrus/controlmode/commands/CreateControlResource.java
@@ -17,6 +17,7 @@ import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.gmf.runtime.common.core.command.CommandResult;
import org.eclipse.papyrus.controlmode.request.ControlModeRequest;
@@ -48,6 +49,15 @@ public class CreateControlResource extends AbstractControlResourceCommand {
public CreateControlResource(ControlModeRequest request, String newFileExtension) {
this(request);
this.newFileExtension = newFileExtension;
+ Resource sourceResource = request.getTargetObject().eResource();
+ if(sourceResource != null) {
+ URI sourceURI = sourceResource.getURI().trimFileExtension().appendFileExtension(newFileExtension);
+ Resource sourceResourceForExtension = sourceResource.getResourceSet().getResource(sourceURI, false);
+ if(sourceResourceForExtension != null) {
+ request.setSourceResource(sourceResourceForExtension, newFileExtension);
+ }
+ }
+
}
diff --git a/plugins/core/org.eclipse.papyrus.controlmode/src/org/eclipse/papyrus/controlmode/request/ControlModeRequest.java b/plugins/core/org.eclipse.papyrus.controlmode/src/org/eclipse/papyrus/controlmode/request/ControlModeRequest.java
index c90c61a..d543f98 100644
--- a/plugins/core/org.eclipse.papyrus.controlmode/src/org/eclipse/papyrus/controlmode/request/ControlModeRequest.java
+++ b/plugins/core/org.eclipse.papyrus.controlmode/src/org/eclipse/papyrus/controlmode/request/ControlModeRequest.java
@@ -10,6 +10,9 @@
******************************************************************************/
package org.eclipse.papyrus.controlmode.request;
+import java.util.ArrayList;
+import java.util.Collection;
+
import org.eclipse.core.runtime.Assert;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
@@ -115,6 +118,10 @@ public class ControlModeRequest extends AbstractEditCommandRequest implements Co
if(newURI != null) {
setTargetResource(editingDomain.getResourceSet().getResource(newURI, false), newURI.fileExtension());
}
+ Resource sourceResource = targetObject.eResource();
+ if(sourceResource != null) {
+ setSourceResource(sourceResource, sourceResource.getURI().fileExtension());
+ }
Resource r = objectToControl.eResource();
Assert.isNotNull(r);
this.sourceURI = r.getURI();
@@ -178,6 +185,41 @@ public class ControlModeRequest extends AbstractEditCommandRequest implements Co
}
/**
+ * Get resources that has been used as target
+ *
+ * @return
+ */
+ public Collection<Resource> getTargetResources() {
+ return getResources(TARGET_RESOURCE);
+ }
+
+ /**
+ * Get resource that has been used as sources
+ *
+ * @return
+ */
+ public Collection<Resource> getSourceResources() {
+ return getResources(SOURCE_RESOURCE);
+ }
+
+ protected Collection<Resource> getResources(String resourceKind) {
+ Collection<Resource> result = new ArrayList<Resource>();
+ for(Object key : getParameters().keySet()) {
+ if(key instanceof String) {
+ String keyString = (String)key;
+ if(keyString.startsWith(resourceKind)) {
+ Object value = getParameter(keyString);
+ if(value instanceof Resource) {
+ result.add((Resource)value);
+ }
+ }
+
+ }
+ }
+ return result;
+ }
+
+ /**
* Get the target resource for this kind of file extension
*
* @param extension
@@ -226,7 +268,7 @@ public class ControlModeRequest extends AbstractEditCommandRequest implements Co
* Get the key used to register this file extension into the parameters for source
*
* @param extension
- * File Extenion
+ * File Extension
* @return
*/
protected String getSourceResourceKey(String extension) {
@@ -243,7 +285,7 @@ public class ControlModeRequest extends AbstractEditCommandRequest implements Co
public ModelSet getModelSet() {
return (ModelSet)getEditingDomain().getResourceSet();
}
-
+
/**
* Create a request for creating a request for controlling a EObject. This request is aware that the action is User Interface action
*