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 2b298bd commit 7a6b9cc
Showing 1 changed file with 28 additions and 2 deletions.
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 7a6b9cc

Please sign in to comment.