From d9c63b65d3742f4e3732681e4f38364a2b888fe3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20Bausson?= Date: Wed, 20 Dec 2023 17:32:45 +0100 Subject: [PATCH] #2062 Adding a case that was untreated when DnDing ports with existing allocations. --- .../core/sirius/analysis/FaServices.java | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/core/plugins/org.polarsys.capella.core.sirius.analysis/src/org/polarsys/capella/core/sirius/analysis/FaServices.java b/core/plugins/org.polarsys.capella.core.sirius.analysis/src/org/polarsys/capella/core/sirius/analysis/FaServices.java index aa374df12f..93b8608771 100644 --- a/core/plugins/org.polarsys.capella.core.sirius.analysis/src/org/polarsys/capella/core/sirius/analysis/FaServices.java +++ b/core/plugins/org.polarsys.capella.core.sirius.analysis/src/org/polarsys/capella/core/sirius/analysis/FaServices.java @@ -3090,15 +3090,22 @@ private Collection retrieveObsoletePortAllocations(Port movingPort, boolean includeComponentRealization, boolean topDelegation, boolean bottomDelegation) { Collection elements = new HashSet(); Collection allocations = retrievePortAllocations(movingPort, includeFunctionalRealization, includeComponentRealization); - Component instanciatedComponent = null; if (newContainer instanceof Part) { - instanciatedComponent = PartExt.getComponentOfPart((Part) newContainer); - } - for (Allocation allocation : allocations) { - Port delegatedPort = (allocation.getSourceElement() == movingPort) ? (Port) allocation.getTargetElement() : (Port) allocation.getSourceElement(); - if (instanciatedComponent == null || !isEObjectInHierarchyOfContainer(delegatedPort.eContainer(), instanciatedComponent)) { + // case where moving the component's port + Component instanciatedComponent = PartExt.getComponentOfPart((Part) newContainer); + for (Allocation allocation : allocations) { + Port delegatedPort = (allocation.getSourceElement() == movingPort) ? (Port) allocation.getTargetElement() : (Port) allocation.getSourceElement(); + if (instanciatedComponent == null || !isEObjectInHierarchyOfContainer(delegatedPort.eContainer(), instanciatedComponent)) { elements.add(allocation); } + } + } else if (newContainer instanceof AbstractFunction) { + // case where moving the function's port + for (Allocation allocation : allocations) { + if (!isEObjectInHierarchyOfContainer(newContainer, allocation.getSourceElement().eContainer())) { + elements.add(allocation); + } + } } return elements; } @@ -3111,7 +3118,7 @@ private Collection retrieveObsoletePortAllocations(Port movingPort, * @param container * @return */ - private boolean isEObjectInHierarchyOfContainer(EObject eObject, NamedElement container) { + private boolean isEObjectInHierarchyOfContainer(EObject eObject, EObject container) { if (eObject == null || container == null) { return false; } else if (eObject == container) {