Search in sources :

Example 1 with EdgeCreationDescription

use of org.eclipse.sirius.diagram.description.tool.EdgeCreationDescription 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 EdgeCreationDescription

use of org.eclipse.sirius.diagram.description.tool.EdgeCreationDescription in project sirius-components by eclipse-sirius.

the class CompatibilityToolSectionsProvider method checkPrecondition.

private boolean checkPrecondition(Object targetElement, Object diagramElement, AbstractToolDescription siriusTool, org.eclipse.sirius.diagram.description.DiagramDescription siriusDiagramDescription) {
    boolean checkPrecondition = false;
    if (!(siriusTool instanceof EdgeCreationDescription)) {
        AQLInterpreter interpreter = this.interpreterFactory.create(siriusDiagramDescription);
        String precondition = siriusTool.getPrecondition();
        if (precondition != null && !precondition.isBlank()) {
            VariableManager variableManager = new VariableManager();
            variableManager.put(VariableManager.SELF, targetElement);
            variableManager.put(Environment.ENVIRONMENT, Environment.SIRIUS_COMPONENTS);
            if (diagramElement instanceof Node) {
                variableManager.put(Node.SELECTED_NODE, diagramElement);
            } else if (diagramElement instanceof Edge) {
                variableManager.put(Edge.SELECTED_EDGE, diagramElement);
            }
            Result result = interpreter.evaluateExpression(variableManager.getVariables(), precondition);
            checkPrecondition = result.getStatus().compareTo(Status.WARNING) <= 0 && result.asBoolean().orElse(Boolean.FALSE);
        } else {
            checkPrecondition = true;
        }
    } else {
        checkPrecondition = true;
    }
    return checkPrecondition;
}
Also used : VariableManager(org.eclipse.sirius.components.representations.VariableManager) AQLInterpreter(org.eclipse.sirius.components.interpreter.AQLInterpreter) Node(org.eclipse.sirius.components.diagrams.Node) Edge(org.eclipse.sirius.components.diagrams.Edge) EdgeCreationDescription(org.eclipse.sirius.diagram.description.tool.EdgeCreationDescription) Result(org.eclipse.sirius.components.interpreter.Result)

Aggregations

EdgeCreationDescription (org.eclipse.sirius.diagram.description.tool.EdgeCreationDescription)2 Edge (org.eclipse.sirius.components.diagrams.Edge)1 Node (org.eclipse.sirius.components.diagrams.Node)1 ITool (org.eclipse.sirius.components.diagrams.tools.ITool)1 AQLInterpreter (org.eclipse.sirius.components.interpreter.AQLInterpreter)1 Result (org.eclipse.sirius.components.interpreter.Result)1 VariableManager (org.eclipse.sirius.components.representations.VariableManager)1 ContainerCreationDescription (org.eclipse.sirius.diagram.description.tool.ContainerCreationDescription)1 DeleteElementDescription (org.eclipse.sirius.diagram.description.tool.DeleteElementDescription)1 NodeCreationDescription (org.eclipse.sirius.diagram.description.tool.NodeCreationDescription)1 AbstractToolDescription (org.eclipse.sirius.viewpoint.description.tool.AbstractToolDescription)1 OperationAction (org.eclipse.sirius.viewpoint.description.tool.OperationAction)1 ToolDescription (org.eclipse.sirius.viewpoint.description.tool.ToolDescription)1