From 741eb6e526caaf4104d12b3a362743d8a08b1294 Mon Sep 17 00:00:00 2001 From: Axel RICHARD Date: Tue, 28 May 2024 21:46:13 +0200 Subject: [PATCH] [3539] Add editing context variable in diagram delete tool Bug: https://github.com/eclipse-sirius/sirius-web/issues/3539 Signed-off-by: Axel RICHARD --- CHANGELOG.adoc | 1 + .../DeleteFromDiagramEventHandler.java | 38 +++++++++---------- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 32ae28a89f..8da366905a 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -44,6 +44,7 @@ - https://github.com/eclipse-sirius/sirius-web/issues/3511[#3511] [diagram] Improve edge handle position for border nodes - https://github.com/eclipse-sirius/sirius-web/issues/2837[#2837] [gantt] Enhance gantt scroll bar management - https://github.com/eclipse-sirius/sirius-web/issues/3441[#3441] [gantt] Use a DateTime widget for AbstractTask entity +- https://github.com/eclipse-sirius/sirius-web/issues/3539[#3539] [diagram] Add editing context variable in diagram delete tool == v2024.5.0 diff --git a/packages/diagrams/backend/sirius-components-collaborative-diagrams/src/main/java/org/eclipse/sirius/components/collaborative/diagrams/handlers/DeleteFromDiagramEventHandler.java b/packages/diagrams/backend/sirius-components-collaborative-diagrams/src/main/java/org/eclipse/sirius/components/collaborative/diagrams/handlers/DeleteFromDiagramEventHandler.java index 6a94aaaae0..0c5302393d 100644 --- a/packages/diagrams/backend/sirius-components-collaborative-diagrams/src/main/java/org/eclipse/sirius/components/collaborative/diagrams/handlers/DeleteFromDiagramEventHandler.java +++ b/packages/diagrams/backend/sirius-components-collaborative-diagrams/src/main/java/org/eclipse/sirius/components/collaborative/diagrams/handlers/DeleteFromDiagramEventHandler.java @@ -187,13 +187,8 @@ private IStatus invokeDeleteNodeTool(Node node, IEditingContext editingContext, if (optionalNodeDescription.isPresent()) { var optionalSelf = this.objectService.getObject(editingContext, node.getTargetObjectId()); if (optionalSelf.isPresent()) { - VariableManager variableManager = new VariableManager(); - variableManager.put(VariableManager.SELF, optionalSelf.get()); - variableManager.put(IDiagramContext.DIAGRAM_CONTEXT, diagramContext); - variableManager.put(Node.SELECTED_NODE, node); - variableManager.put(DELETION_POLICY, deletionPolicy); - variableManager.put(Environment.ENVIRONMENT, new Environment(Environment.SIRIUS_COMPONENTS)); - variableManager.put(IDiagramService.DIAGRAM_SERVICES, new DiagramService(diagramContext)); + var self = optionalSelf.get(); + var variableManager = this.populateVariableManager(editingContext, diagramContext, self, node, null, deletionPolicy); NodeDescription nodeDescription = optionalNodeDescription.get(); this.logger.debug("Deleted diagram element {}", node.getId()); result = nodeDescription.getDeleteHandler().apply(variableManager); @@ -216,22 +211,14 @@ private IStatus invokeDeleteEdgeTool(Edge edge, IEditingContext editingContext, if (optionalEdgeDescription.isPresent()) { var optionalSelf = this.objectService.getObject(editingContext, edge.getTargetObjectId()); if (optionalSelf.isPresent()) { - VariableManager variableManager = new VariableManager(); - variableManager.put(VariableManager.SELF, optionalSelf.get()); - variableManager.put(IDiagramContext.DIAGRAM_CONTEXT, diagramContext); - variableManager.put(Edge.SELECTED_EDGE, edge); - variableManager.put(DELETION_POLICY, deletionPolicy); - variableManager.put(Environment.ENVIRONMENT, new Environment(Environment.SIRIUS_COMPONENTS)); - variableManager.put(IDiagramService.DIAGRAM_SERVICES, new DiagramService(diagramContext)); - - // @formatter:off + var self = optionalSelf.get(); + var variableManager = this.populateVariableManager(editingContext, diagramContext, self, null, edge, deletionPolicy); this.diagramQueryService.findNodeById(diagramContext.getDiagram(), edge.getSourceId()) .flatMap(node -> this.objectService.getObject(editingContext, node.getTargetObjectId())) .ifPresent(semanticElement -> variableManager.put(EdgeDescription.SEMANTIC_EDGE_SOURCE, semanticElement)); this.diagramQueryService.findNodeById(diagramContext.getDiagram(), edge.getTargetId()) .flatMap(node -> this.objectService.getObject(editingContext, node.getTargetObjectId())) .ifPresent(semanticElement -> variableManager.put(EdgeDescription.SEMANTIC_EDGE_TARGET, semanticElement)); - // @formatter:on EdgeDescription edgeDescription = optionalEdgeDescription.get(); this.logger.debug("Deleted diagram edge {}", edge.getId()); @@ -249,23 +236,32 @@ private IStatus invokeDeleteEdgeTool(Edge edge, IEditingContext editingContext, return result; } + private VariableManager populateVariableManager(IEditingContext editingContext, IDiagramContext diagramContext, Object self, Node selectedNode, Edge selectedEdge, DeletionPolicy deletionPolicy) { + VariableManager variableManager = new VariableManager(); + variableManager.put(IDiagramContext.DIAGRAM_CONTEXT, diagramContext); + variableManager.put(IEditingContext.EDITING_CONTEXT, editingContext); + variableManager.put(Environment.ENVIRONMENT, new Environment(Environment.SIRIUS_COMPONENTS)); + variableManager.put(IDiagramService.DIAGRAM_SERVICES, new DiagramService(diagramContext)); + variableManager.put(VariableManager.SELF, self); + variableManager.put(DELETION_POLICY, deletionPolicy); + variableManager.put(Node.SELECTED_NODE, selectedNode); + variableManager.put(Edge.SELECTED_EDGE, selectedEdge); + return variableManager; + } + private Optional findNodeDescription(Node node, Diagram diagram, IEditingContext editingContext) { - // @formatter:off return this.representationDescriptionSearchService .findById(editingContext, diagram.getDescriptionId()) .filter(DiagramDescription.class::isInstance) .map(DiagramDescription.class::cast) .flatMap(diagramDescription -> this.diagramDescriptionService.findNodeDescriptionById(diagramDescription, node.getDescriptionId())); - // @formatter:on } private Optional findEdgeDescription(Edge edge, Diagram diagram, IEditingContext editingContext) { - // @formatter:off return this.representationDescriptionSearchService .findById(editingContext, diagram.getDescriptionId()) .filter(DiagramDescription.class::isInstance) .map(DiagramDescription.class::cast) .flatMap(diagramDescription -> this.diagramDescriptionService.findEdgeDescriptionById(diagramDescription, edge.getDescriptionId())); - // @formatter:on } }