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 14, 2024
1 parent 2daf28a commit a0cf4f8
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 @@ -105,6 +105,7 @@ The implemented fix does not allow to evaluate an AQL expression, but only to re
- https://github.com/eclipse-sirius/sirius-web/issues/3217[#3217] [diagram] Prevent helper lines to be displayed on moving a pinned node
- https://github.com/eclipse-sirius/sirius-web/issues/3215[#3215] [vscode] Fix an issue where it was impossible to delete elements on a diagram from the VSCode extension.
- https://github.com/eclipse-sirius/sirius-web/issues/3208[#3208] [form] Fix an issue with splitbutton default style in form editor
- 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 a0cf4f8

Please sign in to comment.