Skip to content

Commit c80f960

Browse files
committed
[2059] Fix Add existing elements tool
Bug: #2059 Signed-off-by: Axel RICHARD <axel.richard@obeo.fr>
1 parent 2e05393 commit c80f960

6 files changed

Lines changed: 227 additions & 6 deletions

File tree

CHANGELOG.adoc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,9 @@ Now the _end_ keyword is not displayed anymore in the label of these graphical n
9898
- https://github.com/eclipse-syson/syson/issues/2054[#2054] [diagrams] Fix an error when invoking the tools _New Start Action_ or _New Done Action_ from inside a package named `Actions`.
9999
- https://github.com/eclipse-syson/syson/issues/2057[#2057] [diagrams] Fix the support for removing the multiplicity using the direct edit.
100100
- https://github.com/eclipse-syson/syson/issues/1938[#1938] [diagrams] Fix an issue where the _New Flow (flow)_ tool between two parameters was broken.
101-
- https://github.com/eclipse-syson/syson/issues/2058[#2058] [diagrams] Fix error when importing SysML snippets referencing unknown units which could make the resluting model inconsistent
102-
- https://github.com/eclipse-syson/syson/issues/2053[#2053] [diagrams] Prevent incoming and outgoing graphical edges of a graphical `ForkNode` or `JoindNode` to point empty space.
101+
- https://github.com/eclipse-syson/syson/issues/2058[#2058] [diagrams] Fix error when importing SysML snippets referencing unknown units which could make the resulting model inconsistent
102+
- https://github.com/eclipse-syson/syson/issues/2053[#2053] [diagrams] Prevent incoming and outgoing graphical edges of a graphical `ForkNode` or `JoinNode` to point empty space.
103+
- https://github.com/eclipse-syson/syson/issues/2059[#2059] [diagrams] Fix an issue where the _Add existing elements_ tool was not working correctly on the _action flow_ compartment of `ActionUsage` graphical nodes.
103104

104105
=== Improvements
105106

backend/application/syson-application/src/test/java/org/eclipse/syson/application/controllers/diagrams/general/view/GVAddExistingElementsTests.java

