use of org.eclipse.sirius.diagram.description.tool.DeleteElementDescription in project sirius-components by eclipse-sirius.
the class ToolProvider method convertTool.
private Optional<ITool> convertTool(Map<UUID, NodeDescription> id2NodeDescriptions, org.eclipse.sirius.diagram.description.DiagramDescription siriusDiagramDescription, AbstractToolDescription siriusTool, AQLInterpreter interpreter) {
Optional<ITool> result = Optional.empty();
if (siriusTool instanceof NodeCreationDescription) {
NodeCreationDescription nodeCreationTool = (NodeCreationDescription) siriusTool;
result = Optional.of(this.convertNodeCreationDescription(id2NodeDescriptions, interpreter, nodeCreationTool));
} else if (siriusTool instanceof ContainerCreationDescription) {
ContainerCreationDescription containerCreationDescription = (ContainerCreationDescription) siriusTool;
result = Optional.of(this.convertContainerCreationDescription(id2NodeDescriptions, interpreter, containerCreationDescription));
} else if (siriusTool instanceof org.eclipse.sirius.viewpoint.description.tool.ToolDescription) {
org.eclipse.sirius.viewpoint.description.tool.ToolDescription toolDescription = (org.eclipse.sirius.viewpoint.description.tool.ToolDescription) siriusTool;
result = Optional.of(this.convertToolDescription(id2NodeDescriptions, interpreter, siriusDiagramDescription, toolDescription));
} else if (siriusTool instanceof EdgeCreationDescription) {
EdgeCreationDescription edgeCreationDescription = (EdgeCreationDescription) siriusTool;
result = Optional.of(this.convertEdgeCreationDescription(id2NodeDescriptions, interpreter, edgeCreationDescription));
} else if (siriusTool instanceof DeleteElementDescription) {
DeleteElementDescription deleteElementDescription = (DeleteElementDescription) siriusTool;
result = Optional.of(this.convertDeleteElementDescription(id2NodeDescriptions, interpreter, deleteElementDescription));
} else if (siriusTool instanceof OperationAction) {
OperationAction operationAction = (OperationAction) siriusTool;
result = Optional.of(this.convertOperationAction(id2NodeDescriptions, interpreter, siriusDiagramDescription, operationAction));
}
return result;
}
use of org.eclipse.sirius.diagram.description.tool.DeleteElementDescription in project sirius-components by eclipse-sirius.
the class ToolConverter method createDeleteToolHandler.
public Function<VariableManager, IStatus> createDeleteToolHandler(DeleteElementDescription deleteDescription) {
var optionalInitialOperation = Optional.ofNullable(deleteDescription).map(DeleteElementDescription::getInitialOperation);
if (optionalInitialOperation.isPresent()) {
InitialOperation initialOperation = optionalInitialOperation.get();
return variableManager -> {
Map<String, Object> variables = variableManager.getVariables();
// Sirius Desktop Delete Tools expect an "element" variable to be available with the value
// of the initial invocation context (self).
// $NON-NLS-1$
variables.put("element", variables.get(VariableManager.SELF));
var selectedNode = variableManager.get(Node.SELECTED_NODE, Node.class);
if (selectedNode.isPresent()) {
variables.put(ELEMENT_VIEW, selectedNode.get());
var diagramContext = variableManager.get(IDiagramContext.DIAGRAM_CONTEXT, IDiagramContext.class);
if (diagramContext.isPresent()) {
variableManager.put(CONTAINER_VIEW, this.getParentNode(selectedNode.get(), diagramContext.get().getDiagram()));
}
}
var modelOperationHandlerSwitch = this.modelOperationHandlerSwitchProvider.getModelOperationHandlerSwitch(this.interpreter);
return modelOperationHandlerSwitch.apply(initialOperation.getFirstModelOperations()).map(handler -> {
return handler.handle(variables);
}).orElse(// $NON-NLS-1$
new Failure(""));
};
} else {
// If no delete tool is defined, execute the default behavior: delete the underlying semantic element.
return variableManager -> {
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();
}
// $NON-NLS-1$
return new Failure("");
};
}
}
Aggregations