Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemi Schnekenburger2016-12-06 10:01:55 +0000
committerGerrit Code Review @ Eclipse.org2016-12-06 13:36:14 +0000
commita4536cfed3f603378208491f3a4f9373fb1aa122 (patch)
treea7a144c1ce537666e6332616e438bebf511269d4
parentf9ab18e06cbb4eaf20ebae66630c8c470e3c7479 (diff)
downloadorg.eclipse.papyrus-a4536cfed3f603378208491f3a4f9373fb1aa122.tar.gz
org.eclipse.papyrus-a4536cfed3f603378208491f3a4f9373fb1aa122.tar.xz
org.eclipse.papyrus-a4536cfed3f603378208491f3a4f9373fb1aa122.zip
Bug 493630 - Need to create connector between two port of same parent
view - relax constraint on the connector creation. There should not be such constraint in base UML. Change-Id: I22a3ff0e03efa29c233890737672969f5e2f4e47 Signed-off-by: Remi Schnekenburger <remi.schnekenburger@cea.fr>
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/ConnectorEditHelper.java577
1 files changed, 285 insertions, 292 deletions
diff --git a/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/ConnectorEditHelper.java b/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/ConnectorEditHelper.java
index 7330acae7ba..52c2b206f3a 100644
--- a/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/ConnectorEditHelper.java
+++ b/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/ConnectorEditHelper.java
@@ -1,292 +1,285 @@
-/*****************************************************************************
-
- * Copyright (c) 2011-2012 CEA LIST.
- *
- * 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.uml.service.types.helper;
-
-import java.util.List;
-
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.util.EcoreUtil;
-import org.eclipse.gmf.runtime.common.core.command.CommandResult;
-import org.eclipse.gmf.runtime.common.core.command.CompositeCommand;
-import org.eclipse.gmf.runtime.common.core.command.ICommand;
-import org.eclipse.gmf.runtime.common.core.command.IdentityCommand;
-import org.eclipse.gmf.runtime.common.core.command.UnexecutableCommand;
-import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
-import org.eclipse.gmf.runtime.emf.type.core.commands.ConfigureElementCommand;
-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;
-import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
-import org.eclipse.gmf.runtime.emf.type.core.requests.ReorientRelationshipRequest;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.papyrus.uml.service.types.command.ConnectorReorientCommand;
-import org.eclipse.papyrus.uml.service.types.utils.ConnectorUtils;
-import org.eclipse.papyrus.uml.service.types.utils.RequestParameterUtils;
-import org.eclipse.uml2.uml.ConnectableElement;
-import org.eclipse.uml2.uml.Connector;
-import org.eclipse.uml2.uml.ConnectorEnd;
-import org.eclipse.uml2.uml.Port;
-import org.eclipse.uml2.uml.Property;
-import org.eclipse.uml2.uml.StructuredClassifier;
-import org.eclipse.uml2.uml.UMLFactory;
-
-/**
- * Edit helper class for binary {@link Connector}
- */
-public class ConnectorEditHelper extends ElementEditHelper {
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected ICommand getReorientRelationshipCommand(ReorientRelationshipRequest req) {
- return new ConnectorReorientCommand(req);
- }
-
- /**
- * Test if the relationship creation is allowed.
- *
- * @param source
- * the relationship source can be null
- * @param target
- * the relationship target can be null
- * @param sourceView
- * the relationship graphical source can be null
- * @param targetView
- * the relationship graphical target can be null
- * @return true if the creation is allowed
- */
- protected boolean canCreate(EObject source, EObject target, View sourceView, View targetView) {
-
- if((source != null) && !(source instanceof ConnectableElement)) {
- return false;
- }
-
- if((target != null) && !(target instanceof ConnectableElement)) {
- return false;
- }
-
- if((sourceView != null) && (targetView != null)) {
- // Cannot create a self connector on a view
- if(sourceView == targetView) {
- return false;
- }
-
- // Cannot create a connector from a view representing a Part to its own Port (or the opposite)
- if((sourceView.getChildren().contains(targetView)) || (targetView.getChildren().contains(sourceView))) {
- return false;
- }
-
- // Cannot connect two Port owned by the same view
- if((sourceView.getElement() instanceof Port) && (targetView.getElement() instanceof Port)) {
- if(ViewUtil.getContainerView(sourceView) == ViewUtil.getContainerView(targetView)) {
- return false;
- }
- }
-
- // Cannot connect a Part to one of its (possibly indirect) containment, must connect to one of its Port.
- if(getStructureContainers(sourceView).contains(targetView) || getStructureContainers(targetView).contains(sourceView)) {
- return false;
- }
- }
-
- return true;
- }
-
- /**
- * {@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) {
-
- if (!(source instanceof ConnectableElement)){
- return UnexecutableCommand.INSTANCE;
- }
- // The request isn't complete yet. Return the identity command so
- // that the create relationship gesture is enabled.
- return IdentityCommand.INSTANCE;
-
- }
-
- if (source != null && target != null){
- // Propose a semantic container for the new Connector.
- StructuredClassifier proposedContainer = deduceContainer(req);
- if(proposedContainer == null) {
- return UnexecutableCommand.INSTANCE;
- }
-
- EObject container = req.getContainer();
- if (container != proposedContainer){
- req.setContainer(proposedContainer);
- return new CreateRelationshipCommand(req);
- }
-
- }
-
- boolean umlStrict = true;
- if (!req.getParameters().isEmpty()){
- Object umlStrictParameter = req.getParameter(org.eclipse.papyrus.uml.service.types.utils.RequestParameterConstants.UML_STRICT);
- if (umlStrictParameter instanceof Boolean){
- umlStrict = (Boolean) umlStrictParameter;
- }
- }
-
- boolean canCreate = true;
-
- if (umlStrict){
- canCreate = canCreate(source, target, RequestParameterUtils.getSourceView(req), RequestParameterUtils.getTargetView(req));
- }
- if(!noSourceAndTarget && !canCreate) {
- // Abort creation.
- return UnexecutableCommand.INSTANCE;
- }
- return new CreateRelationshipCommand(req);
- }
-
- /**
- * This method provides the source role provided as {@link ConfigureRequest} parameter.
- *
- * @return the target role
- */
- private ConnectableElement getSourceRole(IEditCommandRequest req) {
- ConnectableElement result = null;
- Object paramObject = req.getParameter(CreateRelationshipRequest.SOURCE);
- if(paramObject instanceof ConnectableElement) {
- result = (ConnectableElement)paramObject;
- }
-
- return result;
- }
-
- /**
- * This method provides the target role provided as {@link ConfigureRequest} parameter.
- *
- * @return the target role
- */
- private ConnectableElement getTargetRole(IEditCommandRequest req) {
- ConnectableElement result = null;
- Object paramObject = req.getParameter(CreateRelationshipRequest.TARGET);
- if(paramObject instanceof ConnectableElement) {
- result = (ConnectableElement)paramObject;
- }
-
- return result;
- }
-
- /**
- * This method provides the source partWithPort provided as {@link ConfigureRequest} parameter.
- *
- * @return the target partWithPort
- */
- private Property getSourcePartWithPort(IEditCommandRequest req) {
- Property result = null;
- if(getSourceRole(req) instanceof Port) {
- // Only look for PartWithPort if the role is a Port.
-
- View parentView = ViewUtil.getContainerView(RequestParameterUtils.getSourceView(req));
- EObject semanticParent = parentView.getElement();
- if((semanticParent instanceof Property) && !(semanticParent instanceof Port)) {
- // Only add PartWithPort for assembly (not for delegation)
- if(!EcoreUtil.isAncestor(parentView, RequestParameterUtils.getTargetView(req))) {
- result = (Property)semanticParent;
- }
- }
-
- }
- return result;
- }
-
- /**
- * This method provides the target partWithPort provided as {@link ConfigureRequest} parameter.
- *
- * @return the target partWithPort
- */
- private Property getTargetPartWithPort(IEditCommandRequest req) {
- Property result = null;
- if(getTargetRole(req) instanceof Port) {
- // Only look for PartWithPort if the role is a Port.
-
- View parentView = ViewUtil.getContainerView(RequestParameterUtils.getTargetView(req));
- EObject semanticParent = parentView.getElement();
- if((semanticParent instanceof Property) && !(semanticParent instanceof Port)) {
- // Only add PartWithPort for assembly (not for delegation)
- if(!EcoreUtil.isAncestor(parentView, RequestParameterUtils.getSourceView(req))) {
- result = (Property)semanticParent;
- }
- }
-
- }
-
- return result;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected ICommand getConfigureCommand(final ConfigureRequest req) {
-
- final Connector connector = (Connector)req.getElementToConfigure();
- final ConnectableElement sourceRole = getSourceRole(req);
- final ConnectableElement targetRole = getTargetRole(req);
- final Property sourcePartWithPort = getSourcePartWithPort(req);
- final Property targetPartWithPort = getTargetPartWithPort(req);
-
- ICommand configureCommand = new ConfigureElementCommand(req) {
-
- protected CommandResult doExecuteWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
-
- if((sourceRole == null) || (targetRole == null)) {
- //to allow creation from the ModelExplorer or from the table
- //return CommandResult.newCancelledCommandResult();
- }
-
- // Add source connector end
- ConnectorEnd sourceEnd = UMLFactory.eINSTANCE.createConnectorEnd();
- sourceEnd.setRole(sourceRole);
- sourceEnd.setPartWithPort(sourcePartWithPort);
-
- // Add target connector end
- ConnectorEnd targetEnd = UMLFactory.eINSTANCE.createConnectorEnd();
- targetEnd.setRole(targetRole);
- targetEnd.setPartWithPort(targetPartWithPort);
-
- connector.getEnds().add(sourceEnd);
- connector.getEnds().add(targetEnd);
-
- return CommandResult.newOKCommandResult(connector);
- }
- };
-
- return CompositeCommand.compose(configureCommand, super.getConfigureCommand(req));
- }
-
- private StructuredClassifier deduceContainer(CreateRelationshipRequest request) {
- return new ConnectorUtils().deduceContainer(RequestParameterUtils.getSourceView(request), RequestParameterUtils.getTargetView(request));
- }
-
- private List<View> getStructureContainers(View view) {
- return new ConnectorUtils().getStructureContainers(view);
- }
-}
+/*****************************************************************************
+
+ * Copyright (c) 2011-2012 CEA LIST.
+ *
+ * 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.uml.service.types.helper;
+
+import java.util.List;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.common.core.command.CompositeCommand;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.common.core.command.IdentityCommand;
+import org.eclipse.gmf.runtime.common.core.command.UnexecutableCommand;
+import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
+import org.eclipse.gmf.runtime.emf.type.core.commands.ConfigureElementCommand;
+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;
+import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
+import org.eclipse.gmf.runtime.emf.type.core.requests.ReorientRelationshipRequest;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.uml.service.types.command.ConnectorReorientCommand;
+import org.eclipse.papyrus.uml.service.types.utils.ConnectorUtils;
+import org.eclipse.papyrus.uml.service.types.utils.RequestParameterUtils;
+import org.eclipse.uml2.uml.ConnectableElement;
+import org.eclipse.uml2.uml.Connector;
+import org.eclipse.uml2.uml.ConnectorEnd;
+import org.eclipse.uml2.uml.Port;
+import org.eclipse.uml2.uml.Property;
+import org.eclipse.uml2.uml.StructuredClassifier;
+import org.eclipse.uml2.uml.UMLFactory;
+
+/**
+ * Edit helper class for binary {@link Connector}
+ */
+public class ConnectorEditHelper extends ElementEditHelper {
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected ICommand getReorientRelationshipCommand(ReorientRelationshipRequest req) {
+ return new ConnectorReorientCommand(req);
+ }
+
+ /**
+ * Test if the relationship creation is allowed.
+ *
+ * @param source
+ * the relationship source can be null
+ * @param target
+ * the relationship target can be null
+ * @param sourceView
+ * the relationship graphical source can be null
+ * @param targetView
+ * the relationship graphical target can be null
+ * @return true if the creation is allowed
+ */
+ protected boolean canCreate(EObject source, EObject target, View sourceView, View targetView) {
+
+ if((source != null) && !(source instanceof ConnectableElement)) {
+ return false;
+ }
+
+ if((target != null) && !(target instanceof ConnectableElement)) {
+ return false;
+ }
+
+ if((sourceView != null) && (targetView != null)) {
+ // Cannot create a self connector on a view
+ if(sourceView == targetView) {
+ return false;
+ }
+
+ // Cannot create a connector from a view representing a Part to its own Port (or the opposite)
+ if((sourceView.getChildren().contains(targetView)) || (targetView.getChildren().contains(sourceView))) {
+ return false;
+ }
+
+ // Cannot connect a Part to one of its (possibly indirect) containment, must connect to one of its Port.
+ if(getStructureContainers(sourceView).contains(targetView) || getStructureContainers(targetView).contains(sourceView)) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ /**
+ * {@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) {
+
+ if (!(source instanceof ConnectableElement)){
+ return UnexecutableCommand.INSTANCE;
+ }
+ // The request isn't complete yet. Return the identity command so
+ // that the create relationship gesture is enabled.
+ return IdentityCommand.INSTANCE;
+
+ }
+
+ if (source != null && target != null){
+ // Propose a semantic container for the new Connector.
+ StructuredClassifier proposedContainer = deduceContainer(req);
+ if(proposedContainer == null) {
+ return UnexecutableCommand.INSTANCE;
+ }
+
+ EObject container = req.getContainer();
+ if (container != proposedContainer){
+ req.setContainer(proposedContainer);
+ return new CreateRelationshipCommand(req);
+ }
+
+ }
+
+ boolean umlStrict = true;
+ if (!req.getParameters().isEmpty()){
+ Object umlStrictParameter = req.getParameter(org.eclipse.papyrus.uml.service.types.utils.RequestParameterConstants.UML_STRICT);
+ if (umlStrictParameter instanceof Boolean){
+ umlStrict = (Boolean) umlStrictParameter;
+ }
+ }
+
+ boolean canCreate = true;
+
+ if (umlStrict){
+ canCreate = canCreate(source, target, RequestParameterUtils.getSourceView(req), RequestParameterUtils.getTargetView(req));
+ }
+ if(!noSourceAndTarget && !canCreate) {
+ // Abort creation.
+ return UnexecutableCommand.INSTANCE;
+ }
+ return new CreateRelationshipCommand(req);
+ }
+
+ /**
+ * This method provides the source role provided as {@link ConfigureRequest} parameter.
+ *
+ * @return the target role
+ */
+ private ConnectableElement getSourceRole(IEditCommandRequest req) {
+ ConnectableElement result = null;
+ Object paramObject = req.getParameter(CreateRelationshipRequest.SOURCE);
+ if(paramObject instanceof ConnectableElement) {
+ result = (ConnectableElement)paramObject;
+ }
+
+ return result;
+ }
+
+ /**
+ * This method provides the target role provided as {@link ConfigureRequest} parameter.
+ *
+ * @return the target role
+ */
+ private ConnectableElement getTargetRole(IEditCommandRequest req) {
+ ConnectableElement result = null;
+ Object paramObject = req.getParameter(CreateRelationshipRequest.TARGET);
+ if(paramObject instanceof ConnectableElement) {
+ result = (ConnectableElement)paramObject;
+ }
+
+ return result;
+ }
+
+ /**
+ * This method provides the source partWithPort provided as {@link ConfigureRequest} parameter.
+ *
+ * @return the target partWithPort
+ */
+ private Property getSourcePartWithPort(IEditCommandRequest req) {
+ Property result = null;
+ if(getSourceRole(req) instanceof Port) {
+ // Only look for PartWithPort if the role is a Port.
+
+ View parentView = ViewUtil.getContainerView(RequestParameterUtils.getSourceView(req));
+ EObject semanticParent = parentView.getElement();
+ if((semanticParent instanceof Property) && !(semanticParent instanceof Port)) {
+ // Only add PartWithPort for assembly (not for delegation)
+ if(!EcoreUtil.isAncestor(parentView, RequestParameterUtils.getTargetView(req))) {
+ result = (Property)semanticParent;
+ }
+ }
+
+ }
+ return result;
+ }
+
+ /**
+ * This method provides the target partWithPort provided as {@link ConfigureRequest} parameter.
+ *
+ * @return the target partWithPort
+ */
+ private Property getTargetPartWithPort(IEditCommandRequest req) {
+ Property result = null;
+ if(getTargetRole(req) instanceof Port) {
+ // Only look for PartWithPort if the role is a Port.
+
+ View parentView = ViewUtil.getContainerView(RequestParameterUtils.getTargetView(req));
+ EObject semanticParent = parentView.getElement();
+ if((semanticParent instanceof Property) && !(semanticParent instanceof Port)) {
+ // Only add PartWithPort for assembly (not for delegation)
+ if(!EcoreUtil.isAncestor(parentView, RequestParameterUtils.getSourceView(req))) {
+ result = (Property)semanticParent;
+ }
+ }
+
+ }
+
+ return result;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected ICommand getConfigureCommand(final ConfigureRequest req) {
+
+ final Connector connector = (Connector)req.getElementToConfigure();
+ final ConnectableElement sourceRole = getSourceRole(req);
+ final ConnectableElement targetRole = getTargetRole(req);
+ final Property sourcePartWithPort = getSourcePartWithPort(req);
+ final Property targetPartWithPort = getTargetPartWithPort(req);
+
+ ICommand configureCommand = new ConfigureElementCommand(req) {
+
+ protected CommandResult doExecuteWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
+
+ if((sourceRole == null) || (targetRole == null)) {
+ //to allow creation from the ModelExplorer or from the table
+ //return CommandResult.newCancelledCommandResult();
+ }
+
+ // Add source connector end
+ ConnectorEnd sourceEnd = UMLFactory.eINSTANCE.createConnectorEnd();
+ sourceEnd.setRole(sourceRole);
+ sourceEnd.setPartWithPort(sourcePartWithPort);
+
+ // Add target connector end
+ ConnectorEnd targetEnd = UMLFactory.eINSTANCE.createConnectorEnd();
+ targetEnd.setRole(targetRole);
+ targetEnd.setPartWithPort(targetPartWithPort);
+
+ connector.getEnds().add(sourceEnd);
+ connector.getEnds().add(targetEnd);
+
+ return CommandResult.newOKCommandResult(connector);
+ }
+ };
+
+ return CompositeCommand.compose(configureCommand, super.getConfigureCommand(req));
+ }
+
+ private StructuredClassifier deduceContainer(CreateRelationshipRequest request) {
+ return new ConnectorUtils().deduceContainer(RequestParameterUtils.getSourceView(request), RequestParameterUtils.getTargetView(request));
+ }
+
+ private List<View> getStructureContainers(View view) {
+ return new ConnectorUtils().getStructureContainers(view);
+ }
+}

Back to the top