Lines changed: 63 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import java.text.MessageFormat;
1919
import java.time.Duration;
20+
import java.util.List;
2021
import java.util.Objects;
2122
import java.util.Optional;
2223
import java.util.UUID;
@@ -28,17 +29,24 @@
2829
import org.eclipse.sirius.components.diagrams.Diagram;
2930
import org.eclipse.sirius.components.diagrams.Node;
3031
import org.eclipse.sirius.components.diagrams.ViewModifier;
32+
import org.eclipse.sirius.components.diagrams.tests.navigation.DiagramNavigator;
3133
import org.eclipse.sirius.components.view.emf.diagram.IDiagramIdProvider;
3234
import org.eclipse.sirius.web.tests.services.api.IGivenInitialServerState;
3335
import org.eclipse.syson.AbstractIntegrationTests;
3436
import org.eclipse.syson.GivenSysONServer;
3537
import org.eclipse.syson.application.controllers.diagrams.testers.ToolTester;
38+
import org.eclipse.syson.application.data.GeneralViewAddExistingElementsActionFlowCompartmentTestProjectData;
3639
import org.eclipse.syson.application.data.GeneralViewAddExistingElementsTestProjectData;
3740
import org.eclipse.syson.services.diagrams.DiagramDescriptionIdProvider;
3841
import org.eclipse.syson.services.diagrams.api.IGivenDiagramDescription;
3942
import org.eclipse.syson.services.diagrams.api.IGivenDiagramSubscription;
43+
import org.eclipse.syson.standard.diagrams.view.SDVDescriptionNameGenerator;
44+
import org.eclipse.syson.sysml.SysmlPackage;
45+
import org.eclipse.syson.sysml.helper.LabelConstants;
46+
import org.eclipse.syson.util.IDescriptionNameGenerator;
4047
import org.eclipse.syson.util.SysONRepresentationDescriptionIdentifiers;
4148
import org.junit.jupiter.api.BeforeEach;
49+
import org.junit.jupiter.api.DisplayName;
4250
import org.junit.jupiter.api.Test;
4351
import org.springframework.beans.factory.annotation.Autowired;
4452
import org.springframework.boot.test.context.SpringBootTest;
@@ -87,6 +95,8 @@ public class GVAddExistingElementsTests extends AbstractIntegrationTests {
8795
@Autowired
8896
private ToolTester nodeCreationTester;
8997

98+
private final IDescriptionNameGenerator descriptionNameGenerator = new SDVDescriptionNameGenerator();
99+
90100
private Flux<DiagramRefreshedEventPayload> givenSubscriptionToDiagram() {
91101
var diagramEventInput = new DiagramEventInput(UUID.randomUUID(),
92102
GeneralViewAddExistingElementsTestProjectData.EDITING_CONTEXT_ID,
@@ -153,10 +163,10 @@ public void addExistingElementsRecursiveOnDiagram() {
153163

154164
Consumer<Object> initialDiagramContentConsumer = assertRefreshedDiagramThat(diagram::set);
155165

156-
String creationToolId = diagramDescriptionIdProvider.getDiagramCreationToolId("Add existing elements (recursive)");
157-
assertThat(creationToolId).as("The tool 'Add existing elements (recursive)' should exist on the diagram").isNotNull();
166+
String addExistingElementToolId = diagramDescriptionIdProvider.getDiagramCreationToolId("Add existing elements (recursive)");
167+
assertThat(addExistingElementToolId).as("The tool 'Add existing elements (recursive)' should exist on the diagram").isNotNull();
158168

159-
Runnable nodeCreationRunner = () -> this.nodeCreationTester.invokeTool(GeneralViewAddExistingElementsTestProjectData.EDITING_CONTEXT_ID, diagram, creationToolId);
169+
Runnable addExistingElementTool = () -> this.nodeCreationTester.invokeTool(GeneralViewAddExistingElementsTestProjectData.EDITING_CONTEXT_ID, diagram, addExistingElementToolId);
160170

161171
Consumer<Object> updatedDiagramConsumer = assertRefreshedDiagramThat(newDiagram -> {
162172
assertThat(newDiagram.getNodes()).as("6 nodes should be visible on the diagram").hasSize(7);
@@ -196,7 +206,56 @@ public void addExistingElementsRecursiveOnDiagram() {
196206

197207
StepVerifier.create(flux)
198208
.consumeNextWith(initialDiagramContentConsumer)
199-
.then(nodeCreationRunner)
209+
.then(addExistingElementTool)
210+
.consumeNextWith(updatedDiagramConsumer)
211+
.thenCancel()
212+
.verify(Duration.ofSeconds(10));
213+
}
214+
215+
@DisplayName("GIVEN an ActionUsage with its action flow compartment displayed and a nested ActionUsage in it, WHEN Delete from diagram the nested ActionUsage then use the Add existing element tool on the action flow compartment, THEN the nested ActionUsage should only be displayed in the action flow compartment")
216+
@GivenSysONServer({ GeneralViewAddExistingElementsActionFlowCompartmentTestProjectData.SCRIPT_PATH })
217+
@Test
218+
public void addExistingElementsOnActionFlowCompartment() {
219+
var flux = this.givenSubscriptionToDiagram();
220+
221+
var diagramDescription = this.givenDiagramDescription.getDiagramDescription(GeneralViewAddExistingElementsActionFlowCompartmentTestProjectData.EDITING_CONTEXT_ID,
222+
SysONRepresentationDescriptionIdentifiers.GENERAL_VIEW_DIAGRAM_DESCRIPTION_ID);
223+
var diagramDescriptionIdProvider = new DiagramDescriptionIdProvider(diagramDescription, this.diagramIdProvider);
224+
225+
AtomicReference<Diagram> diagram = new AtomicReference<>();
226+
227+
Consumer<Object> initialDiagramContentConsumer = assertRefreshedDiagramThat(initialDiagram -> {
228+
diagram.set(initialDiagram);
229+
230+
assertThat(initialDiagram.getNodes()).hasSize(1);
231+
232+
var action1ActionFlowCompartmentNode = new DiagramNavigator(initialDiagram).nodeWithLabel(LabelConstants.OPEN_QUOTE + "action" + LabelConstants.CLOSE_QUOTE + LabelConstants.CR + "action1")
233+
.childNodeWithLabel("action flow").getNode();
234+
assertThat(action1ActionFlowCompartmentNode.getChildNodes()).isEmpty();
235+
});
236+
237+
String addExistingElementToolId = diagramDescriptionIdProvider.getNodeToolId(
238+
this.descriptionNameGenerator.getFreeFormCompartmentName(SysmlPackage.eINSTANCE.getActionUsage(), SysmlPackage.eINSTANCE.getUsage_NestedAction()), "Add existing elements");
239+
240+
Runnable addExistingElementTool = () -> this.nodeCreationTester.invokeTool(GeneralViewAddExistingElementsActionFlowCompartmentTestProjectData.EDITING_CONTEXT_ID, diagram.get().getId(),
241+
GeneralViewAddExistingElementsActionFlowCompartmentTestProjectData.GraphicalIds.ACTION_1_ACTIONFLOW_COMPARTMENT_NODE_ID, addExistingElementToolId, List.of());
242+
243+
Consumer<Object> updatedDiagramConsumer = assertRefreshedDiagramThat(newDiagram -> {
244+
assertThat(newDiagram.getNodes()).hasSize(2);
245+
246+
var action1ActionFlowCompartmentNode = new DiagramNavigator(newDiagram).nodeWithLabel(LabelConstants.OPEN_QUOTE + "action" + LabelConstants.CLOSE_QUOTE + LabelConstants.CR + "action1")
247+
.childNodeWithLabel("action flow").getNode();
248+
var childNodes = action1ActionFlowCompartmentNode.getChildNodes();
249+
assertThat(childNodes).hasSize(1);
250+
assertThat(childNodes.get(0).getTargetObjectId()).isEqualTo(GeneralViewAddExistingElementsActionFlowCompartmentTestProjectData.SemanticIds.ACTION_2_ID);
251+
252+
var action2HiddenNode = new DiagramNavigator(newDiagram).nodeWithLabel(LabelConstants.OPEN_QUOTE + "action" + LabelConstants.CLOSE_QUOTE + LabelConstants.CR + "action2").getNode();
253+
assertThat(action2HiddenNode.getModifiers()).contains(ViewModifier.Hidden);
254+
});
255+
256+
StepVerifier.create(flux)
257+
.consumeNextWith(initialDiagramContentConsumer)
258+
.then(addExistingElementTool)
200259
.consumeNextWith(updatedDiagramConsumer)
201260
.thenCancel()
202261
.verify(Duration.ofSeconds(10));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2026 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.data;
14+
15+
/**
16+
* Project data for the "GeneralView-AddExistingElements-ActionFlow-Compartment" project.
17+
*
18+
* @author arichard
19+
*/
20+
public class GeneralViewAddExistingElementsActionFlowCompartmentTestProjectData {
21+
22+
public static final String SCRIPT_PATH = "/scripts/database-content/GeneralView-AddExistingElements-ActionFlow-Compartment.sql";
23+
24+
public static final String EDITING_CONTEXT_ID = "cbb4b3b4-af8e-4a05-a419-19dbfd1cc94d";
25+
26+
/**
27+
* Ids of graphical elements.
28+
*/
29+
public static class GraphicalIds {
30+
31+
public static final String DIAGRAM_ID = "a0ca6720-66e0-40b7-a761-807474c0d773";
32+
33+
public static final String ACTION_1_NODE_ID = "62fff9fd-9f02-39e3-8446-1d638b9b053c";
34+
35+
public static final String ACTION_1_ACTIONFLOW_COMPARTMENT_NODE_ID = "f394cff3-b994-3b34-97c7-7d1a6807093e";
36+
}
37+
38+
/**
39+
* Ids for the semantic elements.
40+
*/
41+
public static final class SemanticIds {
42+
43+
public static final String PACKAGE_1_ID = "8d4123ac-3ac5-412d-90f2-49282b923003";
44+
45+
public static final String GENERAL_VIEW_VIEW_USAGE_ID = "b67872fa-5900-48d3-88f0-e6ced193c8ec";
46+
47+
public static final String ACTION_1_ID = "40d86f92-e400-413d-8ec6-09fcf179b396";
48+
49+
public static final String ACTION_2_ID = "f0a37795-69e1-4ffe-becc-e55c20c70ac3";
50+
}
51+
52+
}

backend/application/syson-application/src/test/resources/scripts/database-content/GeneralView-AddExistingElements-ActionFlow-Compartment.sql

Lines changed: 100 additions & 0 deletions
Large diffs are not rendered by default.

backend/services/syson-diagram-services/src/main/java/org/eclipse/syson/diagram/services/DiagramMutationExposeService.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,14 @@ public Element addToExposedElements(Element element, boolean recursive, IEditing
191191
if (recursive) {
192192
membershipExpose.setIsRecursive(true);
193193
}
194+
// if it is the General View, ActionFlow View or StateTrabnsition View, we want to hide tree
195+
// elements if a compartment containing the same
196+
// element is displayed or it is displayed as border node
197+
if (selectedNode != null && !ViewDefinitionKind.isInterconnectionView(this.utilService.getViewDefinitionKind(childElement, List.of(), editingContext))) {
198+
this.hideNodeIfVisibleCompartmentCouldHostTheFutureNode(childElement, editingContext, diagramContext, selectedNode, convertedNodes);
199+
this.hideNodeIfBorderNodeCouldHostTheFutureNode(childElement, editingContext, diagramContext, selectedNode, convertedNodes);
200+
this.hideNodeIfNestedIsDefault(childElement, editingContext, diagramContext, selectedNode, convertedNodes);
201+
}
194202
}
195203
}
196204
}

doc/content/modules/user-manual/pages/release-notes/2026.3.0.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Now the _end_ keyword is not displayed anymore in the label of these graphical n
3838
** Fix an issue where the _New Flow (flow)_ tool between two parameters was broken.
3939
** The `ForkNode` and `JoinNode` graphical nodes style have been updated and are restricted to horizontal resizing.
4040
+ Consequently, their entire footprint is filled with black, ensuring that all incoming and outgoing edges maintain a valid connection point.
41+
** Fix an issue where the _Add existing elements_ tool was not working correctly on the _action flow_ compartment of `ActionUsage` graphical nodes.
4142

4243
* In textual import/export:
4344

0 commit comments

Comments
 (0)