Skip to content

Commit 75f80e3

Browse files
committed
[1546] Fix DnD from the diagram background to a Package node
Bug: #1546 Signed-off-by: Axel RICHARD <axel.richard@obeo.fr>
1 parent 0e49e05 commit 75f80e3

12 files changed

Lines changed: 385 additions & 217 deletions

File tree

CHANGELOG.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ As a consequence, the `syson-table-requirements-view` and `syson-common-view` mo
5959
`GetIntermediateContainerCreationSwitch.java` has been moved from `syson-application-configuration` to `syson-services`.
6060
- https://github.com/eclipse-syson/syson/issues/1245[#1245] [syson] Standardize read-only computation.
6161
The class `SysMLReadOnlyService` and the interface `ISysMLReadOnlyService` have been removed, use `IReadOnlyObjectPredicate` instead.
62+
- https://github.com/eclipse-syson/syson/issues/1546[#1546] [diagrams] Fix drag and drop of a graphical node from the diagram background into a _Package_ graphical node.
63+
As a consequence, the `ViewToolService#expose` method has been moved into `ToolService.java` and `NodeFinder.java` has been moved from `syson-diagram-common-view` to `syson-services`.
64+
6265

6366
=== Dependency update
6467

@@ -79,6 +82,7 @@ This issue was not visible in SysON but could appear in downstream applications
7982
Now it has been fixed in Sirius Web 2025.8.4, `SysONUpdateLibraryExecutor` has been deleted and `UpdateLibraryExecutor` is used again.
8083
- https://github.com/eclipse-syson/syson/issues/1522[#1522] [diagrams] To avoid edge blinking when refreshing the diagram, we need to set the properties `measured.height` and `measured.width` with the value of the node layout data when converting a custom node accordingly to the xyflow https://reactflow.dev/learn/advanced-use/ssr-ssg-configuration#node-dimensions[documentation].
8184
- https://github.com/eclipse-syson/syson/issues/1545[#1545] [diagrams] Add _interconnection_ compartment to `PartDefinition` nodes in the standard diagrams.
85+
- https://github.com/eclipse-syson/syson/issues/1546[#1546] [diagrams] Fix drag and drop of a graphical node from the diagram background into a _Package_ graphical node.
8286

8387
=== Improvements
8488

