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
}
Aggregations