summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoradaussy2013-12-17 11:54:52 (EST)
committeradaussy2013-12-17 11:54:52 (EST)
commit94594c1ed348e2e30ecd7194ff038ecd869ca0a8 (patch)
tree691b7bd1050380bc7095b794cbf21c7552fffe77
parenta60498ac9b35d92ceb0ec9997a4cea2e2be6d54f (diff)
downloadorg.eclipse.papyrus-94594c1ed348e2e30ecd7194ff038ecd869ca0a8.zip
org.eclipse.papyrus-94594c1ed348e2e30ecd7194ff038ecd869ca0a8.tar.gz
org.eclipse.papyrus-94594c1ed348e2e30ecd7194ff038ecd869ca0a8.tar.bz2
Bug 402905 - [Control Mode] Refactoring of the control command to be
more stable https://bugs.eclipse.org/bugs/show_bug.cgi?id=402905 Compute the affected resource with a control command for collab mode
-rw-r--r--plugins/core/org.eclipse.papyrus.controlmode/src/org/eclipse/papyrus/controlmode/commands/BasicControlCommand.java21
-rw-r--r--plugins/core/org.eclipse.papyrus.controlmode/src/org/eclipse/papyrus/controlmode/helper/ControlCommandHelper.java28
2 files changed, 47 insertions, 2 deletions
diff --git a/plugins/core/org.eclipse.papyrus.controlmode/src/org/eclipse/papyrus/controlmode/commands/BasicControlCommand.java b/plugins/core/org.eclipse.papyrus.controlmode/src/org/eclipse/papyrus/controlmode/commands/BasicControlCommand.java
index 20ff006..970085b 100644
--- a/plugins/core/org.eclipse.papyrus.controlmode/src/org/eclipse/papyrus/controlmode/commands/BasicControlCommand.java
+++ b/plugins/core/org.eclipse.papyrus.controlmode/src/org/eclipse/papyrus/controlmode/commands/BasicControlCommand.java
@@ -13,9 +13,12 @@
*****************************************************************************/
package org.eclipse.papyrus.controlmode.commands;
-import java.util.Collections;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.emf.common.util.URI;
@@ -24,8 +27,12 @@ import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.workspace.util.WorkspaceSynchronizer;
import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.papyrus.controlmode.helper.ControlCommandHelper;
import org.eclipse.papyrus.controlmode.request.ControlModeRequest;
+import com.google.common.base.Function;
+import com.google.common.collect.Collections2;
+
/**
* This command do the basic operation of the control. That is to say move the semantic element to a new resource previously created.
* This resource id got thanks to the request.
@@ -40,7 +47,17 @@ public class BasicControlCommand extends AbstractControlCommandRequest {
* @param request
*/
public BasicControlCommand(ControlModeRequest request) {
- super("Control command", Collections.singletonList(WorkspaceSynchronizer.getFile(request.getTargetObject().eResource())), request);
+ super("Control command", null, request);
+ Set<Resource> affectedResources = new HashSet<Resource>();
+ ControlCommandHelper.getAffectedResourceByControlCommand(request.getTargetObject(), affectedResources);
+ Collection<IFile> affectedFile = Collections2.transform(affectedResources, new Function<Resource, IFile>() {
+
+ public IFile apply(Resource arg0) {
+ return WorkspaceSynchronizer.getFile(arg0);
+ }
+ });
+ System.out.println(affectedFile);
+ getAffectedFiles().addAll(affectedFile);
}
/*
diff --git a/plugins/core/org.eclipse.papyrus.controlmode/src/org/eclipse/papyrus/controlmode/helper/ControlCommandHelper.java b/plugins/core/org.eclipse.papyrus.controlmode/src/org/eclipse/papyrus/controlmode/helper/ControlCommandHelper.java
index b1e0667..6ab2d34 100644
--- a/plugins/core/org.eclipse.papyrus.controlmode/src/org/eclipse/papyrus/controlmode/helper/ControlCommandHelper.java
+++ b/plugins/core/org.eclipse.papyrus.controlmode/src/org/eclipse/papyrus/controlmode/helper/ControlCommandHelper.java
@@ -13,9 +13,15 @@
*****************************************************************************/
package org.eclipse.papyrus.controlmode.helper;
+import java.util.Collection;
+import java.util.Set;
+
import org.eclipse.emf.common.util.EList;
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.papyrus.core.utils.PapyrusEcoreUtils;
/**
* Helper for control command
@@ -43,4 +49,26 @@ public class ControlCommandHelper {
}
return false;
}
+
+
+ public static Set<Resource> getAffectedResourceByControlCommand(EObject source, Set<Resource> affectedResources) {
+ Collection<Setting> settings = PapyrusEcoreUtils.getUsages(source);
+ for(Setting setting : settings) {
+ EStructuralFeature feature = setting.getEStructuralFeature();
+ if(!feature.isDerived() && !feature.isTransient() && !feature.isVolatile()) {
+ EObject fromEObject = setting.getEObject();
+ Resource resource = fromEObject.eResource();
+ if(resource != null) {
+ affectedResources.add(resource);
+ }
+ }
+ }
+ for(EObject child : source.eContents()) {
+ Resource childResoure = child.eResource();
+ if(childResoure != null && childResoure.equals(source.eResource())) {
+ getAffectedResourceByControlCommand(child, affectedResources);
+ }
+ }
+ return affectedResources;
+ }
}