diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 038e2bfcb7..11a56fd7ac 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -27,6 +27,8 @@ Undirected features are excluded from constraint parameter lists as well. Consumers needing only local parameters should filter `getOwnedFeature()` with `directionOf(feature) != null`. `Feature#getOwnedRedefinition()` now also returns virtual implicit positional parameter redefinitions. Consumers needing only stored redefinitions should filter `getOwnedRelationship()` for `Redefinition` instances. +- https://github.com/eclipse-syson/syson/issues/2590[#2590] [services] `TreeMutationAQLService` now requires a `TreeMutationSelectionDialogService` constructor argument instead of providing a public no-argument constructor. +Downstream code constructing this service directly must supply a `TreeMutationSelectionDialogService`, which requires an `IFeedbackMessageService` to receive feature chain redefinition errors; dependency injection must provide these services as well. === Dependency update @@ -91,6 +93,7 @@ It writes SysML v2 models as normalized text, round-trip text that preserves syn Imported reference spellings remain available while the model is loaded. After a reload, serialization uses the stored model. Downstream callers can migrate from the deprecated `SysMLElementSerializer` to `SysONTextSerializer` for SysON model elements. - https://github.com/eclipse-syson/syson/issues/2590[#2590] [diagrams] Add `Redefine a nested feature` tool in diagrams. +Confirming a selected feature path materializes the required local redefinition chain and selects its last feature, revealing it in the Model Explorer and displaying it in Details. - https://github.com/eclipse-syson/syson/issues/2654[#2654] [services] Add `redefineFeatureChain` to materialize and reuse local SysML usages along a selected path. Support positional parameter redefinitions in feature chains, including multiple inheritance and separate return positions. diff --git a/backend/application/syson-application/src/test/java/org/eclipse/syson/application/controllers/diagrams/general/view/GVRedefineNestedFeatureTests.java b/backend/application/syson-application/src/test/java/org/eclipse/syson/application/controllers/diagrams/general/view/GVRedefineNestedFeatureTests.java new file mode 100644 index 0000000000..f49bde8c7d --- /dev/null +++ b/backend/application/syson-application/src/test/java/org/eclipse/syson/application/controllers/diagrams/general/view/GVRedefineNestedFeatureTests.java @@ -0,0 +1,250 @@ +/******************************************************************************* + * Copyright (c) 2026 Obeo. + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Obeo - initial API and implementation + *******************************************************************************/ +package org.eclipse.syson.application.controllers.diagrams.general.view; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.eclipse.sirius.components.diagrams.tests.DiagramEventPayloadConsumer.assertRefreshedDiagramThat; +import static org.eclipse.sirius.components.trees.tests.TreeEventPayloadConsumer.assertRefreshedTreeThat; + +import com.jayway.jsonpath.JsonPath; + +import java.time.Duration; +import java.util.List; +import java.util.UUID; +import java.util.concurrent.atomic.AtomicReference; + +import org.eclipse.sirius.components.collaborative.diagrams.dto.DiagramEventInput; +import org.eclipse.sirius.components.collaborative.diagrams.dto.InvokeSingleClickOnDiagramElementToolInput; +import org.eclipse.sirius.components.collaborative.diagrams.dto.InvokeSingleClickOnDiagramElementToolSuccessPayload; +import org.eclipse.sirius.components.collaborative.diagrams.dto.ToolVariable; +import org.eclipse.sirius.components.collaborative.diagrams.dto.ToolVariableType; +import org.eclipse.sirius.components.collaborative.selection.dto.SelectionDialogTreeEventInput; +import org.eclipse.sirius.components.core.api.IIdentityService; +import org.eclipse.sirius.components.core.api.IObjectSearchService; +import org.eclipse.sirius.components.diagrams.Diagram; +import org.eclipse.sirius.components.diagrams.tests.graphql.InvokeSingleClickOnDiagramElementToolMutationRunner; +import org.eclipse.sirius.components.diagrams.tests.navigation.DiagramNavigator; +import org.eclipse.sirius.components.graphql.tests.ExecuteEditingContextFunctionSuccessPayload; +import org.eclipse.sirius.components.graphql.tests.api.GraphQLResult; +import org.eclipse.sirius.components.trees.TreeItem; +import org.eclipse.sirius.components.view.diagram.DiagramDescription; +import org.eclipse.sirius.components.view.diagram.NodeDescription; +import org.eclipse.sirius.components.view.diagram.NodeTool; +import org.eclipse.sirius.components.view.diagram.SelectionDialogDescription; +import org.eclipse.sirius.components.view.emf.diagram.IDiagramIdProvider; +import org.eclipse.sirius.web.tests.services.api.IGivenInitialServerState; +import org.eclipse.sirius.web.tests.services.representation.RepresentationIdBuilder; +import org.eclipse.sirius.web.tests.services.selection.SelectionDialogTreeEventSubscriptionRunner; +import org.eclipse.syson.AbstractIntegrationTests; +import org.eclipse.syson.application.data.GeneralViewWithTopNodesTestProjectData; +import org.eclipse.syson.services.SemanticRunnableFactory; +import org.eclipse.syson.services.diagrams.DiagramDescriptionIdProvider; +import org.eclipse.syson.services.diagrams.api.IGivenDiagramDescription; +import org.eclipse.syson.services.diagrams.api.IGivenDiagramSubscription; +import org.eclipse.syson.standard.diagrams.view.SDVDescriptionNameGenerator; +import org.eclipse.syson.sysml.AttributeUsage; +import org.eclipse.syson.sysml.Feature; +import org.eclipse.syson.sysml.FeatureMembership; +import org.eclipse.syson.sysml.FeatureTyping; +import org.eclipse.syson.sysml.PartDefinition; +import org.eclipse.syson.sysml.PartUsage; +import org.eclipse.syson.sysml.SysmlFactory; +import org.eclipse.syson.sysml.SysmlPackage; +import org.eclipse.syson.sysml.Type; +import org.eclipse.syson.sysml.metamodel.helper.EMFUtils; +import org.eclipse.syson.tests.api.GivenSysONServer; +import org.eclipse.syson.util.SysONRepresentationDescriptionIdentifiers; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.transaction.annotation.Transactional; + +import reactor.test.StepVerifier; + +/** + * Exercises feature chain selection and redefinition through the diagram tool and its AQL operations. + * + * @author Jerome Gout + */ +@Transactional +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@GivenSysONServer({ GeneralViewWithTopNodesTestProjectData.SCRIPT_PATH }) +@SuppressWarnings("checkstyle:MultipleStringLiterals") +public class GVRedefineNestedFeatureTests extends AbstractIntegrationTests { + + @Autowired + private IGivenInitialServerState givenInitialServerState; + + @Autowired + private IGivenDiagramDescription givenDiagramDescription; + + @Autowired + private IGivenDiagramSubscription givenDiagramSubscription; + + @Autowired + private IDiagramIdProvider diagramIdProvider; + + @Autowired + private IIdentityService identityService; + + @Autowired + private IObjectSearchService objectSearchService; + + @Autowired + private SemanticRunnableFactory semanticRunnableFactory; + + @Autowired + private SelectionDialogTreeEventSubscriptionRunner selectionDialogTreeEventSubscriptionRunner; + + @Autowired + private RepresentationIdBuilder representationIdBuilder; + + @Autowired + private InvokeSingleClickOnDiagramElementToolMutationRunner invokeToolRunner; + + @BeforeEach + public void setUp() { + this.givenInitialServerState.initialize(); + } + + @Test + @DisplayName("GIVEN a part with an inherited nested feature chain, WHEN the diagram tool redefines the chain selected in its dialog, THEN the chain is created and its last feature is selected") + public void redefinesTheSelectedChainAndReturnsItsLastFeatureAsTheNewSelection() { + // GIVEN a diagram part typed by Vehicle and the inherited wheel.diameter chain available in the tool dialog + String editingContextId = GeneralViewWithTopNodesTestProjectData.EDITING_CONTEXT_ID; + String contextId = GeneralViewWithTopNodesTestProjectData.SemanticIds.PART_USAGE_ID; + String diagramId = GeneralViewWithTopNodesTestProjectData.GraphicalIds.DIAGRAM_ID; + DiagramDescription description = this.givenDiagramDescription.getDiagramDescription(editingContextId, + SysONRepresentationDescriptionIdentifiers.GENERAL_VIEW_DIAGRAM_DESCRIPTION_ID); + String nodeDescriptionName = new SDVDescriptionNameGenerator().getNodeName(SysmlPackage.eINSTANCE.getPartUsage()); + String toolId = new DiagramDescriptionIdProvider(description, this.diagramIdProvider).getNodeToolId(nodeDescriptionName, "Redefine a nested feature"); + NodeTool tool = EMFUtils.allContainedObjectOfType(description, NodeDescription.class) + .filter(node -> nodeDescriptionName.equals(node.getName())) + .flatMap(node -> EMFUtils.allContainedObjectOfType(node.getPalette(), NodeTool.class)) + .filter(nodeTool -> "Redefine a nested feature".equals(nodeTool.getName())) + .findFirst().orElseThrow(); + SelectionDialogDescription dialog = (SelectionDialogDescription) tool.getDialogDescription(); + String treeDescriptionId = this.diagramIdProvider.getId(dialog.getSelectionDialogTreeDescription()); + + AtomicReference diagram = new AtomicReference<>(); + AtomicReference selectedChainId = new AtomicReference<>(); + AtomicReference> newSelection = new AtomicReference<>(); + AtomicReference sourcePart = new AtomicReference<>(); + AtomicReference sourceAttribute = new AtomicReference<>(); + + Runnable initializeModel = this.createModelInitializationRunnable(editingContextId, contextId, sourcePart, sourceAttribute); + + Runnable selectChainInDialog = () -> { + String treeId = this.representationIdBuilder.buildSelectionRepresentationId(treeDescriptionId, contextId, List.of()); + var treeInput = new SelectionDialogTreeEventInput(UUID.randomUUID(), editingContextId, treeId); + StepVerifier.create(this.selectionDialogTreeEventSubscriptionRunner.run(treeInput).flux()) + .consumeNextWith(assertRefreshedTreeThat(tree -> { + TreeItem chain = tree.getChildren().stream() + .filter(item -> "wheel.diameter".equals(item.getLabel().toString())) + .findFirst().orElseThrow(); + assertThat(chain.isSelectable()).isTrue(); + selectedChainId.set(chain.getId()); + })) + .thenCancel() + .verify(Duration.ofSeconds(10)); + }; + + // WHEN the diagram tool is invoked with the feature chain selected in the dialog + Runnable invokeTool = () -> { + String nodeId = new DiagramNavigator(diagram.get()).nodeWithTargetObjectId(contextId).getNode().getId(); + var input = new InvokeSingleClickOnDiagramElementToolInput(UUID.randomUUID(), editingContextId, diagramId, List.of(nodeId), toolId, 0, 0, + List.of(new ToolVariable("selectedObject", selectedChainId.get(), ToolVariableType.OBJECT_ID))); + GraphQLResult result = this.invokeToolRunner.run(input); + + // THEN the tool succeeds without errors or feedback messages and returns a single selection entry + assertThat(result.errors()).isEmpty(); + String typename = JsonPath.read(result.data(), "$.data.invokeSingleClickOnDiagramElementTool.__typename"); + assertThat(typename).isEqualTo(InvokeSingleClickOnDiagramElementToolSuccessPayload.class.getSimpleName()); + List messages = JsonPath.read(result.data(), "$.data.invokeSingleClickOnDiagramElementTool.messages"); + assertThat(messages).isEmpty(); + List selectionIds = JsonPath.read(result.data(), "$.data.invokeSingleClickOnDiagramElementTool.newSelection.entries[*].id"); + assertThat(selectionIds).hasSize(1); + newSelection.set(selectionIds); + }; + + // THEN the local chain redefines wheel.diameter, its last feature is selected and the source chain is unchanged + Runnable checkChainAndSelection = this.semanticRunnableFactory.createQueryRunnable(editingContextId, (editingContext, input) -> { + PartUsage context = (PartUsage) this.objectSearchService.getObject(editingContext, contextId).orElseThrow(); + assertThat(context.getOwnedFeature()).hasSize(1); + Feature localPart = context.getOwnedFeature().getFirst(); + assertThat(localPart.getOwnedFeature()).hasSize(1); + Feature localAttribute = localPart.getOwnedFeature().getFirst(); + assertThat(localPart.getOwnedRedefinition()).singleElement() + .satisfies(redefinition -> assertThat(redefinition.getRedefinedFeature()).isSameAs(sourcePart.get())); + assertThat(localAttribute.getOwnedRedefinition()).singleElement() + .satisfies(redefinition -> assertThat(redefinition.getRedefinedFeature()).isSameAs(sourceAttribute.get())); + assertThat(newSelection.get()).containsExactly(this.identityService.getId(localAttribute)); + assertThat(sourcePart.get().getOwnedFeature()).containsExactly(sourceAttribute.get()); + return new ExecuteEditingContextFunctionSuccessPayload(input.id(), true); + }); + + var diagramInput = new DiagramEventInput(UUID.randomUUID(), editingContextId, diagramId); + StepVerifier.create(this.givenDiagramSubscription.subscribe(diagramInput)) + // GIVEN the initialized model, refreshed diagram and wheel.diameter selected in the dialog + .consumeNextWith(assertRefreshedDiagramThat(diagram::set)) + .then(initializeModel) + .consumeNextWith(assertRefreshedDiagramThat(diagram::set)) + .then(selectChainInDialog) + // WHEN the tool redefines the selected chain + .then(invokeTool) + // THEN the diagram refreshes and the local chain and final selection satisfy the assertions + .consumeNextWith(assertRefreshedDiagramThat(diagram::set)) + .then(checkChainAndSelection) + .thenCancel() + .verify(Duration.ofSeconds(20)); + } + + private void addFeature(Type owner, Feature feature) { + FeatureMembership membership = SysmlFactory.eINSTANCE.createFeatureMembership(); + owner.getOwnedRelationship().add(membership); + membership.getOwnedRelatedElement().add(feature); + } + + private Runnable createModelInitializationRunnable(String editingContextId, String contextId, AtomicReference sourcePart, AtomicReference sourceAttribute) { + return this.semanticRunnableFactory.createMutationRunnable(editingContextId, (editingContext, input) -> { + /* + * Fixture structure (context denotes the existing part used by the tool): + * part def Vehicle { + * part wheel { + * attribute diameter; + * } + * } + * part context : Vehicle; + */ + PartUsage context = (PartUsage) this.objectSearchService.getObject(editingContext, contextId).orElseThrow(); + PartDefinition definition = SysmlFactory.eINSTANCE.createPartDefinition(); + definition.setDeclaredName("Vehicle"); + context.eResource().getContents().add(definition); + PartUsage wheel = SysmlFactory.eINSTANCE.createPartUsage(); + wheel.setDeclaredName("wheel"); + AttributeUsage diameter = SysmlFactory.eINSTANCE.createAttributeUsage(); + diameter.setDeclaredName("diameter"); + this.addFeature(definition, wheel); + this.addFeature(wheel, diameter); + FeatureTyping typing = SysmlFactory.eINSTANCE.createFeatureTyping(); + context.getOwnedRelationship().add(typing); + typing.setType(definition); + typing.setTypedFeature(context); + sourcePart.set(wheel); + sourceAttribute.set(diameter); + return new ExecuteEditingContextFunctionSuccessPayload(input.id(), true); + }); + } +} diff --git a/backend/services/syson-tree-services/src/main/java/org/eclipse/syson/tree/services/TreeMutationSelectionDialogService.java b/backend/services/syson-tree-services/src/main/java/org/eclipse/syson/tree/services/TreeMutationSelectionDialogService.java new file mode 100644 index 0000000000..bf66142d56 --- /dev/null +++ b/backend/services/syson-tree-services/src/main/java/org/eclipse/syson/tree/services/TreeMutationSelectionDialogService.java @@ -0,0 +1,70 @@ +/******************************************************************************* + * Copyright (c) 2025, 2026 Obeo. + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Obeo - initial API and implementation + *******************************************************************************/ +package org.eclipse.syson.tree.services; + +import java.util.List; +import java.util.Objects; + +import org.eclipse.sirius.components.core.api.IFeedbackMessageService; +import org.eclipse.sirius.components.representations.Message; +import org.eclipse.sirius.components.representations.MessageLevel; +import org.eclipse.syson.services.ContextualFeatureChain; +import org.eclipse.syson.sysml.Feature; +import org.eclipse.syson.sysml.Type; +import org.eclipse.syson.sysml.metamodel.services.MetamodelMutationElementService; +import org.eclipse.syson.sysml.metamodel.services.redefine.FeatureChainRedefinitionResult; +import org.springframework.stereotype.Service; + +/** + * Selection dialog services doing tree mutations. + * + * @author Jerome Gout + */ +@Service +public class TreeMutationSelectionDialogService { + + private final IFeedbackMessageService feedbackMessageService; + + /** + * Creates a selection dialog mutation service. + * + * @param feedbackMessageService + * the service used to report feature chain redefinition errors + */ + public TreeMutationSelectionDialogService(IFeedbackMessageService feedbackMessageService) { + this.feedbackMessageService = Objects.requireNonNull(feedbackMessageService); + } + + /** + * Redefines the selected chain and reports failures without changing the model. + * + * @param context + * the type on which the tool was invoked + * @param chain + * the feature chain selected in the dialog + * @return the local redefined feature chain, or null on failure + */ + public List redefineFeatureChain(Type context, ContextualFeatureChain chain) { + List features = null; + if (chain != null) { + features = chain.features(); + } + FeatureChainRedefinitionResult result = new MetamodelMutationElementService().redefineFeatureChain(context, features); + result.messages().forEach(message -> this.feedbackMessageService.addFeedbackMessage(new Message(message, MessageLevel.ERROR))); + List localChain = null; + if (result.isSuccess()) { + localChain = result.chain(); + } + return localChain; + } +} diff --git a/backend/services/syson-tree-services/src/main/java/org/eclipse/syson/tree/services/aql/TreeMutationAQLService.java b/backend/services/syson-tree-services/src/main/java/org/eclipse/syson/tree/services/aql/TreeMutationAQLService.java index ce3efa6dfc..c73867262a 100644 --- a/backend/services/syson-tree-services/src/main/java/org/eclipse/syson/tree/services/aql/TreeMutationAQLService.java +++ b/backend/services/syson-tree-services/src/main/java/org/eclipse/syson/tree/services/aql/TreeMutationAQLService.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2025 Obeo. + * Copyright (c) 2025, 2026 Obeo. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License v2.0 * which accompanies this distribution, and is available at @@ -12,6 +12,14 @@ *******************************************************************************/ package org.eclipse.syson.tree.services.aql; +import java.util.List; +import java.util.Objects; + +import org.eclipse.syson.services.ContextualFeatureChain; +import org.eclipse.syson.sysml.Feature; +import org.eclipse.syson.sysml.Type; +import org.eclipse.syson.tree.services.TreeMutationSelectionDialogService; + /** * Entry point for all tree-related services doing mutations in trees and called by AQL expressions in tree * descriptions. @@ -20,4 +28,28 @@ */ public class TreeMutationAQLService { + private final TreeMutationSelectionDialogService treeMutationSelectionDialogService; + + /** + * Creates a tree mutation AQL service. + * + * @param treeMutationSelectionDialogService + * the selection dialog mutation service + */ + public TreeMutationAQLService(TreeMutationSelectionDialogService treeMutationSelectionDialogService) { + this.treeMutationSelectionDialogService = Objects.requireNonNull(treeMutationSelectionDialogService); + } + + /** + * Redefines the selected chain and reports failures without changing the model. + * + * @param context + * the type on which the tool was invoked + * @param chain + * the feature chain selected in the dialog + * @return the local redefined feature chain, or null on failure + */ + public List redefineFeatureChain(Type context, ContextualFeatureChain chain) { + return this.treeMutationSelectionDialogService.redefineFeatureChain(context, chain); + } } diff --git a/backend/services/syson-tree-services/src/test/java/org/eclipse/syson/tree/services/aql/TreeMutationAQLServiceTest.java b/backend/services/syson-tree-services/src/test/java/org/eclipse/syson/tree/services/aql/TreeMutationAQLServiceTest.java new file mode 100644 index 0000000000..1382922bf6 --- /dev/null +++ b/backend/services/syson-tree-services/src/test/java/org/eclipse/syson/tree/services/aql/TreeMutationAQLServiceTest.java @@ -0,0 +1,179 @@ +/******************************************************************************* + * Copyright (c) 2026 Obeo. + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Obeo - initial API and implementation + *******************************************************************************/ +package org.eclipse.syson.tree.services.aql; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.List; + +import org.eclipse.sirius.components.core.api.IFeedbackMessageService; +import org.eclipse.syson.services.ContextualFeatureChain; +import org.eclipse.syson.sysml.ActionUsage; +import org.eclipse.syson.sysml.AttributeUsage; +import org.eclipse.syson.sysml.Feature; +import org.eclipse.syson.sysml.FeatureDirectionKind; +import org.eclipse.syson.sysml.FeatureMembership; +import org.eclipse.syson.sysml.FeatureTyping; +import org.eclipse.syson.sysml.ParameterMembership; +import org.eclipse.syson.sysml.PartDefinition; +import org.eclipse.syson.sysml.PartUsage; +import org.eclipse.syson.sysml.SysmlFactory; +import org.eclipse.syson.sysml.Type; +import org.eclipse.syson.tree.services.TreeMutationSelectionDialogService; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +/** + * Tests the adaptation of feature chain redefinition results and feedback for AQL callers. + * + * @author Jerome Gout + */ +public class TreeMutationAQLServiceTest { + + private final TreeMutationAQLService service = new TreeMutationAQLService(new TreeMutationSelectionDialogService(new IFeedbackMessageService.NoOp())); + + /** + * Redefines an inherited two-segment chain, then checks that repeating the operation reuses both local features. + */ + @Test + @DisplayName("GIVEN an inherited feature chain, WHEN it is redefined twice, THEN both local features are reused and the source is unchanged") + public void returnsTheWholeLocalChainAndReusesItOnRepeatedInvocations() { + // GIVEN a part usage inheriting a part and its nested attribute from its definition + /* + * Fixture structure (names added for readability): + * part def Definition { + * part sourcePart { + * attribute sourceAttribute; + * } + * } + * part context : Definition; + */ + PartDefinition definition = SysmlFactory.eINSTANCE.createPartDefinition(); + PartUsage context = SysmlFactory.eINSTANCE.createPartUsage(); + FeatureTyping typing = SysmlFactory.eINSTANCE.createFeatureTyping(); + context.getOwnedRelationship().add(typing); + typing.setType(definition); + typing.setTypedFeature(context); + PartUsage part = SysmlFactory.eINSTANCE.createPartUsage(); + AttributeUsage attribute = SysmlFactory.eINSTANCE.createAttributeUsage(); + this.addFeature(definition, part); + this.addFeature(part, attribute); + var chain = new ContextualFeatureChain(context, List.of(part, attribute)); + + // WHEN the inherited part-attribute chain is redefined in the part usage + List result = this.service.redefineFeatureChain(context, chain); + + // THEN both local features are returned, contained in the context and linked to their redefined source features + assertThat(result).hasSize(2); + Feature localPart = result.getFirst(); + Feature localAttribute = result.getLast(); + assertThat(context.getOwnedFeature()).containsExactly(localPart); + assertThat(localPart.getOwnedFeature()).containsExactly(localAttribute); + assertThat(localPart.getOwnedRedefinition()).singleElement().satisfies(redefinition -> assertThat(redefinition.getRedefinedFeature()).isSameAs(part)); + assertThat(localAttribute.getOwnedRedefinition()).singleElement().satisfies(redefinition -> assertThat(redefinition.getRedefinedFeature()).isSameAs(attribute)); + + // WHEN the same inherited chain is redefined again + List repeatedResult = this.service.redefineFeatureChain(context, chain); + + // THEN the same local features are reused without duplicates and the source chain remains unchanged + assertThat(repeatedResult).containsExactly(localPart, localAttribute); + assertThat(context.getOwnedFeature()).containsExactly(localPart); + assertThat(localPart.getOwnedFeature()).containsExactly(localAttribute); + assertThat(part.getOwnedFeature()).containsExactly(attribute); + } + + /** + * Redefines an inherited action and its input parameter in a part usage and checks that both local features are returned. + */ + @Test + @DisplayName("GIVEN a chain ending in an inherited input parameter, WHEN it is redefined, THEN the local action and input parameter are returned in order") + public void returnsTheLocalActionAndInputParameter() { + // GIVEN a part usage inheriting an action with an input parameter + /* + * Fixture structure (names added for readability): + * part def Definition { + * action sourceAction { + * in attribute parameter; + * } + * } + * part context : Definition; + */ + PartDefinition definition = SysmlFactory.eINSTANCE.createPartDefinition(); + PartUsage context = SysmlFactory.eINSTANCE.createPartUsage(); + FeatureTyping typing = SysmlFactory.eINSTANCE.createFeatureTyping(); + context.getOwnedRelationship().add(typing); + typing.setType(definition); + typing.setTypedFeature(context); + ActionUsage action = SysmlFactory.eINSTANCE.createActionUsage(); + AttributeUsage parameter = SysmlFactory.eINSTANCE.createAttributeUsage(); + parameter.setDirection(FeatureDirectionKind.IN); + this.addFeature(definition, action); + ParameterMembership parameterMembership = SysmlFactory.eINSTANCE.createParameterMembership(); + action.getOwnedRelationship().add(parameterMembership); + parameterMembership.getOwnedRelatedElement().add(parameter); + + // WHEN the action-parameter chain is redefined in the part usage + List result = this.service.redefineFeatureChain(context, new ContextualFeatureChain(context, List.of(action, parameter))); + + // THEN the local action owns the returned input parameter and both redefine their corresponding source features + assertThat(result).hasSize(2); + Feature localAction = result.getFirst(); + Feature localParameter = result.getLast(); + assertThat(context.getOwnedFeature()).containsExactly(localAction); + assertThat(localAction.allRedefinedFeatures()).contains(action); + assertThat(localAction.getOwnedFeature()).containsExactly(localParameter); + assertThat(localParameter.getOwningFeatureMembership()).isInstanceOf(ParameterMembership.class); + assertThat(localParameter.getDirection()).isEqualTo(FeatureDirectionKind.IN); + assertThat(localParameter.allRedefinedFeatures()).contains(parameter); + } + + /** + * Invokes redefinition on an empty definition without a selected chain and checks that the context stays unchanged. + */ + @Test + @DisplayName("GIVEN a context without a selected chain, WHEN redefinition is invoked, THEN null is returned and the context is unchanged") + public void missingSelectionReturnsNullWithoutChangingContext() { + // GIVEN an empty part definition without a selected feature chain + PartDefinition context = SysmlFactory.eINSTANCE.createPartDefinition(); + context.setDeclaredName("Context"); + + // WHEN redefinition is invoked with a null selection + List result = this.service.redefineFeatureChain(context, null); + + // THEN null is returned and the context still has no owned relationships + assertThat(result).isNull(); + assertThat(context.getOwnedRelationship()).isEmpty(); + } + + /** + * Invokes redefinition with a single-feature selection but no target context and checks that it returns null. + */ + @Test + @DisplayName("GIVEN a selected feature without a target context, WHEN redefinition is invoked, THEN null is returned") + public void missingContextReturnsNull() { + // GIVEN a selected part usage without a target context for redefinition + PartUsage feature = SysmlFactory.eINSTANCE.createPartUsage(); + + // WHEN redefinition is invoked with a null context + List result = this.service.redefineFeatureChain(null, new ContextualFeatureChain(feature, List.of(feature))); + + // THEN null is returned + assertThat(result).isNull(); + } + + private void addFeature(Type owner, Feature feature) { + FeatureMembership membership = SysmlFactory.eINSTANCE.createFeatureMembership(); + owner.getOwnedRelationship().add(membership); + membership.getOwnedRelatedElement().add(feature); + } +} diff --git a/backend/views/syson-diagram-common-view/src/main/java/org/eclipse/syson/diagram/common/view/tools/RedefineNestedFeatureToolProvider.java b/backend/views/syson-diagram-common-view/src/main/java/org/eclipse/syson/diagram/common/view/tools/RedefineNestedFeatureToolProvider.java index a1926f53ff..ec95a1ea62 100644 --- a/backend/views/syson-diagram-common-view/src/main/java/org/eclipse/syson/diagram/common/view/tools/RedefineNestedFeatureToolProvider.java +++ b/backend/views/syson-diagram-common-view/src/main/java/org/eclipse/syson/diagram/common/view/tools/RedefineNestedFeatureToolProvider.java @@ -12,12 +12,14 @@ *******************************************************************************/ package org.eclipse.syson.diagram.common.view.tools; +import org.eclipse.sirius.components.view.Let; import org.eclipse.sirius.components.view.builder.IViewDiagramElementFinder; import org.eclipse.sirius.components.view.builder.generated.diagram.DiagramBuilders; import org.eclipse.sirius.components.view.builder.generated.view.ViewBuilders; import org.eclipse.sirius.components.view.builder.providers.INodeToolProvider; import org.eclipse.sirius.components.view.diagram.NodeTool; import org.eclipse.sirius.components.view.diagram.SelectionDialogDescription; +import org.eclipse.syson.tree.services.aql.TreeMutationAQLService; import org.eclipse.syson.tree.services.aql.TreeQueryAQLService; import org.eclipse.syson.util.AQLConstants; import org.eclipse.syson.util.ServiceMethod; @@ -35,13 +37,20 @@ public class RedefineNestedFeatureToolProvider implements INodeToolProvider { @Override public NodeTool create(IViewDiagramElementFinder cache) { + Let redefineChain = this.viewBuilderHelper.newLet() + .variableName("redefinedFeatures") + .valueExpression(ServiceMethod.of1(TreeMutationAQLService::redefineFeatureChain).aqlSelf("selectedObject")) + .build(); + return this.diagramBuilderHelper.newNodeTool() .name("Redefine a nested feature") .iconURLsExpression("/icons/full/obj16/Redefinition.svg") .dialogDescription(this.getSelectionDialogDescription()) .body(this.viewBuilderHelper.newChangeContext() .expression(AQLConstants.AQL_SELF) + .children(redefineChain) .build()) + .elementsToSelectExpression("aql:redefinedFeatures->last()") .build(); } diff --git a/backend/views/syson-standard-diagrams-view/src/main/java/org/eclipse/syson/standard/diagrams/view/ActionFlowViewJavaServiceProvider.java b/backend/views/syson-standard-diagrams-view/src/main/java/org/eclipse/syson/standard/diagrams/view/ActionFlowViewJavaServiceProvider.java index 775266e8f8..059e36badd 100644 --- a/backend/views/syson-standard-diagrams-view/src/main/java/org/eclipse/syson/standard/diagrams/view/ActionFlowViewJavaServiceProvider.java +++ b/backend/views/syson-standard-diagrams-view/src/main/java/org/eclipse/syson/standard/diagrams/view/ActionFlowViewJavaServiceProvider.java @@ -24,6 +24,7 @@ import org.eclipse.syson.representation.services.aql.RepresentationQueryAQLService; import org.eclipse.syson.services.UtilService; import org.eclipse.syson.standard.diagrams.view.services.ActionFlowViewCreateService; +import org.eclipse.syson.tree.services.aql.TreeMutationAQLService; import org.eclipse.syson.tree.services.aql.TreeQueryAQLService; import org.springframework.context.annotation.Configuration; @@ -50,7 +51,8 @@ public List> getServiceClasses(View view) { ModelQueryAQLService.class, RepresentationMutationAQLService.class, RepresentationQueryAQLService.class, - TreeQueryAQLService.class); + TreeQueryAQLService.class, + TreeMutationAQLService.class); } return List.of(); } diff --git a/backend/views/syson-standard-diagrams-view/src/main/java/org/eclipse/syson/standard/diagrams/view/InterconnectionViewJavaServiceProvider.java b/backend/views/syson-standard-diagrams-view/src/main/java/org/eclipse/syson/standard/diagrams/view/InterconnectionViewJavaServiceProvider.java index 8a7e974c11..29a47e126c 100644 --- a/backend/views/syson-standard-diagrams-view/src/main/java/org/eclipse/syson/standard/diagrams/view/InterconnectionViewJavaServiceProvider.java +++ b/backend/views/syson-standard-diagrams-view/src/main/java/org/eclipse/syson/standard/diagrams/view/InterconnectionViewJavaServiceProvider.java @@ -24,6 +24,7 @@ import org.eclipse.syson.representation.services.aql.RepresentationQueryAQLService; import org.eclipse.syson.services.UtilService; import org.eclipse.syson.standard.diagrams.view.services.InterconnectionViewCreateService; +import org.eclipse.syson.tree.services.aql.TreeMutationAQLService; import org.eclipse.syson.tree.services.aql.TreeQueryAQLService; import org.springframework.context.annotation.Configuration; @@ -50,7 +51,8 @@ public List> getServiceClasses(View view) { ModelQueryAQLService.class, RepresentationMutationAQLService.class, RepresentationQueryAQLService.class, - TreeQueryAQLService.class); + TreeQueryAQLService.class, + TreeMutationAQLService.class); } return List.of(); } diff --git a/backend/views/syson-standard-diagrams-view/src/main/java/org/eclipse/syson/standard/diagrams/view/SDVJavaServiceProvider.java b/backend/views/syson-standard-diagrams-view/src/main/java/org/eclipse/syson/standard/diagrams/view/SDVJavaServiceProvider.java index e2f1270ed3..c7916f5cb3 100644 --- a/backend/views/syson-standard-diagrams-view/src/main/java/org/eclipse/syson/standard/diagrams/view/SDVJavaServiceProvider.java +++ b/backend/views/syson-standard-diagrams-view/src/main/java/org/eclipse/syson/standard/diagrams/view/SDVJavaServiceProvider.java @@ -25,6 +25,7 @@ import org.eclipse.syson.representation.services.aql.RepresentationQueryAQLService; import org.eclipse.syson.services.DeleteService; import org.eclipse.syson.services.UtilService; +import org.eclipse.syson.tree.services.aql.TreeMutationAQLService; import org.eclipse.syson.tree.services.aql.TreeQueryAQLService; import org.springframework.context.annotation.Configuration; @@ -52,7 +53,8 @@ public List> getServiceClasses(View view) { ModelQueryAQLService.class, RepresentationMutationAQLService.class, RepresentationQueryAQLService.class, - TreeQueryAQLService.class); + TreeQueryAQLService.class, + TreeMutationAQLService.class); } return List.of(); } diff --git a/backend/views/syson-standard-diagrams-view/src/main/java/org/eclipse/syson/standard/diagrams/view/StateTransitionViewJavaServiceProvider.java b/backend/views/syson-standard-diagrams-view/src/main/java/org/eclipse/syson/standard/diagrams/view/StateTransitionViewJavaServiceProvider.java index f99131bcea..4ae84ec5f0 100644 --- a/backend/views/syson-standard-diagrams-view/src/main/java/org/eclipse/syson/standard/diagrams/view/StateTransitionViewJavaServiceProvider.java +++ b/backend/views/syson-standard-diagrams-view/src/main/java/org/eclipse/syson/standard/diagrams/view/StateTransitionViewJavaServiceProvider.java @@ -24,6 +24,7 @@ import org.eclipse.syson.representation.services.aql.RepresentationQueryAQLService; import org.eclipse.syson.services.UtilService; import org.eclipse.syson.standard.diagrams.view.services.StateTransitionViewCreateService; +import org.eclipse.syson.tree.services.aql.TreeMutationAQLService; import org.eclipse.syson.tree.services.aql.TreeQueryAQLService; import org.springframework.context.annotation.Configuration; @@ -50,7 +51,8 @@ public List> getServiceClasses(View view) { ModelQueryAQLService.class, RepresentationMutationAQLService.class, RepresentationQueryAQLService.class, - TreeQueryAQLService.class); + TreeQueryAQLService.class, + TreeMutationAQLService.class); } return List.of(); } diff --git a/doc/content/modules/user-manual/assets/images/redefine-nested-feature-dialog.png b/doc/content/modules/user-manual/assets/images/redefine-nested-feature-dialog.png new file mode 100644 index 0000000000..baff9dd82b Binary files /dev/null and b/doc/content/modules/user-manual/assets/images/redefine-nested-feature-dialog.png differ diff --git a/doc/content/modules/user-manual/assets/images/redefine-nested-feature-model.png b/doc/content/modules/user-manual/assets/images/redefine-nested-feature-model.png new file mode 100644 index 0000000000..44a449965e Binary files /dev/null and b/doc/content/modules/user-manual/assets/images/redefine-nested-feature-model.png differ diff --git a/doc/content/modules/user-manual/assets/images/redefine-nested-feature-result.png b/doc/content/modules/user-manual/assets/images/redefine-nested-feature-result.png new file mode 100644 index 0000000000..d4dbca7c4c Binary files /dev/null and b/doc/content/modules/user-manual/assets/images/redefine-nested-feature-result.png differ diff --git a/doc/content/modules/user-manual/pages/release-notes/2026.12.0.adoc b/doc/content/modules/user-manual/pages/release-notes/2026.12.0.adoc index 2a9772c59d..5f7185a5f6 100644 --- a/doc/content/modules/user-manual/pages/release-notes/2026.12.0.adoc +++ b/doc/content/modules/user-manual/pages/release-notes/2026.12.0.adoc @@ -11,10 +11,10 @@ * In diagrams: -** A new _Redefine a nested feature_ tool is available in the _Structure_ section of diagram palettes for `Usage` and `Definition` graphical nodes. -This initial implementation opens a selection dialog listing configurable feature paths. -Confirming a selection closes the dialog without modifying the model. -Actual feature redefinition will be added in a subsequent change. +** A new _Redefine a nested feature_ tool is available in the _Structure_ section of diagram palettes for `Usage` and `Definition` nodes. +Users can select a feature path to create the required local redefinitions in one operation. +The resulting feature is revealed in the Model Explorer. +See xref:features/general-view.adoc#redefine-nested-feature[Redefine a nested feature] for instructions and an example. * For application developers: diff --git a/doc/content/modules/user-manual/partials/manage-elements-diagram.adoc b/doc/content/modules/user-manual/partials/manage-elements-diagram.adoc index 72f6da6f8c..f157a57fdd 100644 --- a/doc/content/modules/user-manual/partials/manage-elements-diagram.adoc +++ b/doc/content/modules/user-manual/partials/manage-elements-diagram.adoc @@ -32,6 +32,46 @@ The palette is displayed, and users can select the desired creation tool from a image::manage-elements-fromParentCompartment-creation.png[Creation from Parent Compartment, width=70%,height=70%] +[#redefine-nested-feature] +=== Redefine a nested feature + +The _Redefine a nested feature_ tool allows users to customize an inherited feature within a specific _Usage_ or _Definition_, including features nested several levels deep. +The original features remain unchanged. + +Consider the following model: + +image::redefine-nested-feature-model.png[Example model, width=70%, align=center] + +The `vehicle` part inherits the `engine` part from `Vehicle`, and `engine` provides the `power` attribute through its `Engine` definition. +To customize `power` for this vehicle, users can redefine the `engine.power` feature chain directly from the `vehicle` node. + +To redefine a nested feature: + +. Right-click the `vehicle` node to open its palette. +. In the _Structure_ section, select _Redefine a nested feature_. +. In the dialog, select `engine.power`. +. Confirm the selection. + +image::redefine-nested-feature-dialog.png[Feature selection dialog, width=80%, align=center] + +{product} creates the local redefinitions needed along the selected path. +Existing local features or redefinitions are reused. + +In the example above, the tool creates a local redefinition of `engine` inside `vehicle`, then a local redefinition of `power` inside that engine. +If `engine` is already locally redefined, only the missing redefinition of `power` is created. + +The last feature in the resulting chain is selected and revealed in the Model Explorer. +Users can then edit its properties in the Details view. + +image::redefine-nested-feature-result.png[Redefine result, width=70%, align=center] + +[NOTE] +==== +The dialog lists accessible feature chains that still require at least one local redefinition. +Features declared in the SysML and KerML standard libraries are excluded. +Fully local chains are no longer listed. +==== + === Delete element Users can delete a graphical element from the diagram without removing it from the model. diff --git a/frontend/syson-components/src/extensions/redefineNestedFeature/RedefineNestedFeatureSelection.tsx b/frontend/syson-components/src/extensions/redefineNestedFeature/RedefineNestedFeatureSelection.tsx new file mode 100644 index 0000000000..8f46cd1391 --- /dev/null +++ b/frontend/syson-components/src/extensions/redefineNestedFeature/RedefineNestedFeatureSelection.tsx @@ -0,0 +1,85 @@ +/******************************************************************************* + * Copyright (c) 2026 Obeo. + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Obeo - initial API and implementation + *******************************************************************************/ +import { ApolloLink, Observable } from '@apollo/client'; +import { Selection, useSelection, useWorkbench } from '@eclipse-sirius/sirius-components-core'; +import { DiagramToolbarActionProps } from '@eclipse-sirius/sirius-components-diagrams'; +import { useEffect } from 'react'; + +interface FeatureChainSelection { + editingContextId: string; + diagramId: string; + selection: Selection; +} + +const listeners = new Set<(result: FeatureChainSelection) => void>(); + +// Observe the standard invocation so pointer and keyboard activation share selection handling. +export const redefineNestedFeatureSelectionLink = new ApolloLink((operation, forward) => { + const input = operation.variables.input; + const isFeatureChainInvocation = + operation.operationName === 'invokeSingleClickOnDiagramElementTool' && + input?.variables?.some( + (variable: { name: string; value: string }) => + variable.name === 'selectedObject' && variable.value.startsWith('contextual-feature-chain:') + ); + if (!isFeatureChainInvocation) { + return forward(operation); + } + return new Observable((observer) => { + const subscription = forward(operation).subscribe({ + next: (result) => { + const payload = result.data?.invokeSingleClickOnDiagramElementTool; + if ( + !result.errors?.length && + payload?.__typename === 'InvokeSingleClickOnDiagramElementToolSuccessPayload' && + !payload.messages.some((message: { level: string }) => message.level === 'ERROR') && + payload.newSelection?.entries.length + ) { + listeners.forEach((listener) => + listener({ + editingContextId: input.editingContextId, + diagramId: input.representationId, + selection: payload.newSelection, + }) + ); + } + observer.next(result); + }, + error: (error) => observer.error(error), + complete: () => observer.complete(), + }); + return () => subscription.unsubscribe(); + }); +}); + +export const RedefineNestedFeatureSelection = ({ editingContextId, diagramId }: DiagramToolbarActionProps) => { + const { setSelection } = useSelection(); + const workbench = useWorkbench(); + useEffect(() => { + const listener = (result: FeatureChainSelection) => { + if (result.editingContextId === editingContextId && result.diagramId === diagramId) { + setSelection(result.selection); + workbench + .getWorkbenchPanelHandles() + .flatMap((panel) => panel.getWorkbenchViewHandles()) + .find((view) => view.id === 'explorer') + ?.applySelection?.(result.selection); + } + }; + listeners.add(listener); + return () => { + listeners.delete(listener); + }; + }, [editingContextId, diagramId, setSelection, workbench]); + return null; +}; diff --git a/frontend/syson-components/src/extensions/registry/SysONExtensionRegistry.tsx b/frontend/syson-components/src/extensions/registry/SysONExtensionRegistry.tsx index db4acf9391..1f74ddd9ac 100644 --- a/frontend/syson-components/src/extensions/registry/SysONExtensionRegistry.tsx +++ b/frontend/syson-components/src/extensions/registry/SysONExtensionRegistry.tsx @@ -11,6 +11,7 @@ * Obeo - initial API and implementation *******************************************************************************/ +import { ApolloLink } from '@apollo/client'; import { ExtensionRegistry } from '@eclipse-sirius/sirius-components-core'; import { DIAGRAM_REPRESENTATION_KIND, @@ -68,6 +69,10 @@ import { NewExpressionDiagramToolOverriddenContribution } from '../expressions/N import { NewExpressionExplorerToolOverriddenContribution } from '../expressions/NewExpressionExplorerToolOverriddenContribution'; import { NewSysMLExpressionMenuContribution } from '../expressions/NewSysMLExpressionMenuContribution'; import { InsertTextualSysMLv2ExplorerToolOverriddenContribution } from '../InsertTextualSysMLv2ExplorerToolOverriddenContribution'; +import { + RedefineNestedFeatureSelection, + redefineNestedFeatureSelectionLink, +} from '../redefineNestedFeature/RedefineNestedFeatureSelection'; import { InsertTextualSysMLMenuContribution } from '../InsertTextualSysMLv2MenuContribution'; import { SysONNavigationBarMenuIcon } from '../navigationBarMenu/SysONNavigationBarMenuIcon'; import { PublishProjectSysMLContentsAsLibraryCommand } from '../omnibox/PublishProjectSysMLContentsAsLibraryCommand'; @@ -104,6 +109,9 @@ const apolloClientOptionsConfigurer: ApolloClientOptionsConfigurer = (currentOpt : sysMLNodesStyleDocumentTransform; return { ...currentOptions, + link: currentOptions.link + ? ApolloLink.from([redefineNestedFeatureSelectionLink, currentOptions.link]) + : redefineNestedFeatureSelectionLink, documentTransform: newDocumentTransform, }; }; @@ -112,6 +120,11 @@ sysONExtensionRegistry.putData(apolloClientOptionsConfigurersExtensionPoint, { data: [apolloClientOptionsConfigurer], }); +sysONExtensionRegistry.addComponent(diagramToolbarActionExtensionPoint, { + identifier: `syson_${diagramToolbarActionExtensionPoint.identifier}_RedefineNestedFeatureSelection`, + Component: RedefineNestedFeatureSelection, +}); + sysONExtensionRegistry.addComponent(diagramToolbarActionExtensionPoint, { identifier: `syson_${diagramToolbarActionExtensionPoint.identifier}_CustomToolbarEntriesMenu`, Component: SysONDiagramPanelMenu, diff --git a/integration-tests-playwright/playwright/e2e/redefine-nested-feature.spec.ts b/integration-tests-playwright/playwright/e2e/redefine-nested-feature.spec.ts new file mode 100644 index 0000000000..aa9ffb00ce --- /dev/null +++ b/integration-tests-playwright/playwright/e2e/redefine-nested-feature.spec.ts @@ -0,0 +1,91 @@ +/******************************************************************************* + * Copyright (c) 2026 Obeo. + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Obeo - initial API and implementation + *******************************************************************************/ +import { expect, test } from '@playwright/test'; +import { PlaywrightDetails } from '../helpers/PlaywrightDetails'; +import { PlaywrightExplorer } from '../helpers/PlaywrightExplorer'; +import { PlaywrightNode } from '../helpers/PlaywrightNode'; +import { PlaywrightProject } from '../helpers/PlaywrightProject'; + +test.describe('Redefine a nested feature', () => { + let projectId: string; + + test.beforeEach(async ({ page, request }) => { + const project = await new PlaywrightProject(request).createSysMLV2Project('redefine nested feature'); + projectId = project.projectId; + await page.goto(`/projects/${projectId}/edit`); + const explorer = new PlaywrightExplorer(page); + await explorer.uploadDocument('RedefineNestedFeature.sysml'); + await explorer.expand('RedefineNestedFeature.sysml'); + await explorer.expand('Redefinition'); + await explorer.createRepresentation('view1 [GeneralView]', 'General View', 'view1'); + await page.getByTestId('arrange-all-main-button').click(); + }); + + test.afterEach(async ({ request }) => { + await new PlaywrightProject(request).deleteProject(projectId); + }); + + for (const { chain, activation } of [ + { chain: 'wheel', activation: 'pointer' }, + { chain: 'wheel.diameter', activation: 'pointer' }, + { chain: 'wheel.diameter', activation: 'Enter' }, + ]) { + test(`reveals and selects ${chain} in Explorer and Details after ${activation} activation and confirmation`, async ({ + page, + }) => { + const vehicle = new PlaywrightNode(page, 'vehicle : Vehicle', 'List'); + await vehicle.click(); + await vehicle.openPalette(); + if (activation === 'Enter') { + const search = page.getByTestId('Palette').getByRole('textbox'); + await search.fill('Redefine a nested feature'); + await expect(page.getByTestId('tool-Redefine a nested feature')).toBeVisible(); + await search.press('Enter'); + } else { + await page.getByTestId('toolSection-Structure').click(); + await page.getByTestId('tool-Redefine a nested feature').click(); + } + + const dialog = page.getByRole('dialog'); + await expect(dialog.getByTestId('confirm-action')).toBeDisabled(); + await dialog.locator(`[data-treeitemlabel="${chain}"]`).click(); + const invocation = page.waitForResponse((response) => { + return ( + response.url().endsWith('/api/graphql') && + response.request().postDataJSON()?.operationName === 'invokeSingleClickOnDiagramElementTool' + ); + }); + await dialog.getByTestId('confirm-action').click(); + await expect(dialog).toBeHidden(); + const result = await (await invocation).json(); + expect(result.errors).toBeUndefined(); + const payload = result.data.invokeSingleClickOnDiagramElementTool; + expect(payload.__typename).toBe('InvokeSingleClickOnDiagramElementToolSuccessPayload'); + expect(payload.messages).toEqual([]); + expect(payload.newSelection.entries).toHaveLength(1); + const selectedId = payload.newSelection.entries[0].id; + + // Do not select or reveal anything manually: the tool must update both views itself. + const explorer = new PlaywrightExplorer(page); + const selected = explorer.explorerLocator.locator(`[data-treeitemid="${selectedId}"]`); + await expect(selected).toBeVisible(); + await expect(selected).toHaveAttribute('data-testid', 'selected'); + const details = new PlaywrightDetails(page); + await expect(details.detailsLocator).toContainText(`Redefinition::vehicle::${chain.replace('.', '::')}`); + + if (chain === 'wheel.diameter') { + await expect(page.locator('.react-flow__node [data-testid*="diameter"]')).toHaveCount(0); + } + }); + } +}); diff --git a/integration-tests-playwright/playwright/resources/RedefineNestedFeature.sysml b/integration-tests-playwright/playwright/resources/RedefineNestedFeature.sysml new file mode 100644 index 0000000000..1fa3aedd8c --- /dev/null +++ b/integration-tests-playwright/playwright/resources/RedefineNestedFeature.sysml @@ -0,0 +1,11 @@ +package Redefinition { + part def Vehicle { + part wheel { + attribute diameter; + } + } + part vehicle : Vehicle; + view view1 : StandardViewDefinitions::GeneralView { + expose vehicle; + } +}