Skip to content

Commit 373b081

Browse files
committed
[2129] Improve actor creation tool using the latest selection dialog changes
Bug: #2129 Signed-off-by: Guillaume Coutable <guillaume.coutable@obeo.fr>
1 parent a3dfac3 commit 373b081

6 files changed

Lines changed: 103 additions & 30 deletions

File tree

CHANGELOG.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ As a result, the following GraphQL mutations have been removed `exposeRequiremen
3535

3636
=== Improvements
3737

38+
- https://github.com/eclipse-syson/syson/issues/2129[#2129] [diagrams] Leverage the latest change of the selection dialog to allow creating a `FlowUsage` from a `ConnectionUsage` without selection a `PayloadFeature`
3839

3940
=== New features
4041

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

Lines changed: 80 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@
3030
import org.eclipse.sirius.components.collaborative.diagrams.dto.DiagramRefreshedEventPayload;
3131
import org.eclipse.sirius.components.collaborative.diagrams.dto.EditLabelInput;
3232
import org.eclipse.sirius.components.collaborative.diagrams.dto.EditLabelSuccessPayload;
33-
import org.eclipse.sirius.components.collaborative.diagrams.dto.InvokeSingleClickOnDiagramElementToolInput;
34-
import org.eclipse.sirius.components.collaborative.diagrams.dto.InvokeSingleClickOnDiagramElementToolSuccessPayload;
3533
import org.eclipse.sirius.components.collaborative.diagrams.dto.ToolVariable;
3634
import org.eclipse.sirius.components.collaborative.diagrams.dto.ToolVariableType;
3735
import org.eclipse.sirius.components.core.api.IEditingContext;
@@ -43,7 +41,6 @@
4341
import org.eclipse.sirius.components.diagrams.events.ReconnectEdgeKind;
4442
import org.eclipse.sirius.components.diagrams.tests.assertions.DiagramAssertions;
4543
import org.eclipse.sirius.components.diagrams.tests.graphql.EditLabelMutationRunner;
46-
import org.eclipse.sirius.components.diagrams.tests.graphql.InvokeSingleClickOnDiagramElementToolMutationRunner;
4744
import org.eclipse.sirius.components.diagrams.tests.graphql.PaletteQueryRunner;
4845
import org.eclipse.sirius.components.diagrams.tests.navigation.DiagramNavigator;
4946
import org.eclipse.sirius.components.graphql.tests.ExecuteEditingContextFunctionSuccessPayload;
@@ -112,9 +109,6 @@ public class GVFlowUsageTests extends AbstractIntegrationTests {
112109
@Autowired
113110
private EditLabelMutationRunner editLabelMutationRunner;
114111

115-
@Autowired
116-
private InvokeSingleClickOnDiagramElementToolMutationRunner invokeSingleClickOnDiagramElementToolMutationRunner;
117-
118112
@Autowired
119113
private PaletteQueryRunner paletteQueryRunner;
120114

@@ -437,14 +431,7 @@ public void createFlowUsageInConnection() {
437431

438432
Runnable createFlowUsageOnConnection = () -> {
439433
var selectedObjectVariable = new ToolVariable("selectedObject", GeneralViewFlowUsageProjectData.SemanticIds.VIDEO_SIGNAL_ID, ToolVariableType.OBJECT_ID);
440-
var input = new InvokeSingleClickOnDiagramElementToolInput(UUID.randomUUID(), GeneralViewFlowUsageProjectData.EDITING_CONTEXT_ID, diagramId.get(), List.of(connectionEdgeId.get()),
441-
flowCreationToolId, 0, 0,
442-
List.of(selectedObjectVariable));
443-
var result = this.invokeSingleClickOnDiagramElementToolMutationRunner.run(input);
444-
String typename = JsonPath.read(result.data(), "$.data.invokeSingleClickOnDiagramElementTool.__typename");
445-
assertThat(typename).isEqualTo(InvokeSingleClickOnDiagramElementToolSuccessPayload.class.getSimpleName());
446-
List<String> messages = JsonPath.read(result.data(), "$.data.invokeSingleClickOnDiagramElementTool.messages[*].body");
447-
assertThat(messages).hasSize(0);
434+
this.toolTester.invokeTool(GeneralViewFlowUsageProjectData.EDITING_CONTEXT_ID, diagramId.get(), connectionEdgeId.get(), flowCreationToolId, List.of(selectedObjectVariable));
448435
};
449436

450437
Consumer<Object> validateEffectOnLabel = assertRefreshedDiagramThat(diagram -> this.assertEdgeLabelText(connectionEdgeId.get(), diagram, "cable : HDMICable \u25b6 Flow"));
@@ -489,6 +476,85 @@ public void createFlowUsageInConnection() {
489476
.verify(Duration.ofSeconds(10));
490477
}
491478

479+
@Test
480+
@DisplayName("GIVEN a connection WHEN we create a flow usage in it without selecting a payload THEN the flow is correctly setup without a payload feature")
481+
@GivenSysONServer({ GeneralViewFlowUsageProjectData.SCRIPT_PATH })
482+
public void createFlowUsageInConnectionWithoutPayloadFeature() {
483+
var diagramEventInput = new DiagramEventInput(UUID.randomUUID(),
484+
GeneralViewFlowUsageProjectData.EDITING_CONTEXT_ID,
485+
GeneralViewFlowUsageProjectData.GraphicalIds.DIAGRAM_ID);
486+
487+
var flux = this.givenDiagramSubscription.subscribe(diagramEventInput);
488+
489+
var diagramId = new AtomicReference<String>();
490+
var connectionEdgeId = new AtomicReference<String>();
491+
var connectionEdgeLabelId = new AtomicReference<String>();
492+
493+
var diagramDescription = this.givenDiagramDescription.getDiagramDescription(GeneralViewFlowUsageProjectData.EDITING_CONTEXT_ID,
494+
SysONRepresentationDescriptionIdentifiers.GENERAL_VIEW_DIAGRAM_DESCRIPTION_ID);
495+
var diagramDescriptionIdProvider = new DiagramDescriptionIdProvider(diagramDescription, this.diagramIdProvider);
496+
String flowCreationToolId = diagramDescriptionIdProvider.getNodeCreationToolIdOnEdge(this.descriptionNameGenerator.getEdgeName(SysmlPackage.eINSTANCE.getConnectionUsage()), "New Flow");
497+
498+
Consumer<Object> initialDiagramContentConsumer = assertRefreshedDiagramThat(diagram -> {
499+
diagramId.set(diagram.getId());
500+
var connectionEdge = new DiagramNavigator(diagram).edgeWithId(GeneralViewFlowUsageProjectData.GraphicalIds.CONNECTION_EDGE_ID).getEdge();
501+
connectionEdgeId.set(connectionEdge.getId());
502+
connectionEdgeLabelId.set(connectionEdge.getCenterLabel().id());
503+
});
504+
505+
Runnable renameAndTypeTheConnection = () -> this.editLabel(diagramId.get(), connectionEdgeLabelId.get(), "cable : HDMICable");
506+
507+
Consumer<Object> validateLabelEditResult = assertRefreshedDiagramThat(diagram -> this.assertEdgeLabelText(connectionEdgeId.get(), diagram, "cable : HDMICable"));
508+
509+
Runnable validateSemanticEffectOfLabelEdit = this.semanticRunnableFactory.createRunnable(GeneralViewFlowUsageProjectData.EDITING_CONTEXT_ID,
510+
(editingContext, executeEditingContextFunctionInput) -> {
511+
this.assertConnectionType(editingContext, GeneralViewFlowUsageProjectData.SemanticIds.CONNECT_ID, GeneralViewFlowUsageProjectData.SemanticIds.HDMI_CABLE_ID);
512+
return new ExecuteEditingContextFunctionSuccessPayload(executeEditingContextFunctionInput.id(), true);
513+
});
514+
515+
Runnable createFlowUsageOnConnection = () -> {
516+
var selectedObjectVariable = new ToolVariable("selectedObject", "", ToolVariableType.OBJECT_ID);
517+
this.toolTester.invokeTool(GeneralViewFlowUsageProjectData.EDITING_CONTEXT_ID, diagramId.get(), connectionEdgeId.get(), flowCreationToolId, List.of(selectedObjectVariable));
518+
};
519+
520+
Consumer<Object> validateEffectOnLabel = assertRefreshedDiagramThat(diagram -> this.assertEdgeLabelText(connectionEdgeId.get(), diagram, "cable : HDMICable \u25b6 Flow"));
521+
522+
Runnable validateSemanticEffectOfFlowCreation = this.semanticRunnableFactory.createRunnable(GeneralViewFlowUsageProjectData.EDITING_CONTEXT_ID,
523+
(editingContext, executeEditingContextFunctionInput) -> {
524+
var optionalConnection = this.objectSearchService.getObject(editingContext, GeneralViewFlowUsageProjectData.SemanticIds.CONNECT_ID);
525+
assertThat(optionalConnection).containsInstanceOf(ConnectionUsage.class);
526+
ConnectionUsage connection = (ConnectionUsage) optionalConnection.get();
527+
// The flow usage has been created
528+
var optionalFlowUsage = connection.getOwnedFeature().stream().filter(FlowUsage.class::isInstance).map(FlowUsage.class::cast).findFirst();
529+
assertThat(optionalFlowUsage).isPresent();
530+
var flowUsage = optionalFlowUsage.get();
531+
532+
// The flow does not have a payload feature
533+
var optionalPayloadFeature = flowUsage.getOwnedFeature().stream().filter(PayloadFeature.class::isInstance).map(PayloadFeature.class::cast).findFirst();
534+
assertThat(optionalPayloadFeature).isEmpty();
535+
536+
// The flow has two FlowEnds: one redefining HDMICable::inputSide, the other HDMICable::outputSide
537+
var flowEnds = flowUsage.getOwnedFeature().stream().filter(FlowEnd.class::isInstance).map(FlowEnd.class::cast).toList();
538+
assertThat(flowEnds).hasSize(2);
539+
var sourceEnd = flowEnds.get(0);
540+
assertThat(sourceEnd.getOwnedFeature().get(0).getOwnedRedefinition().get(0).getRedefinedFeature().getQualifiedName()).isEqualTo("Package1::HDMICable::inputSide");
541+
var targetEnd = flowEnds.get(1);
542+
assertThat(targetEnd.getOwnedFeature().get(0).getOwnedRedefinition().get(0).getRedefinedFeature().getQualifiedName()).isEqualTo("Package1::HDMICable::outputSide");
543+
return new ExecuteEditingContextFunctionSuccessPayload(executeEditingContextFunctionInput.id(), true);
544+
});
545+
546+
StepVerifier.create(flux)
547+
.consumeNextWith(initialDiagramContentConsumer)
548+
.then(renameAndTypeTheConnection)
549+
.consumeNextWith(validateLabelEditResult)
550+
.then(validateSemanticEffectOfLabelEdit)
551+
.then(createFlowUsageOnConnection)
552+
.consumeNextWith(validateEffectOnLabel)
553+
.then(validateSemanticEffectOfFlowCreation)
554+
.thenCancel()
555+
.verify(Duration.ofSeconds(10));
556+
}
557+
492558
@Test
493559
@DisplayName("GIVEN an untype connection WHEN we opening its palette THEN the flow tool is not proposed")
494560
@GivenSysONServer({ GeneralViewFlowUsageProjectData.SCRIPT_PATH })

backend/application/syson-application/src/test/java/org/eclipse/syson/application/controllers/diagrams/testers/ToolTester.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public void invokeTool(String editingContextId, AtomicReference<Diagram> diagram
7777
}
7878

7979
public void invokeTool(String editingContextId, String diagramId, String diagramElementId, String toolId, List<ToolVariable> variables) {
80-
var createElementInput = new InvokeSingleClickOnDiagramElementToolInput(
80+
var input = new InvokeSingleClickOnDiagramElementToolInput(
8181
UUID.randomUUID(),
8282
editingContextId,
8383
diagramId,
@@ -86,9 +86,11 @@ public void invokeTool(String editingContextId, String diagramId, String diagram
8686
0,
8787
0,
8888
variables);
89-
var createElementResult = this.invokeSingleClickOnDiagramElementToolMutationRunner.run(createElementInput);
90-
String typename = JsonPath.read(createElementResult.data(), "$.data.invokeSingleClickOnDiagramElementTool.__typename");
89+
var result = this.invokeSingleClickOnDiagramElementToolMutationRunner.run(input);
90+
String typename = JsonPath.read(result.data(), "$.data.invokeSingleClickOnDiagramElementTool.__typename");
9191
assertThat(typename).isEqualTo(InvokeSingleClickOnDiagramElementToolSuccessPayload.class.getSimpleName());
92+
List<String> messages = JsonPath.read(result.data(), "$.data.invokeSingleClickOnDiagramElementTool.messages[*].body");
93+
assertThat(messages).hasSize(0);
9294
}
9395

9496
public void createNodeOnEdge(String editingContextId, AtomicReference<Diagram> diagram, String selectedEdgeTargetObjectLabel, String toolId) {

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

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -615,14 +615,6 @@ public Connector reconnectTarget(Connector connector, Feature newTarget, Node so
615615
* the given {@link SatisfyRequirementUsage}.
616616
* @param newSource
617617
* the new source {@link Element}.
618-
* @param sourceNode
619-
* new source node of the edge
620-
* @param targetNode
621-
* target node of the edge
622-
* @param editingContext
623-
* the editing context
624-
* @param diagram
625-
* the context diagram
626618
* @return the given {@link SatisfyRequirementUsage}.
627619
*/
628620
public SatisfyRequirementUsage reconnectSatisfyRequirementSource(SatisfyRequirementUsage sru, Element newSource) {
@@ -771,12 +763,14 @@ public FlowUsage createFlowUsage(Feature source, Feature target, Node sourceNode
771763
*/
772764
public FlowUsage createFlowUsageWithPayload(ConnectionUsage parent, Type payloadType) {
773765
var connectionTypes = parent.getType();
774-
if (connectionTypes.size() > 0 && connectionTypes.get(0).getOwnedEndFeature().size() >= 2) {
775-
var connectionType = connectionTypes.get(0);
766+
if (!connectionTypes.isEmpty() && connectionTypes.getFirst().getOwnedEndFeature().size() >= 2) {
767+
var connectionType = connectionTypes.getFirst();
776768
Feature source = connectionType.getOwnedEndFeature().get(0);
777769
Feature target = connectionType.getOwnedEndFeature().get(1);
778770
var flowUsage = this.metamodelMutationElementService.createFlowUsage(source, target, connectionType, connectionType, parent);
779-
flowUsage.getOwnedRelationship().add(this.createPayloadFeatureMembership(payloadType));
771+
if (payloadType != null) {
772+
flowUsage.getOwnedRelationship().add(this.createPayloadFeatureMembership(payloadType));
773+
}
780774
return flowUsage;
781775
} else {
782776
return null;

backend/views/syson-diagram-common-view/src/main/java/org/eclipse/syson/diagram/common/view/tools/FlowNodeToolProvider.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,17 @@ private SelectionDialogDescription getSelectionDialogDescription() {
7171
return this.diagramBuilderHelper.newSelectionDialogDescription()
7272
.selectionDialogTreeDescription(selectionDialogTree)
7373
.defaultTitleExpression("New Flow")
74-
.descriptionExpression("Select a payload for the new Flow:")
75-
.optional(false)
74+
.noSelectionTitleExpression("New Flow")
75+
.withSelectionTitleExpression("New Flow")
76+
.descriptionExpression("Create an Flow:")
77+
.noSelectionActionLabelExpression("Create a new Flow")
78+
.noSelectionActionDescriptionExpression("Create a new Flow without Payload")
79+
.withSelectionActionLabelExpression("Select a Payload for the new Flow")
80+
.withSelectionActionDescriptionExpression("Create a new Flow with a Payload")
81+
.noSelectionActionStatusMessageExpression("It will create a new Flow without Payload")
82+
.selectionRequiredWithoutSelectionStatusMessageExpression("Select one Element to be added as the new Flow Payload")
83+
.selectionRequiredWithSelectionStatusMessageExpression(AQLConstants.AQL + "'It will create an Flow with ' + selectedObjects->first().name + ' as Payload'")
84+
.optional(true)
7685
.build();
7786
}
7887

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
** Add tools to create timeslices and snapshots, available on `OccurrenceUsage`, `ItemUsage`, and `PartUsage` graphical nodes.
2626
These tools leverage a selection dialog to either create a specific timeslice/snapshot graphical node or, if no selection is made, default to a timeslice/snapshot `OccurrenceUsage` graphical node.
27+
** Improve the tool creating a `FlowUsage` from a `ConnectionUsage` by making the payload selection optional.
2728

2829
== Technical details
2930

0 commit comments

Comments
 (0)