Skip to content

Commit 3764f49

Browse files
adaussyAxelRICHARD
authored andcommitted
[1255] Improve label of TransitionUsage to handle "AcceptParameterPart"
Bug: #1255 Signed-off-by: Arthur Daussy <[email protected]>
1 parent 1430078 commit 3764f49

File tree

12 files changed

+381
-99
lines changed

12 files changed

+381
-99
lines changed

CHANGELOG.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
When end-users click on _New Object_ on a semantic element, and select a `ViewUsage`, then a `ViewUsage` typed by default with the _General View_ `ViewDefinition` from the standard library will be created.
2525
- https://github.com/eclipse-syson/syson/issues/1252[#1252] [exort] Implement textual export of `TriggerInvocationExpression`.
2626
- https://github.com/eclipse-syson/syson/issues/1233[#1233] [general-view] Add a creation tool of State sub actions with referenced action inside State elements
27+
- https://github.com/eclipse-syson/syson/issues/1255[#1255] [general-view] Improve label of `TransitionUsage` to display the "AcceptParameterPart".
2728

2829
=== New features
2930

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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.junit.jupiter.api.Assertions.fail;
17+
18+
import java.time.Duration;
19+
import java.util.Optional;
20+
import java.util.UUID;
21+
import java.util.function.Consumer;
22+
23+
import org.eclipse.sirius.components.collaborative.diagrams.dto.DiagramEventInput;
24+
import org.eclipse.sirius.components.collaborative.diagrams.dto.DiagramRefreshedEventPayload;
25+
import org.eclipse.sirius.components.diagrams.Edge;
26+
import org.eclipse.sirius.web.tests.services.api.IGivenInitialServerState;
27+
import org.eclipse.syson.AbstractIntegrationTests;
28+
import org.eclipse.syson.application.data.GeneralViewStateTransitionUsageProjectData;
29+
import org.eclipse.syson.services.diagrams.api.IGivenDiagramSubscription;
30+
import org.junit.jupiter.api.DisplayName;
31+
import org.junit.jupiter.api.Test;
32+
import org.springframework.beans.factory.annotation.Autowired;
33+
import org.springframework.boot.test.context.SpringBootTest;
34+
import org.springframework.test.context.jdbc.Sql;
35+
import org.springframework.test.context.jdbc.SqlConfig;
36+
import org.springframework.transaction.annotation.Transactional;
37+
38+
import reactor.test.StepVerifier;
39+
40+
/**
41+
* Tests related to TransitionUsage between states in the General View Diagram.
42+
*
43+
* @author Arthur Daussy
44+
*/
45+
@Transactional
46+
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
47+
public class GVStateTransitionUsageTests extends AbstractIntegrationTests {
48+
49+
@Autowired
50+
private IGivenInitialServerState givenInitialServerState;
51+
52+
@Autowired
53+
private IGivenDiagramSubscription givenDiagramSubscription;
54+
55+
@Sql(scripts = { GeneralViewStateTransitionUsageProjectData.SCRIPT_PATH }, executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
56+
@Sql(scripts = { "/scripts/cleanup.sql" }, executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD, config = @SqlConfig(transactionMode = SqlConfig.TransactionMode.ISOLATED))
57+
@Test
58+
@DisplayName("Given a General View with multiplicity range, when the diagram is render, then the edge center label as an empty text")
59+
public void checkMultiplicityLabel() {
60+
this.givenInitialServerState.initialize();
61+
var diagramEventInput = new DiagramEventInput(UUID.randomUUID(),
62+
GeneralViewStateTransitionUsageProjectData.EDITING_CONTEXT_ID,
63+
GeneralViewStateTransitionUsageProjectData.GraphicalIds.DIAGRAM_ID);
64+
var flux = this.givenDiagramSubscription.subscribe(diagramEventInput);
65+
66+
Consumer<DiagramRefreshedEventPayload> initialDiagramContentConsumer = payload -> Optional.of(payload)
67+
.map(DiagramRefreshedEventPayload::diagram)
68+
.ifPresentOrElse(diagram -> {
69+
assertThat(diagram.getEdges()).hasSize(3);
70+
Edge offOnEdge = diagram.getEdges().stream()
71+
.filter(e -> GeneralViewStateTransitionUsageProjectData.GraphicalIds.OFF_ON_ID.equals(e.getId()))
72+
.findFirst()
73+
.get();
74+
assertThat(offOnEdge.getCenterLabel().getText()).isEqualTo("TurnOn via commPort");
75+
assertThat(offOnEdge.getSourceId()).isEqualTo(GeneralViewStateTransitionUsageProjectData.GraphicalIds.OFF_ID);
76+
assertThat(offOnEdge.getTargetId()).isEqualTo(GeneralViewStateTransitionUsageProjectData.GraphicalIds.ON_ID);
77+
Edge onOffEdge = diagram.getEdges().stream()
78+
.filter(e -> GeneralViewStateTransitionUsageProjectData.GraphicalIds.ON_OFF_ID.equals(e.getId()))
79+
.findFirst()
80+
.get();
81+
assertThat(onOffEdge.getCenterLabel().getText()).isEqualTo("after 5 [minute]");
82+
assertThat(onOffEdge.getSourceId()).isEqualTo(GeneralViewStateTransitionUsageProjectData.GraphicalIds.ON_ID);
83+
assertThat(onOffEdge.getTargetId()).isEqualTo(GeneralViewStateTransitionUsageProjectData.GraphicalIds.OFF_ID);
84+
Edge onIdleEdge = diagram.getEdges().stream()
85+
.filter(e -> GeneralViewStateTransitionUsageProjectData.GraphicalIds.ON_IDLE_ID.equals(e.getId()))
86+
.findFirst()
87+
.get();
88+
assertThat(onIdleEdge.getCenterLabel().getText()).isEqualTo("[x > 0]");
89+
assertThat(onIdleEdge.getSourceId()).isEqualTo(GeneralViewStateTransitionUsageProjectData.GraphicalIds.ON_ID);
90+
assertThat(onIdleEdge.getTargetId()).isEqualTo(GeneralViewStateTransitionUsageProjectData.GraphicalIds.IDLE_ID);
91+
}, () -> fail("Missing diagram"));
92+
93+
StepVerifier.create(flux)
94+
.consumeNextWith(initialDiagramContentConsumer)
95+
.thenCancel()
96+
.verify(Duration.ofSeconds(10));
97+
}
98+
99+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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.data;
14+
15+
/**
16+
* Project data for the "GeneralView-AddExistingElements" project.
17+
*
18+
* @author Arthur Daussy
19+
*/
20+
public class GeneralViewStateTransitionUsageProjectData {
21+
22+
public static final String SCRIPT_PATH = "/scripts/database-content/GeneralView-StateTransitionUsages.sql";
23+
24+
public static final String EDITING_CONTEXT_ID = "e7077fc5-9cab-4220-b9fe-3556184ef44b";
25+
26+
/**
27+
* Ids of graphical elements.
28+
*/
29+
public static class GraphicalIds {
30+
31+
public static final String DIAGRAM_ID = "0b0f1d24-863d-4b59-a3dd-6f4d96e01268";
32+
33+
public static final String OFF_ON_ID = "5b175ad8-4942-3589-9e3c-ba7f0bd3f6b7";
34+
35+
public static final String ON_OFF_ID = "b3c6c8dc-3638-3504-a929-ce396b9c63a9";
36+
37+
public static final String ON_IDLE_ID = "d08e916a-ca8d-3da6-b904-e1f7eb6168b3";
38+
39+
public static final String OFF_ID = "9a9e9d06-c888-3b40-b8da-56c89381c4ae";
40+
41+
public static final String IDLE_ID = "d08f526d-0d47-37b8-ab61-697b1b0d9d86";
42+
43+
public static final String ON_ID = "cdde895f-94e1-3db5-8371-abaaad85ba62";
44+
}
45+
46+
/**
47+
* Ids for the semantic elements.
48+
*/
49+
public static final class SemanticIds {
50+
public static final String PACKAGE_1_ID = "d0cd12a0-7589-4e89-8bf9-36ccbf611afb";
51+
52+
public static final String TURN_ON_ID = "7f679f47-f682-4757-b525-96c0eac9cc5b";
53+
54+
public static final String ON_OFF2_ID = "b4d007e6-696f-4901-a2f2-aa6d55c20c5d";
55+
56+
public static final String COMMPORT_ID = "ecb5ca50-ae4e-45f8-bc65-6cb5a390ca77";
57+
58+
public static final String X_ID = "2ced40c8-37a5-410d-bf02-a5db9830bf3a";
59+
60+
public static final String OFF_ID = "e23f6158-09df-4ee3-8d73-4343a6afbc9b";
61+
62+
public static final String ON_ID = "64c48e36-273a-4a81-806c-8ff1d4cafdf3";
63+
64+
public static final String IDLE_ID = "f0c47f61-5488-4850-8c96-8048280971eb";
65+
66+
public static final String OFF_ON_ID = "133cdb61-9a0c-4f58-bed4-bc329692d88e";
67+
68+
public static final String ON_OFF_ID = "3f88365d-ba28-445e-9df6-733c2e4c6e43";
69+
70+
public static final String ON_IDLE_ID = "a5b763a9-987c-4da5-a109-dd12305c119b";
71+
}
72+
73+
}

backend/application/syson-application/src/test/resources/scripts/database-content/GeneralView-StateTransitionUsages.sql

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

backend/metamodel/syson-sysml-metamodel/src/main/java/org/eclipse/syson/sysml/textual/SysMLElementSerializer.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,6 +1016,21 @@ public String caseViewpointDefinition(ViewpointDefinition vp) {
10161016

10171017
return builder.toString();
10181018
}
1019+
1020+
1021+
/**
1022+
* Get a String representation of the "AcceptParameterPart" BNF rule to be used on {@link AcceptActionUsage}.
1023+
*
1024+
* @param acceptActionUsage
1025+
* a non null {@link AcceptActionUsage}
1026+
* @return a String representation of the "AcceptParameterPart"
1027+
*/
1028+
public String getAcceptParameterPart(AcceptActionUsage acceptActionUsage) {
1029+
Appender builder = this.newAppender();
1030+
this.appendAcceptParameterPart(builder, acceptActionUsage);
1031+
return builder.toString();
1032+
}
1033+
10191034

10201035
private Appender newAppender() {
10211036
return new Appender(this.lineSeparator, this.indentation);

backend/views/syson-diagram-actionflow-view/src/test/java/org/eclipse/syson/diagram/actionflow/view/ActionFlowViewDiagramDescriptionTests.java

Lines changed: 3 additions & 1 deletion
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
@@ -88,6 +88,8 @@ public void eachEdgeWithCenterLabelHasDirectEditTool() {
8888
// SuccessionAsUsage has a label but the grammar does not support the direct edit tool yet
8989
.filter(this.diagramPredicates.hasDomainType(SysmlPackage.eINSTANCE.getSuccessionAsUsage()).negate())
9090
.filter(this.diagramPredicates.hasDomainType(SysmlPackage.eINSTANCE.getAllocationUsage()).negate())
91+
// TransitionUsage has a label but the grammar does not support the direct edit tool yet
92+
.filter(this.diagramPredicates.hasDomainType(SysmlPackage.eINSTANCE.getTransitionUsage()).negate())
9193
.toList();
9294
new EdgeDescriptionHasDirectEditToolChecker().checkAll(edgeDescriptionCandidates);
9395
}

backend/views/syson-diagram-common-view/src/main/java/org/eclipse/syson/diagram/common/view/edges/AbstractTransitionEdgeDescriptionProvider.java

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import java.util.Objects;
1818

1919
import org.eclipse.emf.ecore.EClass;
20-
import org.eclipse.emf.ecore.EOperation;
2120
import org.eclipse.sirius.components.view.builder.IViewDiagramElementFinder;
2221
import org.eclipse.sirius.components.view.builder.generated.diagram.DiagramBuilders;
2322
import org.eclipse.sirius.components.view.builder.generated.view.ChangeContextBuilder;
@@ -29,7 +28,6 @@
2928
import org.eclipse.sirius.components.view.diagram.EdgeDescription;
3029
import org.eclipse.sirius.components.view.diagram.EdgeStyle;
3130
import org.eclipse.sirius.components.view.diagram.IconLabelNodeStyleDescription;
32-
import org.eclipse.sirius.components.view.diagram.LabelEditTool;
3331
import org.eclipse.sirius.components.view.diagram.LineStyle;
3432
import org.eclipse.sirius.components.view.diagram.NodeDescription;
3533
import org.eclipse.sirius.components.view.diagram.NodeTool;
@@ -111,27 +109,6 @@ protected String getTargetReconnectToolPreconditionExpression() {
111109
return this.getSourceReconnectToolPreconditionExpression();
112110
}
113111

114-
/**
115-
* Label edit tool setting the attributes of an {@linkplain EOperation} based on the provided input. Will allow to
116-
* set the {@linkplain EOperation} dataType, parameters, and cardinality values. <br/>
117-
* Relies on {@code org.eclipse.emf.ecoretools.design.service.DesignServices.performEdit(EAttribute, String)} or
118-
* {@code org.eclipse.emf.ecoretools.design.service.DesignServices.performEdit(EOperation, String)}.
119-
*
120-
* @return The LabelEditTool for the TransitionEdge
121-
*/
122-
@Override
123-
protected LabelEditTool getEdgeEditTool() {
124-
var changeContext = this.getViewBuilderHelper().newChangeContext()
125-
.expression(AQLUtils.getSelfServiceCallExpression("directEditTransitionEdgeLabel", "newLabel"))
126-
.build();
127-
128-
return this.getDiagramBuilderHelper().newLabelEditTool()
129-
.name("Edit TransitionUsage Label")
130-
.initialDirectEditLabelExpression(AQLUtils.getSelfServiceCallExpression("getTransitionLabel", "false"))
131-
.body(changeContext)
132-
.build();
133-
}
134-
135112
/**
136113
* Implementers should provide the list of {@link NodeTool} (without ToolSection) for this {@link EdgeDescription}.
137114
*

0 commit comments

Comments
 (0)