backend/application/syson-application/src/test/java/org/eclipse/syson/application/controllers/diagrams/compartments/ActionTransitionUsagesTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@
3333
import org.eclipse.syson.AbstractIntegrationTests;
3434
import org.eclipse.syson.application.controllers.diagrams.testers.ToolTester;
3535
import org.eclipse.syson.application.data.ActionTransitionUsagesProjectData;
36-
import org.eclipse.syson.diagram.common.view.services.NodeFinder;
3736
import org.eclipse.syson.services.diagrams.DiagramDescriptionIdProvider;
3837
import org.eclipse.syson.services.diagrams.api.IGivenDiagramDescription;
3938
import org.eclipse.syson.services.diagrams.api.IGivenDiagramReference;
4039
import org.eclipse.syson.services.diagrams.api.IGivenDiagramSubscription;
4140
import org.eclipse.syson.standard.diagrams.view.SDVDescriptionNameGenerator;
4241
import org.eclipse.syson.sysml.SysmlPackage;
4342
import org.eclipse.syson.util.IDescriptionNameGenerator;
43+
import org.eclipse.syson.util.NodeFinder;
4444
import org.eclipse.syson.util.SysONRepresentationDescriptionIdentifiers;
4545
import org.junit.jupiter.api.AfterEach;
4646
import org.junit.jupiter.api.BeforeEach;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025 Obeo.
3+
* This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v2.0
5+
* which accompanies this distribution, and is available at
6+
* https://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*
10+
* Contributors:
11+
* Obeo - initial API and implementation
12+
*******************************************************************************/
13+
package org.eclipse.syson.application.controllers.diagrams.general.view;
14+
15+
import static org.assertj.core.api.Assertions.assertThat;
16+
import static org.eclipse.sirius.components.diagrams.tests.DiagramEventPayloadConsumer.assertRefreshedDiagramThat;
17+
18+
import com.jayway.jsonpath.JsonPath;
19+
20+
import java.time.Duration;
21+
import java.util.UUID;
22+
import java.util.concurrent.atomic.AtomicReference;
23+
import java.util.function.Consumer;
24+
25+
import org.eclipse.sirius.components.collaborative.diagrams.dto.DiagramEventInput;
26+
import org.eclipse.sirius.components.collaborative.diagrams.dto.DiagramRefreshedEventPayload;
27+
import org.eclipse.sirius.components.collaborative.diagrams.dto.DropNodeInput;
28+
import org.eclipse.sirius.components.core.api.SuccessPayload;
29+
import org.eclipse.sirius.components.diagrams.tests.graphql.DropNodeMutationRunner;
30+
import org.eclipse.sirius.components.diagrams.tests.navigation.DiagramNavigator;
31+
import org.eclipse.sirius.web.tests.services.api.IGivenInitialServerState;
32+
import org.eclipse.syson.AbstractIntegrationTests;
33+
import org.eclipse.syson.application.data.GeneralViewWithTopNodesTestProjectData;
34+
import org.eclipse.syson.services.diagrams.api.IGivenDiagramSubscription;
35+
import org.junit.jupiter.api.BeforeEach;
36+
import org.junit.jupiter.api.DisplayName;
37+
import org.junit.jupiter.api.Test;
38+
import org.springframework.beans.factory.annotation.Autowired;
39+
import org.springframework.boot.test.context.SpringBootTest;
40+
import org.springframework.test.context.jdbc.Sql;
41+
import org.springframework.test.context.jdbc.SqlConfig;
42+
import org.springframework.transaction.annotation.Transactional;
43+
44+
import reactor.core.publisher.Flux;
45+
import reactor.test.StepVerifier;
46+
47+
/**
48+
* Tests the drag and drop of nodes inside the General View diagram.
49+
*
50+
* @author arichard
51+
*/
52+
@Transactional
53+
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
54+
public class GVDropFromDiagramTests extends AbstractIntegrationTests {
55+
56+
@Autowired
57+
private IGivenInitialServerState givenInitialServerState;
58+
59+
@Autowired
60+
private IGivenDiagramSubscription givenDiagramSubscription;
61+
62+
@Autowired
63+
private DropNodeMutationRunner dropNodeMutationRunner;
64+
65+
private Flux<DiagramRefreshedEventPayload> givenSubscriptionToDiagram() {
66+
var diagramEventInput = new DiagramEventInput(UUID.randomUUID(),
67+
GeneralViewWithTopNodesTestProjectData.EDITING_CONTEXT_ID,
68+
GeneralViewWithTopNodesTestProjectData.GraphicalIds.DIAGRAM_ID);
69+
var flux = this.givenDiagramSubscription.subscribe(diagramEventInput);
70+
return flux;
71+
}
72+
73+
@BeforeEach
74+
public void beforeEach() {
75+
this.givenInitialServerState.initialize();
76+
}
77+
78+
@DisplayName("Given a diagram with some nodes, when a node is dropped in another one, then the diagram is updated")
79+
@Sql(scripts = { GeneralViewWithTopNodesTestProjectData.SCRIPT_PATH }, executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD,
80+
config = @SqlConfig(transactionMode = SqlConfig.TransactionMode.ISOLATED))
81+
@Sql(scripts = { "/scripts/cleanup.sql" }, executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD, config = @SqlConfig(transactionMode = SqlConfig.TransactionMode.ISOLATED))
82+
@Test
83+
public void dropPartFromDiagramToPackageThenFromPackageToPart() {
84+
var flux = this.givenSubscriptionToDiagram();
85+
86+
var diagramId = new AtomicReference<String>();
87+
var packageNodeId = new AtomicReference<String>();
88+
var partNodeId = new AtomicReference<String>();
89+
90+
Consumer<Object> initialDiagramContentConsumer = assertRefreshedDiagramThat(diagram -> {
91+
diagramId.set(diagram.getId());
92+
93+
var packageNode = new DiagramNavigator(diagram).nodeWithLabel("Package").getNode();
94+
packageNodeId.set(packageNode.getId());
95+
96+
var partNode = new DiagramNavigator(diagram).nodeWithLabel("\u00ABref part\u00BB\npart").getNode();
97+
partNodeId.set(partNode.getId());
98+
99+
assertThat(packageNode.getChildNodes()).hasSize(0);
100+
});
101+
102+
Runnable dropPartNodeFromDiagramToPackage = () -> {
103+
var input = new DropNodeInput(
104+
UUID.randomUUID(),
105+
GeneralViewWithTopNodesTestProjectData.EDITING_CONTEXT_ID.toString(),
106+
diagramId.get(),
107+
partNodeId.get(),
108+
packageNodeId.get(),
109+
0,
110+
0);
111+
var result = this.dropNodeMutationRunner.run(input);
112+
String typename = JsonPath.read(result, "$.data.dropNode.__typename");
113+
assertThat(typename).isEqualTo(SuccessPayload.class.getSimpleName());
114+
};
115+
116+
Consumer<Object> updatedDiagramContentConsumerAfterFirstDrop = assertRefreshedDiagramThat(diagram -> {
117+
var packageNode = new DiagramNavigator(diagram).nodeWithLabel("Package").getNode();
118+
119+
var partNode = new DiagramNavigator(diagram).nodeWithLabel("\u00ABref part\u00BB\npart").getNode();
120+
partNodeId.set(partNode.getId());
121+
122+
assertThat(packageNode.getChildNodes()).hasSize(1);
123+
assertThat(packageNode.getChildNodes().get(0)).isEqualTo(partNode);
124+
});
125+
126+
Runnable dropPartNodeFromPackageToDiagram = () -> {
127+
var input = new DropNodeInput(
128+
UUID.randomUUID(),
129+
GeneralViewWithTopNodesTestProjectData.EDITING_CONTEXT_ID.toString(),
130+
diagramId.get(),
131+
partNodeId.get(),
132+
diagramId.get(),
133+
0,
134+
0);
135+
var result = this.dropNodeMutationRunner.run(input);
136+
String typename = JsonPath.read(result, "$.data.dropNode.__typename");
137+
assertThat(typename).isEqualTo(SuccessPayload.class.getSimpleName());
138+
};
139+
140+
Consumer<Object> updatedDiagramContentConsumerAfterSecondDrop = assertRefreshedDiagramThat(diagram -> {
141+
var packageNode = new DiagramNavigator(diagram).nodeWithLabel("Package").getNode();
142+
143+
var partNode = new DiagramNavigator(diagram).nodeWithLabel("\u00ABref part\u00BB\npart").getNode();
144+
145+
assertThat(packageNode.getChildNodes()).hasSize(0);
146+
assertThat(partNode).isNotNull();
147+
});
148+
149+
StepVerifier.create(flux)
150+
.consumeNextWith(initialDiagramContentConsumer)
151+
.then(dropPartNodeFromDiagramToPackage)
152+
.consumeNextWith(updatedDiagramContentConsumerAfterFirstDrop)
153+
.then(dropPartNodeFromPackageToDiagram)
154+
.consumeNextWith(updatedDiagramContentConsumerAfterSecondDrop)
155+
.thenCancel()
156+
.verify(Duration.ofSeconds(10));
157+
}
158+
}

backend/application/syson-application/src/test/java/org/eclipse/syson/services/diagrams/DiagramComparator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2024 Obeo.
2+
* Copyright (c) 2024, 2025 Obeo.
33
* This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v2.0
55
* which accompanies this distribution, and is available at
@@ -17,7 +17,7 @@
1717
import org.eclipse.sirius.components.diagrams.Diagram;
1818
import org.eclipse.sirius.components.diagrams.Edge;
1919
import org.eclipse.sirius.components.diagrams.Node;
20-
import org.eclipse.syson.diagram.common.view.services.NodeFinder;
20+
import org.eclipse.syson.util.NodeFinder;
2121
import org.springframework.stereotype.Service;
2222

2323
/**

0 commit comments

Comments
 (0)