Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemi Schnekenburger2017-02-03 09:02:30 +0000
committerGerrit Code Review @ Eclipse.org2017-02-03 16:38:14 +0000
commitce06ec09814f06dd12baae83fb777c8c3337c192 (patch)
treeec19eb5483a39f1b7a59495a822346488bc0b91c /plugins/infra
parentcfbd8c1772ecd80c4288ad614700f44606b986aa (diff)
downloadorg.eclipse.papyrus-ce06ec09814f06dd12baae83fb777c8c3337c192.tar.gz
org.eclipse.papyrus-ce06ec09814f06dd12baae83fb777c8c3337c192.tar.xz
org.eclipse.papyrus-ce06ec09814f06dd12baae83fb777c8c3337c192.zip
Bug 511616: [Infra] CreateRelationshipCommand should allow modifications
of source and target on ConfigureRequest from CreateRequest https://bugs.eclipse.org/bugs/show_bug.cgi?id=511616 - Creating a new command to override GMF basic one - Use this command in DefaultEditHelper, the basic helper used in Papyrus for almost any element. Signed-off-by: Remi Schnekenburger <rschnekenburger@eclipsesource.com>
Diffstat (limited to 'plugins/infra')
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/CreateRelationshipCommandEx.java57
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/DefaultEditHelper.java22
2 files changed, 79 insertions, 0 deletions
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/CreateRelationshipCommandEx.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/CreateRelationshipCommandEx.java
new file mode 100644
index 00000000000..68e889a17e1
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/CreateRelationshipCommandEx.java
@@ -0,0 +1,57 @@
+/*****************************************************************************
+ * Copyright (c) 2017 CEA LIST and others.
+ *
+ * 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.gmfdiag.common.commands;
+
+import org.eclipse.gmf.runtime.emf.type.core.commands.CreateRelationshipCommand;
+import org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest;
+import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
+
+/**
+ * Specific {@link CreateRelationshipCommand} that does not set the source and target in the configure request if it is already set.
+ * <p>
+ * This allows to override the source and/or the target in the advices. Basic GMF implementation reset the {@link CreateRelationshipRequest#SOURCE} & {@link CreateRelationshipRequest#TARGET} when the configureRequest is created, with original values.
+ * </p>
+ */
+public class CreateRelationshipCommandEx extends CreateRelationshipCommand {
+
+ /**
+ * Constructor.
+ *
+ * @param request
+ * the element creation request
+ */
+ public CreateRelationshipCommandEx(CreateRelationshipRequest request) {
+ super(request);
+ }
+
+ @Override
+ protected ConfigureRequest createConfigureRequest() {
+ // let the super() create the requests as usual
+ ConfigureRequest result = super.createConfigureRequest();
+
+ // retrieve those from create request
+ Object requestSource = getRequest().getParameter(CreateRelationshipRequest.SOURCE);
+ Object requestTarget = getRequest().getParameter(CreateRelationshipRequest.TARGET);
+
+ // overrides parameters only if necessary, e.g. set and different
+ if (requestSource != null && !requestSource.equals(result.getParameter(CreateRelationshipRequest.SOURCE))) {
+ result.setParameter(CreateRelationshipRequest.SOURCE, requestSource);
+ }
+ if (requestTarget != null && !requestTarget.equals(result.getParameter(CreateRelationshipRequest.TARGET))) {
+ result.setParameter(CreateRelationshipRequest.TARGET, requestTarget);
+ }
+ return result;
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/DefaultEditHelper.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/DefaultEditHelper.java
index 8a03c87f595..5c16a7215f5 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/DefaultEditHelper.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/DefaultEditHelper.java
@@ -24,6 +24,7 @@ import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.common.core.command.IdentityCommand;
import org.eclipse.gmf.runtime.emf.type.core.ElementTypeRegistry;
import org.eclipse.gmf.runtime.emf.type.core.IClientContext;
import org.eclipse.gmf.runtime.emf.type.core.IContainerDescriptor;
@@ -40,6 +41,7 @@ import org.eclipse.papyrus.commands.DestroyElementPapyrusCommand;
import org.eclipse.papyrus.infra.emf.commands.UnsetValueCommand;
import org.eclipse.papyrus.infra.emf.requests.UnsetRequest;
import org.eclipse.papyrus.infra.gmfdiag.common.commands.CreateEditBasedElementCommand;
+import org.eclipse.papyrus.infra.gmfdiag.common.commands.CreateRelationshipCommandEx;
import org.eclipse.papyrus.infra.services.edit.utils.CacheRegistry;
import org.eclipse.papyrus.infra.services.edit.utils.IRequestCacheEntries;
import org.eclipse.papyrus.infra.types.core.notification.AbstractNotifierEditHelper;
@@ -159,6 +161,26 @@ public class DefaultEditHelper extends AbstractNotifierEditHelper {
}
/**
+ * {@inheritDoc}
+ */
+ @Override
+ protected ICommand getCreateRelationshipCommand(CreateRelationshipRequest req) {
+ EObject source = req.getSource();
+ EObject target = req.getTarget();
+
+ boolean noSourceOrTarget = (source == null || target == null);
+ boolean noSourceAndTarget = (source == null && target == null);
+
+ if (noSourceOrTarget && !noSourceAndTarget) {
+ // The request isn't complete yet. Return the identity command so
+ // that the create relationship gesture is enabled.
+ return IdentityCommand.INSTANCE;
+ }
+
+ return new CreateRelationshipCommandEx(req);
+ }
+
+ /**
* Gets the command to destroy a single child of an element of my kind along
* with its dependents (not related by containment). By default, returns a
* composite that destroys the elements and zero or more dependents.

Back to the top