Bug 508337 - [SysML1.4][IBD] Full port - Connectors for ports of Full
Ports have incomplete NestedConnectorEnd path
- allow Port as structure container
- deprecate the cancreate in UMLConnectorUtils and move it in
ConnectorCreationEditHelperAdvice (The test should be done in approve
request not with a static method)
Change-Id: I7206398281915e5eb8b57a595e1e99221f192488
Signed-off-by: Benoit Maggi <benoit.maggi@cea.fr>
diff --git a/core/org.eclipse.papyrus.sysml14.service.types/src/org/eclipse/papyrus/sysml14/service/types/advice/ConnectorCreationEditHelperAdvice.java b/core/org.eclipse.papyrus.sysml14.service.types/src/org/eclipse/papyrus/sysml14/service/types/advice/ConnectorCreationEditHelperAdvice.java
index b9a7ebe..882bdfc 100644
--- a/core/org.eclipse.papyrus.sysml14.service.types/src/org/eclipse/papyrus/sysml14/service/types/advice/ConnectorCreationEditHelperAdvice.java
+++ b/core/org.eclipse.papyrus.sysml14.service.types/src/org/eclipse/papyrus/sysml14/service/types/advice/ConnectorCreationEditHelperAdvice.java
@@ -31,6 +31,7 @@
import org.eclipse.papyrus.sysml14.service.types.util.UMLConnectorUtils;
import org.eclipse.papyrus.uml.service.types.element.UMLElementTypes;
import org.eclipse.papyrus.uml.service.types.utils.RequestParameterUtils;
+import org.eclipse.uml2.uml.ConnectableElement;
import org.eclipse.uml2.uml.Property;
/**
@@ -64,7 +65,7 @@
// Restrict this advice action to the end of Connector creation gesture (before clicking on target)
// in order to add SysML specific constraint
if ((Arrays.asList(request.getElementType().getAllSuperTypes()).contains(UMLElementTypes.CONNECTOR))
- && (request.getSource() != null) && (request.getTarget() != null) && (request.getContainer() != null)) {
+ && (source != null) && (target != null) && (request.getContainer() != null)) {
// Restrict action to SysML Connector (meaning owned by Block)
if (((ISpecializationType) ElementTypeRegistry.getInstance().getType(SysMLServiceTypeUtil.ORG_ECLIPSE_PAPYRUS_SYSML14_BLOCK)).getMatcher().matches(request.getContainer())) {
@@ -74,7 +75,7 @@
|| ConnectorUtil.isCrossingEncapsulation(targetView, sourceView)) {
return UnexecutableCommand.INSTANCE;
}
- if (UMLConnectorUtils.canCreate(source, target, sourceView, targetView)) {
+ if (canCreate(source, target, sourceView, targetView)) {
request.setParameter(org.eclipse.papyrus.uml.service.types.utils.RequestParameterConstants.UML_STRICT, false);
}
}
@@ -107,14 +108,14 @@
// Check if source view is nested
if (utils.isNestedConnectableElement(sourceView, targetView)) {
List<Property> nestedPath = utils.getNestedPropertyPath(sourceView, targetView);
- SetNestedPathCommand next = new SetNestedPathCommand("Set connector nested source path", request.getNewElement(), request, nestedPath, SetNestedPathCommand.NESTED_SOURCE);
+ SetNestedPathCommand next = new SetNestedPathCommand("Set connector nested source path from source to target", request.getNewElement(), request, nestedPath, SetNestedPathCommand.NESTED_SOURCE);
defaultCommand = CompositeCommand.compose(defaultCommand, next);
}
// Check if target view is nested
if (utils.isNestedConnectableElement(targetView, sourceView)) {
List<Property> nestedPath = utils.getNestedPropertyPath(targetView, sourceView);
- SetNestedPathCommand next = new SetNestedPathCommand("Set connector nested source path", request.getNewElement(), request, nestedPath, SetNestedPathCommand.NESTED_TARGET);
+ SetNestedPathCommand next = new SetNestedPathCommand("Set connector nested source path from target to source", request.getNewElement(), request, nestedPath, SetNestedPathCommand.NESTED_TARGET);
defaultCommand = CompositeCommand.compose(defaultCommand, next);
}
}
@@ -122,4 +123,43 @@
return defaultCommand;
}
+
+ /**
+ * 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
+ */
+ //FIXME test creation should be done in approve request
+ private 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 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 (utils.getStructureContainers(sourceView).contains(targetView) || utils.getStructureContainers(targetView).contains(sourceView)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
}
diff --git a/core/org.eclipse.papyrus.sysml14.service.types/src/org/eclipse/papyrus/sysml14/service/types/util/UMLConnectorUtils.java b/core/org.eclipse.papyrus.sysml14.service.types/src/org/eclipse/papyrus/sysml14/service/types/util/UMLConnectorUtils.java
index af7ce14..db93aa6 100644
--- a/core/org.eclipse.papyrus.sysml14.service.types/src/org/eclipse/papyrus/sysml14/service/types/util/UMLConnectorUtils.java
+++ b/core/org.eclipse.papyrus.sysml14.service.types/src/org/eclipse/papyrus/sysml14/service/types/util/UMLConnectorUtils.java
@@ -8,8 +8,8 @@
*
* Contributors:
*
- * CEA LIST - Initial API and implementation
- *
+ * CEA LIST - Initial API and implementation
+ * Benoit Maggi (CEA LIST) benoit.maggi@cea.fr - 508337
*****************************************************************************/
package org.eclipse.papyrus.sysml14.service.types.util;
@@ -130,21 +130,13 @@
*/
public View getNearestStructureContainer(View view) {
View nearestStructureContainer = null;
-
for (View containerView : getStructureContainers(view)) {
-
if (view == containerView) {
continue;
}
-
- if ((view.getElement() instanceof Port) && (containerView.getChildren().contains(view))) {
- continue;
- }
-
nearestStructureContainer = containerView;
break;
}
-
return nearestStructureContainer;
}
@@ -234,6 +226,8 @@
/**
* Test if the relationship creation is allowed.
*
+ * @deprecated in 0.10.1 (will be removed in 0.11.0)
+ *
* @param source
* the relationship source can be null
* @param target
@@ -244,6 +238,7 @@
* the relationship graphical target can be null
* @return true if the creation is allowed
*/
+ @Deprecated // test creation should be done in approve request
public static boolean canCreate(EObject source, EObject target, View sourceView, View targetView) {
if ((source != null) && !(source instanceof ConnectableElement)) {