From 0c602da2be7c65c9a77bc7f42837a169cd314519 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20B=C3=A9gaudeau?= Date: Fri, 14 Jan 2022 11:05:38 +0100 Subject: [PATCH] [822] Add the support for the GRAPHICAL deletion policy in the compatibility layer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug: https://github.com/eclipse-sirius/sirius-components/issues/822 Signed-off-by: Axel RICHARD Signed-off-by: Stéphane Bégaudeau --- CHANGELOG.adoc | 2 ++ .../web/compat/diagrams/ToolConverter.java | 30 +++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index e5984bf37f..1665612159 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -43,7 +43,9 @@ Currently it is not possible to compute different values for width and height. - https://github.com/eclipse-sirius/sirius-components/issues/132[#132] [diagram] Add support for drag and drop from the explorer to a diagram - https://github.com/eclipse-sirius/sirius-components/issues/924[#924] [view] Add support for all text styles on labels - https://github.com/eclipse-sirius/sirius-components/issues/929[#929] [core] Add support for providing a listener on GraphQLWebSocketHandler operations + - https://github.com/eclipse-sirius/sirius-components/issues/884[#884] [view] Add support for defining unsynchronized nodes and edges +- https://github.com/eclipse-sirius/sirius-components/issues/822[#822] [diagram] Add support for graphical deletion. We can now offer a dedicated menu in the user interface to perform a graphical deletion instead of a semantic one. On the backend, the compatibility layer has been updated to perform a `DeletionViewRequest` if there is no default deletion tool and a new variable named `deletionPolicy` is available to determine if the deletion should be performed graphically or semantically === Improvements diff --git a/backend/sirius-web-compatibility/src/main/java/org/eclipse/sirius/web/compat/diagrams/ToolConverter.java b/backend/sirius-web-compatibility/src/main/java/org/eclipse/sirius/web/compat/diagrams/ToolConverter.java index ba7bb235e4..7d7e31c4e7 100644 --- a/backend/sirius-web-compatibility/src/main/java/org/eclipse/sirius/web/compat/diagrams/ToolConverter.java +++ b/backend/sirius-web-compatibility/src/main/java/org/eclipse/sirius/web/compat/diagrams/ToolConverter.java @@ -28,12 +28,15 @@ import org.eclipse.sirius.web.core.api.IEditService; import org.eclipse.sirius.web.diagrams.Diagram; import org.eclipse.sirius.web.diagrams.Node; +import org.eclipse.sirius.web.diagrams.ViewDeletionRequest; import org.eclipse.sirius.web.interpreter.AQLInterpreter; import org.eclipse.sirius.web.representations.Failure; import org.eclipse.sirius.web.representations.IStatus; import org.eclipse.sirius.web.representations.Success; import org.eclipse.sirius.web.representations.VariableManager; import org.eclipse.sirius.web.spring.collaborative.diagrams.api.IDiagramContext; +import org.eclipse.sirius.web.spring.collaborative.diagrams.dto.DeletionPolicy; +import org.eclipse.sirius.web.spring.collaborative.diagrams.handlers.DeleteFromDiagramEventHandler; /** * Converts Sirius Diagrams tools definitions into plain Java functions that can be easily invoked without depending on @@ -102,8 +105,31 @@ public Function createDeleteToolHandler(DeleteElementD } else { // If no delete tool is defined, execute the default behavior: delete the underlying semantic element. return variableManager -> { - Optional.of(variableManager.getVariables().get(VariableManager.SELF)).ifPresent(this.editService::delete); - return new Success(); + var optionalObject = variableManager.get(VariableManager.SELF, Object.class); + var optionalSelectedNode = variableManager.get(Node.SELECTED_NODE, Node.class); + var optionalDiagramContext = variableManager.get(IDiagramContext.DIAGRAM_CONTEXT, IDiagramContext.class); + + if (optionalObject.isPresent()) { + Object object = optionalObject.get(); + + DeletionPolicy deletionPolicy = variableManager.get(DeleteFromDiagramEventHandler.DELETION_POLICY, DeletionPolicy.class).orElse(DeletionPolicy.SEMANTIC); + if (DeletionPolicy.SEMANTIC == deletionPolicy) { + this.editService.delete(object); + } else if (optionalDiagramContext.isPresent() && optionalSelectedNode.isPresent()) { + IDiagramContext diagramContext = optionalDiagramContext.get(); + Node selectedNode = optionalSelectedNode.get(); + // @formatter:off + ViewDeletionRequest viewDeletionRequest = ViewDeletionRequest.newViewDeletionRequest() + .elementId(selectedNode.getId()) + .build(); + // @formatter:on + + diagramContext.getViewDeletionRequests().add(viewDeletionRequest); + } + return new Success(); + } + + return new Failure(""); //$NON-NLS-1$ }; } }