summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilippe Roland2014-01-27 10:33:12 (EST)
committerPhilippe Roland2014-01-27 10:33:12 (EST)
commit55135c9acd1d1013c0f77b1c10c75ce43dee26c0 (patch)
treeee09c040b043f74beb1e4a06cacccf2bc6d74c0a
parenta72327757a400fdf968a30498ed66f21ccf75843 (diff)
downloadorg.eclipse.papyrus-55135c9acd1d1013c0f77b1c10c75ce43dee26c0.zip
org.eclipse.papyrus-55135c9acd1d1013c0f77b1c10c75ce43dee26c0.tar.gz
org.eclipse.papyrus-55135c9acd1d1013c0f77b1c10c75ce43dee26c0.tar.bz2
426255 - [ControlMode] Controlling an EObject causes its old
resource to not be flagged as modified
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/commands/BasicControlCommand.java157
1 files changed, 81 insertions, 76 deletions
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/commands/BasicControlCommand.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/commands/BasicControlCommand.java
index 9fc09ae..7827eeb 100644
--- a/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/commands/BasicControlCommand.java
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/commands/BasicControlCommand.java
@@ -1,76 +1,81 @@
-/*****************************************************************************
- * Copyright (c) 2013 Atos.
- *
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Arthur Daussy (Atos) arthur.daussy@atos.net - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.services.controlmode.commands;
-
-import java.util.Collections;
-
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.IProgressMonitor;
-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.workspace.util.WorkspaceSynchronizer;
-import org.eclipse.gmf.runtime.common.core.command.CommandResult;
-import org.eclipse.papyrus.infra.services.controlmode.ControlModeRequest;
-
-/**
- * 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.
- *
- * @author adaussy
- *
- */
-public class BasicControlCommand extends AbstractControlCommand {
-
-
- /**
- * @param request
- */
- public BasicControlCommand(ControlModeRequest request) {
- super("Control command", Collections.singletonList(WorkspaceSynchronizer.getFile(request.getTargetObject().eResource())), request);
- }
-
- @Override
- public boolean canExecute() {
- return super.canExecute() && getObjectToControl() != null && !getObjectToControl().eIsProxy();
- }
-
- @Override
- protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
- ResourceSet currentResourceSet = getRequest().getModelSet();
- Resource resource = currentResourceSet.getResource(getNewURI(), false);
- if(resource == null) {
- throw new ExecutionException("The resource was not created");
- }
- resource.getContents().add(getObjectToControl());
- return CommandResult.newOKCommandResult(resource);
- }
-
-
- /**
- * @return the object being controled
- */
- public EObject getObjectToControl() {
- return getRequest().getTargetObject();
- }
-
- /**
- * @return
- */
- public URI getNewURI() {
- return getRequest().getNewURI();
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2013 Atos.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Arthur Daussy (Atos) arthur.daussy@atos.net - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.services.controlmode.commands;
+
+import java.util.Collections;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+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.workspace.util.WorkspaceSynchronizer;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.papyrus.infra.services.controlmode.ControlModeRequest;
+
+/**
+ * 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.
+ *
+ * @author adaussy
+ *
+ */
+public class BasicControlCommand extends AbstractControlCommand {
+
+
+ /**
+ * @param request
+ */
+ public BasicControlCommand(ControlModeRequest request) {
+ super("Control command", Collections.singletonList(WorkspaceSynchronizer.getFile(request.getTargetObject().eResource())), request);
+ }
+
+ @Override
+ public boolean canExecute() {
+ return super.canExecute() && getObjectToControl() != null && !getObjectToControl().eIsProxy();
+ }
+
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ ResourceSet currentResourceSet = getRequest().getModelSet();
+ Resource resource = currentResourceSet.getResource(getNewURI(), false);
+ if(resource == null) {
+ throw new ExecutionException("The resource was not created");
+ }
+ EObject objectToControl = getObjectToControl();
+ // as a safeguard, add this object's resource so it is tagged as modified and savable
+ if(objectToControl != null && objectToControl.eResource() != null) {
+ objectToControl.eResource().setModified(true);
+ }
+ resource.getContents().add(objectToControl);
+ return CommandResult.newOKCommandResult(resource);
+ }
+
+
+ /**
+ * @return the object being controled
+ */
+ public EObject getObjectToControl() {
+ return getRequest().getTargetObject();
+ }
+
+ /**
+ * @return
+ */
+ public URI getNewURI() {
+ return getRequest().getNewURI();
+ }
+}