Search in sources :

Example 1 with SingleClickOnTwoDiagramElementsTool

use of org.eclipse.sirius.components.diagrams.tools.SingleClickOnTwoDiagramElementsTool in project sirius-components by eclipse-sirius.

the class DiagramDescriptionConverter method createToolSections.

private List<ToolSection> createToolSections(AQLInterpreter interpreter) {
    var capturedConvertedNodes = Map.copyOf(this.convertedNodes);
    List<ITool> nodeCreationTools = new ArrayList<>();
    for (var nodeDescription : this.convertedNodes.keySet()) {
        // Add custom tools
        int i = 0;
        for (NodeTool nodeTool : nodeDescription.getNodeTools()) {
            // @formatter:off
            SingleClickOnDiagramElementTool customTool = // $NON-NLS-1$
            SingleClickOnDiagramElementTool.newSingleClickOnDiagramElementTool(this.idProvider.apply(nodeDescription) + "_tool" + i++).label(nodeTool.getName()).imageURL(NODE_CREATION_TOOL_ICON).handler(variableManager -> new ToolInterpreter(interpreter, this.objectService, this.editService, this.getDiagramContext(variableManager), capturedConvertedNodes).executeTool(nodeTool, variableManager)).targetDescriptions(Optional.ofNullable(nodeDescription.eContainer()).map(this.convertedNodes::get).stream().collect(Collectors.toList())).appliesToDiagramRoot(nodeDescription.eContainer() instanceof org.eclipse.sirius.components.view.DiagramDescription).build();
            // @formatter:on
            nodeCreationTools.add(customTool);
        }
        // If there are no custom tools defined, add a canonical creation tool
        if (i == 0) {
            // @formatter:off
            SingleClickOnDiagramElementTool tool = // $NON-NLS-1$
            SingleClickOnDiagramElementTool.newSingleClickOnDiagramElementTool(this.idProvider.apply(nodeDescription) + "_creationTool").label(// $NON-NLS-1$
            "New " + this.getSimpleTypeName(nodeDescription.getDomainType())).imageURL(NODE_CREATION_TOOL_ICON).handler(variableManager -> this.canonicalBehaviors.createNewNode(nodeDescription, variableManager)).targetDescriptions(Optional.ofNullable(nodeDescription.eContainer()).map(this.convertedNodes::get).stream().collect(Collectors.toList())).appliesToDiagramRoot(nodeDescription.eContainer() instanceof org.eclipse.sirius.components.view.DiagramDescription).build();
            // @formatter:on
            nodeCreationTools.add(tool);
        }
    }
    List<ITool> edgeCreationTools = new ArrayList<>();
    for (var edgeDescription : this.convertedEdges.keySet()) {
        // Add custom tools
        int i = 0;
        for (EdgeTool edgeTool : edgeDescription.getEdgeTools()) {
            // @formatter:off
            SingleClickOnTwoDiagramElementsTool customTool = // $NON-NLS-1$
            SingleClickOnTwoDiagramElementsTool.newSingleClickOnTwoDiagramElementsTool(this.idProvider.apply(edgeDescription) + "_tool" + i++).label(edgeTool.getName()).imageURL(EDGE_CREATION_TOOL_ICON).candidates(List.of(SingleClickOnTwoDiagramElementsCandidate.newSingleClickOnTwoDiagramElementsCandidate().sources(edgeDescription.getSourceNodeDescriptions().stream().map(this.convertedNodes::get).collect(Collectors.toList())).targets(edgeDescription.getTargetNodeDescriptions().stream().map(this.convertedNodes::get).collect(Collectors.toList())).build())).handler(variableManager -> new ToolInterpreter(interpreter, this.objectService, this.editService, this.getDiagramContext(variableManager), capturedConvertedNodes).executeTool(edgeTool, variableManager)).build();
            // @formatter:on
            edgeCreationTools.add(customTool);
        }
        // If there are no custom tools defined, add a canonical creation tool
        if (i == 0) {
            // @formatter:off
            SingleClickOnTwoDiagramElementsTool tool = // $NON-NLS-1$
            SingleClickOnTwoDiagramElementsTool.newSingleClickOnTwoDiagramElementsTool(this.idProvider.apply(edgeDescription) + "_creationTool").label(// $NON-NLS-1$
            "New " + this.getSimpleTypeName(edgeDescription.getDomainType())).imageURL(EDGE_CREATION_TOOL_ICON).candidates(List.of(SingleClickOnTwoDiagramElementsCandidate.newSingleClickOnTwoDiagramElementsCandidate().sources(edgeDescription.getSourceNodeDescriptions().stream().map(this.convertedNodes::get).collect(Collectors.toList())).targets(edgeDescription.getTargetNodeDescriptions().stream().map(this.convertedNodes::get).collect(Collectors.toList())).build())).handler(variableManager -> this.canonicalBehaviors.createNewEdge(variableManager, edgeDescription)).build();
            // @formatter:on
            edgeCreationTools.add(tool);
        }
    }
    // @formatter:off
    return // $NON-NLS-1$
    List.of(// $NON-NLS-1$
    ToolSection.newToolSection(UUID.randomUUID().toString()).label(NODE_CREATION_TOOL_SECTION).tools(nodeCreationTools).imageURL("").build(), // $NON-NLS-1$
    ToolSection.newToolSection(UUID.randomUUID().toString()).label(EDGE_CREATION_TOOL_SECTION).tools(edgeCreationTools).imageURL("").build());
// @formatter:on
}
Also used : IObjectService(org.eclipse.sirius.components.core.api.IObjectService) BiFunction(java.util.function.BiFunction) DiagramDescription(org.eclipse.sirius.components.diagrams.description.DiagramDescription) INodeStyle(org.eclipse.sirius.components.diagrams.INodeStyle) NodeDescription(org.eclipse.sirius.components.diagrams.description.NodeDescription) ToolSection(org.eclipse.sirius.components.diagrams.tools.ToolSection) IStatus(org.eclipse.sirius.components.representations.IStatus) ITool(org.eclipse.sirius.components.diagrams.tools.ITool) Map(java.util.Map) DomainClassPredicate(org.eclipse.sirius.components.emf.compatibility.DomainClassPredicate) NodeStyle(org.eclipse.sirius.components.view.NodeStyle) Predicate(java.util.function.Predicate) LabelStyleDescription(org.eclipse.sirius.components.diagrams.description.LabelStyleDescription) Result(org.eclipse.sirius.components.interpreter.Result) EObject(org.eclipse.emf.ecore.EObject) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) AQLInterpreter(org.eclipse.sirius.components.interpreter.AQLInterpreter) Element(org.eclipse.sirius.components.representations.Element) Objects(java.util.Objects) List(java.util.List) EdgeDescription(org.eclipse.sirius.components.diagrams.description.EdgeDescription) SingleClickOnTwoDiagramElementsCandidate(org.eclipse.sirius.components.diagrams.tools.SingleClickOnTwoDiagramElementsCandidate) Optional(java.util.Optional) IRepresentationDescription(org.eclipse.sirius.components.representations.IRepresentationDescription) LabelDescription(org.eclipse.sirius.components.diagrams.description.LabelDescription) Size(org.eclipse.sirius.components.diagrams.Size) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) SynchronizationPolicy(org.eclipse.sirius.components.diagrams.description.SynchronizationPolicy) HashMap(java.util.HashMap) Function(java.util.function.Function) ArrayList(java.util.ArrayList) Status(org.eclipse.sirius.components.interpreter.Status) EClass(org.eclipse.emf.ecore.EClass) SingleClickOnDiagramElementTool(org.eclipse.sirius.components.diagrams.tools.SingleClickOnDiagramElementTool) CanonicalBehaviors(org.eclipse.sirius.components.emf.view.CanonicalBehaviors) SingleClickOnTwoDiagramElementsTool(org.eclipse.sirius.components.diagrams.tools.SingleClickOnTwoDiagramElementsTool) IEditService(org.eclipse.sirius.components.core.api.IEditService) EdgeStyle(org.eclipse.sirius.components.diagrams.EdgeStyle) DiagramRenderingCache(org.eclipse.sirius.components.diagrams.renderer.DiagramRenderingCache) ToolInterpreter(org.eclipse.sirius.components.emf.view.ToolInterpreter) IDiagramContext(org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramContext) Failure(org.eclipse.sirius.components.representations.Failure) EcoreUtil(org.eclipse.emf.ecore.util.EcoreUtil) DiagramElementDescription(org.eclipse.sirius.components.view.DiagramElementDescription) EdgeTool(org.eclipse.sirius.components.view.EdgeTool) LabelEditTool(org.eclipse.sirius.components.view.LabelEditTool) ViewPackage(org.eclipse.sirius.components.view.ViewPackage) NodeElementProps(org.eclipse.sirius.components.diagrams.elements.NodeElementProps) VariableManager(org.eclipse.sirius.components.representations.VariableManager) DeleteTool(org.eclipse.sirius.components.view.DeleteTool) NodeTool(org.eclipse.sirius.components.view.NodeTool) ToolInterpreter(org.eclipse.sirius.components.emf.view.ToolInterpreter) ArrayList(java.util.ArrayList) SingleClickOnTwoDiagramElementsTool(org.eclipse.sirius.components.diagrams.tools.SingleClickOnTwoDiagramElementsTool) ITool(org.eclipse.sirius.components.diagrams.tools.ITool) DiagramDescription(org.eclipse.sirius.components.diagrams.description.DiagramDescription) EdgeTool(org.eclipse.sirius.components.view.EdgeTool) NodeTool(org.eclipse.sirius.components.view.NodeTool) SingleClickOnDiagramElementTool(org.eclipse.sirius.components.diagrams.tools.SingleClickOnDiagramElementTool)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 UUID (java.util.UUID)1 BiFunction (java.util.function.BiFunction)1 Function (java.util.function.Function)1 Predicate (java.util.function.Predicate)1 Collectors (java.util.stream.Collectors)1 EClass (org.eclipse.emf.ecore.EClass)1 EObject (org.eclipse.emf.ecore.EObject)1 EcoreUtil (org.eclipse.emf.ecore.util.EcoreUtil)1 IDiagramContext (org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramContext)1 IEditService (org.eclipse.sirius.components.core.api.IEditService)1 IEditingContext (org.eclipse.sirius.components.core.api.IEditingContext)1 IObjectService (org.eclipse.sirius.components.core.api.IObjectService)1 EdgeStyle (org.eclipse.sirius.components.diagrams.EdgeStyle)1 INodeStyle (org.eclipse.sirius.components.diagrams.INodeStyle)1