Skip to content

Commit

Permalink
[3539] Add editing context variable in diagram delete tool
Browse files Browse the repository at this point in the history
Bug: eclipse-sirius#3539
Signed-off-by: Axel RICHARD <[email protected]>
  • Loading branch information
AxelRICHARD authored and sbegaudeau committed Jun 3, 2024
1 parent a0f8d43 commit 741eb6e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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());
Expand All @@ -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<NodeDescription> 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<EdgeDescription> 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
}
}

0 comments on commit 741eb6e

Please sign in to comment.