Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenoit Maggi2014-01-30 08:10:48 -0500
committervlorenzo2014-01-31 07:35:18 -0500
commit1eaaf3cec9afacfc9413be01455bf0cedc98efb1 (patch)
tree84b5f508c74a5f671924903b2cd8e36a2103afcc /plugins
parent5ed67de8ae01238b3bc16474b5a3727d606a19b6 (diff)
downloadorg.eclipse.papyrus-1eaaf3cec9afacfc9413be01455bf0cedc98efb1.tar.gz
org.eclipse.papyrus-1eaaf3cec9afacfc9413be01455bf0cedc98efb1.tar.xz
org.eclipse.papyrus-1eaaf3cec9afacfc9413be01455bf0cedc98efb1.zip
Bug 418586 - [Connector] [UML] [SysML] [CompositeStructureDiagram]
Problems with UML/SysML Connector Allow connector : - on the same port - between ports of the same part - between ports of the same Block Change-Id: If0e0391d10e8a15ff15471a30d87f60927bebf35 Signed-off-by: Benoit Maggi <benoit.maggi@cea.fr>
Diffstat (limited to 'plugins')
-rw-r--r--plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/helper/advice/BlockConnectorEditHelperAdvice.java212
-rw-r--r--plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/utils/ConnectorUtils.java41
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/ConnectorEditHelper.java560
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/utils/RequestParameterConstants.java55
4 files changed, 471 insertions, 397 deletions
diff --git a/plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/helper/advice/BlockConnectorEditHelperAdvice.java b/plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/helper/advice/BlockConnectorEditHelperAdvice.java
index 23ea34dc511..90237b7c6cd 100644
--- a/plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/helper/advice/BlockConnectorEditHelperAdvice.java
+++ b/plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/helper/advice/BlockConnectorEditHelperAdvice.java
@@ -1,103 +1,109 @@
-/*****************************************************************************
- * Copyright (c) 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.sysml.service.types.helper.advice;
-
-import java.util.List;
-
-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.UnexecutableCommand;
-import org.eclipse.gmf.runtime.emf.type.core.ISpecializationType;
-import org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice;
-import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.papyrus.sysml.blocks.Block;
-import org.eclipse.papyrus.sysml.service.types.command.SetNestedPathCommand;
-import org.eclipse.papyrus.sysml.service.types.element.SysMLElementTypes;
-import org.eclipse.papyrus.sysml.service.types.utils.ConnectorUtils;
-import org.eclipse.papyrus.uml.service.types.element.UMLElementTypes;
-import org.eclipse.papyrus.uml.service.types.utils.RequestParameterUtils;
-import org.eclipse.uml2.uml.Connector;
-import org.eclipse.uml2.uml.Property;
-
-/**
- * <pre>
- * This HelperAdvice completes {@link Block} edit commands with SysML
- * specific {@link Connector} related actions:
- * - Block::isEncapsulated management
- * - NestedPropertyEnd management
- * </pre>
- */
-public class BlockConnectorEditHelperAdvice extends AbstractEditHelperAdvice {
-
- private ConnectorUtils utils = new ConnectorUtils();
-
- @Override
- protected ICommand getBeforeCreateRelationshipCommand(CreateRelationshipRequest request) {
-
- View sourceView = RequestParameterUtils.getSourceView(request);
- View targetView = RequestParameterUtils.getTargetView(request);
-
- // Restrict this advice action to the end of Connector creation gesture (before clicking on target)
- // in order to add SysML specific constraint
- if((request.getElementType() == UMLElementTypes.CONNECTOR)
- && (request.getSource() != null) && (request.getTarget() != null) && (request.getContainer() != null)) {
-
- // Restrict action to SysML Connector (meaning owned by Block)
- if(((ISpecializationType)SysMLElementTypes.BLOCK).getMatcher().matches(request.getContainer())) {
-
- // If the source or target view is enclosed in a structure encapsulated view, forbid creation.
- if(utils.isCrossingEncapsulation(sourceView, targetView)
- || utils.isCrossingEncapsulation(targetView, sourceView)) {
- return UnexecutableCommand.INSTANCE;
- }
- }
- }
-
- return super.getBeforeCreateRelationshipCommand(request);
- }
-
- @Override
- protected ICommand getAfterCreateRelationshipCommand(CreateRelationshipRequest request) {
-
- ICommand defaultCommand = super.getAfterCreateRelationshipCommand(request);
-
- View sourceView = RequestParameterUtils.getSourceView(request);
- View targetView = RequestParameterUtils.getTargetView(request);
-
- // Restrict this advice action to the end of Connector creation gesture (before clicking on target)
- // in order to add SysML specific constraint
- if((request.getElementType() == UMLElementTypes.CONNECTOR)
- && (request.getSource() != null) && (request.getTarget() != null) && (request.getContainer() != null)) {
-
- // Restrict action to SysML Connector (meaning owned by Block)
- if(((ISpecializationType)SysMLElementTypes.BLOCK).getMatcher().matches(request.getContainer())) {
-
- // Check if source view is nested
- if(utils.isNestedConnectableElement(sourceView, targetView)){
- List<Property> nestedPath = utils.getNestedPropertyPath(sourceView, targetView);
- defaultCommand = CompositeCommand.compose(defaultCommand, new SetNestedPathCommand("Set connector nested source path", request.getNewElement(), request, nestedPath, SetNestedPathCommand.NESTED_SOURCE)); //$NON-NLS-0$
- }
-
- // Check if target view is nested
- if(utils.isNestedConnectableElement(targetView, sourceView)){
- List<Property> nestedPath = utils.getNestedPropertyPath(targetView, sourceView);
- defaultCommand = CompositeCommand.compose(defaultCommand, new SetNestedPathCommand("Set connector nested source path", request.getNewElement(), request, nestedPath, SetNestedPathCommand.NESTED_TARGET)); //$NON-NLS-0$
- }
- }
- }
-
- return defaultCommand;
- }
-}
+/*****************************************************************************
+ * Copyright (c) 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.sysml.service.types.helper.advice;
+
+import java.util.List;
+
+import org.eclipse.emf.ecore.EObject;
+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.UnexecutableCommand;
+import org.eclipse.gmf.runtime.emf.type.core.ISpecializationType;
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice;
+import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.sysml.blocks.Block;
+import org.eclipse.papyrus.sysml.service.types.command.SetNestedPathCommand;
+import org.eclipse.papyrus.sysml.service.types.element.SysMLElementTypes;
+import org.eclipse.papyrus.sysml.service.types.utils.ConnectorUtils;
+import org.eclipse.papyrus.uml.service.types.element.UMLElementTypes;
+import org.eclipse.papyrus.uml.service.types.utils.RequestParameterUtils;
+import org.eclipse.uml2.uml.Connector;
+import org.eclipse.uml2.uml.Property;
+
+/**
+ * <pre>
+ * This HelperAdvice completes {@link Block} edit commands with SysML
+ * specific {@link Connector} related actions:
+ * - Block::isEncapsulated management
+ * - NestedPropertyEnd management
+ * </pre>
+ */
+public class BlockConnectorEditHelperAdvice extends AbstractEditHelperAdvice {
+
+ private ConnectorUtils utils = new ConnectorUtils();
+
+ @Override
+ protected ICommand getBeforeCreateRelationshipCommand(CreateRelationshipRequest request) {
+
+ EObject source = request.getSource();
+ EObject target = request.getTarget();
+ View sourceView = RequestParameterUtils.getSourceView(request);
+ View targetView = RequestParameterUtils.getTargetView(request);
+
+ // Restrict this advice action to the end of Connector creation gesture (before clicking on target)
+ // in order to add SysML specific constraint
+ if((request.getElementType() == UMLElementTypes.CONNECTOR)
+ && (request.getSource() != null) && (request.getTarget() != null) && (request.getContainer() != null)) {
+
+ // Restrict action to SysML Connector (meaning owned by Block)
+ if(((ISpecializationType)SysMLElementTypes.BLOCK).getMatcher().matches(request.getContainer())) {
+
+ // If the source or target view is enclosed in a structure encapsulated view, forbid creation.
+ if(utils.isCrossingEncapsulation(sourceView, targetView)
+ || utils.isCrossingEncapsulation(targetView, sourceView)) {
+ return UnexecutableCommand.INSTANCE;
+ }
+ if (ConnectorUtils.canCreate(source, target, sourceView, targetView)) {
+ request.setParameter( org.eclipse.papyrus.uml.service.types.utils.RequestParameterConstants.UML_STRICT, false);
+ }
+ }
+ }
+
+ return super.getBeforeCreateRelationshipCommand(request);
+ }
+
+ @Override
+ protected ICommand getAfterCreateRelationshipCommand(CreateRelationshipRequest request) {
+
+ ICommand defaultCommand = super.getAfterCreateRelationshipCommand(request);
+
+ View sourceView = RequestParameterUtils.getSourceView(request);
+ View targetView = RequestParameterUtils.getTargetView(request);
+
+ // Restrict this advice action to the end of Connector creation gesture (before clicking on target)
+ // in order to add SysML specific constraint
+ if((request.getElementType() == UMLElementTypes.CONNECTOR)
+ && (request.getSource() != null) && (request.getTarget() != null) && (request.getContainer() != null)) {
+
+ // Restrict action to SysML Connector (meaning owned by Block)
+ if(((ISpecializationType)SysMLElementTypes.BLOCK).getMatcher().matches(request.getContainer())) {
+
+ // Check if source view is nested
+ if(utils.isNestedConnectableElement(sourceView, targetView)){
+ List<Property> nestedPath = utils.getNestedPropertyPath(sourceView, targetView);
+ defaultCommand = CompositeCommand.compose(defaultCommand, new SetNestedPathCommand("Set connector nested source path", request.getNewElement(), request, nestedPath, SetNestedPathCommand.NESTED_SOURCE)); //$NON-NLS-0$
+ }
+
+ // Check if target view is nested
+ if(utils.isNestedConnectableElement(targetView, sourceView)){
+ List<Property> nestedPath = utils.getNestedPropertyPath(targetView, sourceView);
+ defaultCommand = CompositeCommand.compose(defaultCommand, new SetNestedPathCommand("Set connector nested source path", request.getNewElement(), request, nestedPath, SetNestedPathCommand.NESTED_TARGET)); //$NON-NLS-0$
+ }
+ }
+ }
+
+ return defaultCommand;
+ }
+}
diff --git a/plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/utils/ConnectorUtils.java b/plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/utils/ConnectorUtils.java
index bb965e5a360..d9d723e6e10 100644
--- a/plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/utils/ConnectorUtils.java
+++ b/plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/utils/ConnectorUtils.java
@@ -387,4 +387,45 @@ public class ConnectorUtils extends org.eclipse.papyrus.uml.service.types.utils.
return null;
}
+ /**
+ * 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
+ */
+ public static 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)) {
+ // Allow to 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(new ConnectorUtils().getStructureContainers(sourceView).contains(targetView) || new ConnectorUtils().getStructureContainers(targetView).contains(sourceView)) {
+ return false;
+ }
+ }
+ return true;
+ }
}
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 11d1051efdb..3b4e7f9eb65 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,268 +1,292 @@
-/*****************************************************************************
- * 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(!noSourceAndTarget && !canCreate(source, target, RequestParameterUtils.getSourceView(req), RequestParameterUtils.getTargetView(req))) {
- // Abort creation.
- return UnexecutableCommand.INSTANCE;
- }
-
- if(noSourceOrTarget && !noSourceAndTarget) {
- // The request isn't complete yet. Return the identity command so
- // that the create relationship gesture is enabled.
- return IdentityCommand.INSTANCE;
- }
-
- // Propose a semantic container for the new Connector.
- StructuredClassifier proposedContainer = deduceContainer(req);
- if(proposedContainer == null) {
- return UnexecutableCommand.INSTANCE;
- }
-
- req.setContainer(proposedContainer);
-
- 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 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);
+ }
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/utils/RequestParameterConstants.java b/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/utils/RequestParameterConstants.java
index 1016cf93e4a..b7e996dc5b3 100644
--- a/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/utils/RequestParameterConstants.java
+++ b/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/utils/RequestParameterConstants.java
@@ -1,26 +1,29 @@
-/*****************************************************************************
- * 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.utils;
-
-/**
- * <pre>
- * IDs of request parameters.
- * </pre>
- * @deprecated
- * @use org.eclipse.papyrus.infra.services.edit.utils.RequestParameterConstants instead
- */
-@Deprecated
-public interface RequestParameterConstants extends org.eclipse.papyrus.infra.services.edit.utils.RequestParameterConstants {
-
-}
+/*****************************************************************************
+ * 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.utils;
+
+/**
+ * <pre>
+ * IDs of request parameters.
+ * </pre>
+ * @use org.eclipse.papyrus.infra.services.edit.utils.RequestParameterConstants instead
+ */
+public interface RequestParameterConstants extends org.eclipse.papyrus.infra.services.edit.utils.RequestParameterConstants {
+
+ /**
+ * Parameter used to override som UML Constraint (for sysml)
+ *
+ */
+ public static final String UML_STRICT = "UML_STRICT"; //$NON-NLS-1$
+}

Back to the top