Skip to content

Commit

Permalink
eclipse-capella#2884 Improve DnD on DeploymentLinks
Browse files Browse the repository at this point in the history
When multiple DeploymentsLinks are enabled, the drag and drop of a
Component or a Part with several DeploymentLinks doesn't remove existing
DeploymentsLinks that are not affected by the reference update.

Signed-off-by: Glenn Plouhinec <[email protected]>
  • Loading branch information
GlennPlou committed Oct 15, 2024
1 parent b3844fb commit b030757
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2020 THALES GLOBAL SERVICES.
* Copyright (c) 2006, 2024 THALES GLOBAL SERVICES.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand Down Expand Up @@ -718,7 +718,7 @@ public boolean isValidDndABComponent(Component semanticObjectToDrop, EObject tar
* Returns whether the given part can be dropped into the target element view
*/
public boolean isValidDndABComponent(Part semanticObjectToDrop, EObject targetContainerView) {
EObject context = null;
final EObject context;

Component component = (Component) semanticObjectToDrop.getAbstractType();
if (component.isActor()) {
Expand All @@ -727,6 +727,10 @@ public boolean isValidDndABComponent(Part semanticObjectToDrop, EObject targetCo
}

context = CsServices.getService().getABTarget((DSemanticDecorator) targetContainerView);
boolean isSourceAlreadyDeployed = semanticObjectToDrop.getDeployingLinks().stream().anyMatch(link -> link.getLocation().equals(context));
if (isSourceAlreadyDeployed) {
return false;
}
if (context instanceof BlockArchitecture) {
return false;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2020 THALES GLOBAL SERVICES.
* Copyright (c) 2006, 2024 THALES GLOBAL SERVICES.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand Down Expand Up @@ -2988,7 +2988,10 @@ public EObject dndABDeployment(NamedElement pcMoved, NamedElement oldContainer,
}

// move all deploying links
for (AbstractDeploymentLink link : new ArrayList<AbstractDeploymentLink>(component.getDeployingLinks())) {
List<AbstractDeploymentLink> deployingLinksToUpdate = component.getDeployingLinks().stream()
.filter(link -> link.getLocation().equals(oldContainer))
.toList();
for (AbstractDeploymentLink link : deployingLinksToUpdate) {
link.setLocation(newComponent);
newComponent.getOwnedDeploymentLinks().add(link);
}
Expand All @@ -3009,7 +3012,10 @@ public EObject dndABDeployment(NamedElement pcMoved, NamedElement oldContainer,
}

// move all deploying links
for (AbstractDeploymentLink link : new ArrayList<AbstractDeploymentLink>(currentPart.getDeployingLinks())) {
List<AbstractDeploymentLink> deployingLinksToUpdate = currentPart.getDeployingLinks().stream()
.filter(link -> link.getLocation().equals(oldContainer))
.toList();
for (AbstractDeploymentLink link : deployingLinksToUpdate) {
link.setLocation(newPart);
newPart.getOwnedDeploymentLinks().add(link);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2020 THALES GLOBAL SERVICES.
* Copyright (c) 2019, 2024 THALES GLOBAL SERVICES.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand Down Expand Up @@ -46,6 +46,7 @@ public void test() throws Exception {

testDnDComponentsFromProjectExplorer(context);
testDnDComponentsBehaviorAndNodeDeployedOrNot(session, context);
testDnDComponentsMultipleDeployements(session, context);
}

public void testDnDComponentsFromProjectExplorer(SessionContext context) {
Expand All @@ -66,6 +67,23 @@ public void testOnXAB(SessionContext context, String diagramName, String contain
.run();
}

public void testDnDComponentsMultipleDeployements(Session session, SessionContext context) throws Exception {
String PC6 = PA__PAB_COMPONENT_PC6_PART;
String PC9 = PA__PAB_PHYSICAL_COMPONENT9;
String PC14 = PA__PC_PART_PC14;
String PC10 = PA__PAB_PC_COMPONENT10;
assertEquals(false, testDnDOnPAB(session, context, PA__PAB_DIAGRAM, PC10, PC9));
Runnable checksDnD_PC10toPC6 = () -> {
Part semanticPC10 = (Part) context.getSemanticElement(PC10);
EObject semanticPC9 = context.getSemanticElement(PC9);
EObject semanticPC14 = context.getSemanticElement(PC14);

assertTrue(semanticPC10.getDeployingParts().contains(semanticPC9));
assertFalse(semanticPC10.getDeployingParts().contains(semanticPC14));
};
assertEquals(true, testDnDOnPAB(session, context, PA__PAB_DIAGRAM, PC10, PC6, checksDnD_PC10toPC6));
}

public void testDnDComponentsBehaviorAndNodeDeployedOrNot(Session session, SessionContext context) throws Exception {
List<String> draggedElements = new ArrayList<>();
List<String> containerElements = new ArrayList<>();
Expand Down Expand Up @@ -124,6 +142,8 @@ public void testDnDComponentsBehaviorAndNodeDeployedOrNot(Session session, Sessi
expectedNotPossible.add(new Pair<>(NOT_DEPLOYED_BEHAVIOR_DRAGGED, NOT_DEPLOYED_NODE_CONTAINER));
expectedNotPossible.add(new Pair<>(NOT_DEPLOYED_BEHAVIOR_DRAGGED, DEPLOYED_NODE_CONTAINER));
expectedNotPossible.add(new Pair<>(NOT_DEPLOYED_BEHAVIOR_DRAGGED, ACTOR_CONTAINER));
// Moving PC 8 from PC 1 to PC 1 is not a drag and drop.
expectedNotPossible.add(new Pair<>(DEPLOYED_NODE_DRAGGED, NOT_DEPLOYED_NODE_CONTAINER));

// Now testing all combinations of dragged elements and containers
for (String draggedElement : draggedElements) {
Expand All @@ -144,6 +164,11 @@ public void testDnDComponentsBehaviorAndNodeDeployedOrNot(Session session, Sessi
}
}

public boolean testDnDOnPAB(//
Session session, SessionContext context, String diagramName, String draggedElement, String containerElement) throws Exception {
return testDnDOnPAB(session, context, diagramName, draggedElement, containerElement, null);
}

/**
* Return true if the Drag&Drop of draggedElement into containerElement in PAB diagramName is valid
*
Expand All @@ -156,7 +181,7 @@ public void testDnDComponentsBehaviorAndNodeDeployedOrNot(Session session, Sessi
* @throws Exception
*/
public boolean testDnDOnPAB(//
Session session, SessionContext context, String diagramName, String draggedElement, String containerElement)
Session session, SessionContext context, String diagramName, String draggedElement, String containerElement, Runnable additionalAssertions)
throws Exception {
DiagramContext diagramContext = new OpenDiagramStep(context, diagramName).run();
XABDiagram diagram = XABDiagram.openDiagram(context, diagramName, BlockArchitectureExt.Type.PA);
Expand All @@ -175,6 +200,9 @@ public boolean testDnDOnPAB(//
if (containerView instanceof DDiagramElementContainer) {
DDiagramElementContainer dContainer = (DDiagramElementContainer) containerView;
boolean result = dContainer.getElements().contains(draggedElementView);
if (additionalAssertions != null) {
additionalAssertions.run();
}
undo(session, diagramContext);
return result;
}
Expand Down

0 comments on commit b030757

Please sign in to comment.