Skip to content

Commit

Permalink
[822] Add the support for the GRAPHICAL deletion policy in the compat…
Browse files Browse the repository at this point in the history
…ibility layer

Bug: #822
Signed-off-by: Axel RICHARD <axel.richard@obeo.fr>
Signed-off-by: Stéphane Bégaudeau <stephane.begaudeau@obeo.fr>
  • Loading branch information
sbegaudeau committed Jan 14, 2022
1 parent 2607bb0 commit c19a9bb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -102,8 +105,31 @@ public Function<VariableManager, IStatus> 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$
};
}
}
Expand Down

0 comments on commit c19a9bb

Please sign in to comment.