Skip to content

Commit

Permalink
eclipse-capella#2062 Adding a case that was untreated when DnDing por…
Browse files Browse the repository at this point in the history
…ts with existing allocations.
  • Loading branch information
ebausson-obeo authored and SteveMonnier committed Jan 26, 2024
1 parent f15eaac commit d9c63b6
Showing 1 changed file with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3090,15 +3090,22 @@ private Collection<Allocation> retrieveObsoletePortAllocations(Port movingPort,
boolean includeComponentRealization, boolean topDelegation, boolean bottomDelegation) {
Collection<Allocation> elements = new HashSet<Allocation>();
Collection<Allocation> 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;
}
Expand All @@ -3111,7 +3118,7 @@ private Collection<Allocation> 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) {
Expand Down

0 comments on commit d9c63b6

Please sign in to comment.