Skip to content

Commit

Permalink
[3206] Add precondition check for edge tool and diagram tool section
Browse files Browse the repository at this point in the history
Bug: #3206
Signed-off-by: Florian ROUËNÉ <florian.rouene@obeosoft.com>
  • Loading branch information
frouene committed Mar 12, 2024
1 parent 814a19d commit d09c07e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Expand Up @@ -98,6 +98,7 @@ The implemented fix does not allow to evaluate an AQL expression, but only to re
- https://github.com/eclipse-sirius/sirius-web/issues/2825[#2825] [diagram] Fix an issue where a click on the text during direct edit opened the palette instead of change the caret position.
- https://github.com/eclipse-sirius/sirius-web/issues/3185[#3185] [diagram] Fix an issue where child nodes were used in helper lines computation of container.
- https://github.com/eclipse-sirius/sirius-web/issues/3149[#3149] [diagram] Fix an issue where newly created border nodes could overlap existing one
- https://github.com/eclipse-sirius/sirius-web/issues/3206[#3206] [diagram] Fix an issue where precondition on tool was not respected during palette creation

=== New Features

Expand Down
Expand Up @@ -171,7 +171,10 @@ private ToolSection createToolSection(DiagramToolSection toolSection, VariableMa
return ToolSection.newToolSection(toolSelectionId)
.label(toolSection.getName())
.iconURL(List.of())
.tools(toolSection.getNodeTools().stream().map(tool -> this.createDiagramRootNodeTool(tool, variableManager, interpreter)).toList())
.tools(toolSection.getNodeTools().stream()
.filter(tool -> this.checkPrecondition(tool, variableManager, interpreter))
.map(tool -> this.createDiagramRootNodeTool(tool, variableManager, interpreter))
.toList())
.build();
}

Expand Down Expand Up @@ -287,7 +290,10 @@ protected Palette getEdgePalette(IEditingContext editingContext, EdgeDescription
.toList());
toolSections.addAll(extraToolSections);
edgePalette = Palette.newPalette(edgePaletteId)
.tools(toolFinder.findNodeTools(viewEdgeDescription).stream().map(tool -> this.createNodeTool(tool, variableManager, interpreter)).toList())
.tools(toolFinder.findNodeTools(viewEdgeDescription).stream()
.filter(tool -> this.checkPrecondition(tool, variableManager, interpreter))
.map(tool -> this.createNodeTool(tool, variableManager, interpreter))
.toList())
.toolSections(toolSections)
.build();

Expand Down
Expand Up @@ -59,12 +59,17 @@
*/
public class ViewPaletteProviderTests {

public static final String PRECONDITION_EXPRESSION_FALSE = "false";

private static EdgeDescription getEdgeDescription() {
EdgeDescription edgeDescription = DiagramFactory.eINSTANCE.createEdgeDescription();
EdgePalette edgePalette = DiagramFactory.eINSTANCE.createEdgePalette();
edgeDescription.setPalette(edgePalette);
NodeTool nodeTool = DiagramFactory.eINSTANCE.createNodeTool();
edgePalette.getNodeTools().add(nodeTool);
NodeTool nodeToolWithFalsePrecondition = DiagramFactory.eINSTANCE.createNodeTool();
nodeToolWithFalsePrecondition.setPreconditionExpression(PRECONDITION_EXPRESSION_FALSE);
edgePalette.getNodeTools().add(nodeToolWithFalsePrecondition);
EdgeToolSection toolSection = DiagramFactory.eINSTANCE.createEdgeToolSection();
edgePalette.getToolSections().add(toolSection);
NodeTool nodeToolInToolSection = DiagramFactory.eINSTANCE.createNodeTool();
Expand All @@ -77,9 +82,15 @@ private static org.eclipse.sirius.components.view.diagram.NodeDescription getNod
NodePalette nodePalette = DiagramFactory.eINSTANCE.createNodePalette();
nodeDescription.setPalette(nodePalette);
NodeTool nodeTool = DiagramFactory.eINSTANCE.createNodeTool();
NodeTool nodeToolWithFalsePrecondition = DiagramFactory.eINSTANCE.createNodeTool();
nodeToolWithFalsePrecondition.setPreconditionExpression(PRECONDITION_EXPRESSION_FALSE);
EdgeTool edgeTool = DiagramFactory.eINSTANCE.createEdgeTool();
EdgeTool edgeToolWithFalsePrecondition = DiagramFactory.eINSTANCE.createEdgeTool();
edgeToolWithFalsePrecondition.setPreconditionExpression(PRECONDITION_EXPRESSION_FALSE);
nodePalette.getNodeTools().add(nodeTool);
nodePalette.getEdgeTools().add(edgeTool);
nodePalette.getNodeTools().add(nodeToolWithFalsePrecondition);
nodePalette.getEdgeTools().add(edgeToolWithFalsePrecondition);
NodeToolSection toolSection = DiagramFactory.eINSTANCE.createNodeToolSection();
nodePalette.getToolSections().add(toolSection);
NodeTool nodeToolInToolSection = DiagramFactory.eINSTANCE.createNodeTool();
Expand All @@ -95,6 +106,9 @@ private static org.eclipse.sirius.components.view.diagram.DiagramDescription get
diagramDescription.setPalette(diagramPalette);
NodeTool nodeTool = DiagramFactory.eINSTANCE.createNodeTool();
diagramPalette.getNodeTools().add(nodeTool);
NodeTool nodeToolWithFalsePrecondition = DiagramFactory.eINSTANCE.createNodeTool();
nodeToolWithFalsePrecondition.setPreconditionExpression(PRECONDITION_EXPRESSION_FALSE);
diagramPalette.getNodeTools().add(nodeToolWithFalsePrecondition);
DiagramToolSection diagramToolSection = DiagramFactory.eINSTANCE.createDiagramToolSection();
diagramPalette.getToolSections().add(diagramToolSection);
NodeTool nodeToolInToolSection = DiagramFactory.eINSTANCE.createNodeTool();
Expand Down

0 comments on commit d09c07e

Please sign in to comment.