Search in sources :

Example 1 with DeleteElementDescription

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;
}
Also used : DeleteElementDescription(org.eclipse.sirius.diagram.description.tool.DeleteElementDescription) NodeCreationDescription(org.eclipse.sirius.diagram.description.tool.NodeCreationDescription) ToolDescription(org.eclipse.sirius.viewpoint.description.tool.ToolDescription) ITool(org.eclipse.sirius.components.diagrams.tools.ITool) OperationAction(org.eclipse.sirius.viewpoint.description.tool.OperationAction) ToolDescription(org.eclipse.sirius.viewpoint.description.tool.ToolDescription) AbstractToolDescription(org.eclipse.sirius.viewpoint.description.tool.AbstractToolDescription) ContainerCreationDescription(org.eclipse.sirius.diagram.description.tool.ContainerCreationDescription) EdgeCreationDescription(org.eclipse.sirius.diagram.description.tool.EdgeCreationDescription)

Example 2 with DeleteElementDescription

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("");
        };
    }
}
Also used : InitialOperation(org.eclipse.sirius.viewpoint.description.tool.InitialOperation) Node(org.eclipse.sirius.components.diagrams.Node) IDiagramContext(org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramContext) Failure(org.eclipse.sirius.components.representations.Failure) IModelOperationHandlerSwitchProvider(org.eclipse.sirius.components.compatibility.api.IModelOperationHandlerSwitchProvider) ContainerDropDescription(org.eclipse.sirius.diagram.description.tool.ContainerDropDescription) BiFunction(java.util.function.BiFunction) ViewDeletionRequest(org.eclipse.sirius.components.diagrams.ViewDeletionRequest) Success(org.eclipse.sirius.components.representations.Success) InitialOperation(org.eclipse.sirius.viewpoint.description.tool.InitialOperation) InitialContainerDropOperation(org.eclipse.sirius.viewpoint.description.tool.InitialContainerDropOperation) DeletionPolicy(org.eclipse.sirius.components.collaborative.diagrams.dto.DeletionPolicy) Function(java.util.function.Function) AQLInterpreter(org.eclipse.sirius.components.interpreter.AQLInterpreter) DirectEditLabel(org.eclipse.sirius.diagram.description.tool.DirectEditLabel) Objects(java.util.Objects) DeleteElementDescription(org.eclipse.sirius.diagram.description.tool.DeleteElementDescription) List(java.util.List) DeleteFromDiagramEventHandler(org.eclipse.sirius.components.collaborative.diagrams.handlers.DeleteFromDiagramEventHandler) Diagram(org.eclipse.sirius.components.diagrams.Diagram) IStatus(org.eclipse.sirius.components.representations.IStatus) Map(java.util.Map) Optional(java.util.Optional) VariableManager(org.eclipse.sirius.components.representations.VariableManager) IEditService(org.eclipse.sirius.components.core.api.IEditService) DeletionPolicy(org.eclipse.sirius.components.collaborative.diagrams.dto.DeletionPolicy) DeleteElementDescription(org.eclipse.sirius.diagram.description.tool.DeleteElementDescription) Node(org.eclipse.sirius.components.diagrams.Node) IDiagramContext(org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramContext) ViewDeletionRequest(org.eclipse.sirius.components.diagrams.ViewDeletionRequest) Map(java.util.Map) Failure(org.eclipse.sirius.components.representations.Failure) Success(org.eclipse.sirius.components.representations.Success)

Aggregations

DeleteElementDescription (org.eclipse.sirius.diagram.description.tool.DeleteElementDescription)2 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 BiFunction (java.util.function.BiFunction)1 Function (java.util.function.Function)1 IDiagramContext (org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramContext)1 DeletionPolicy (org.eclipse.sirius.components.collaborative.diagrams.dto.DeletionPolicy)1 DeleteFromDiagramEventHandler (org.eclipse.sirius.components.collaborative.diagrams.handlers.DeleteFromDiagramEventHandler)1 IModelOperationHandlerSwitchProvider (org.eclipse.sirius.components.compatibility.api.IModelOperationHandlerSwitchProvider)1 IEditService (org.eclipse.sirius.components.core.api.IEditService)1 Diagram (org.eclipse.sirius.components.diagrams.Diagram)1 Node (org.eclipse.sirius.components.diagrams.Node)1 ViewDeletionRequest (org.eclipse.sirius.components.diagrams.ViewDeletionRequest)1 ITool (org.eclipse.sirius.components.diagrams.tools.ITool)1 AQLInterpreter (org.eclipse.sirius.components.interpreter.AQLInterpreter)1 Failure (org.eclipse.sirius.components.representations.Failure)1 IStatus (org.eclipse.sirius.components.representations.IStatus)1 Success (org.eclipse.sirius.components.representations.Success)1