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 19, 2024
1 parent 2c93cf3 commit bc5a894
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 @@ -111,6 +111,7 @@ The implemented fix does not allow to evaluate an AQL expression, but only to re
- https://github.com/eclipse-sirius/sirius-web/issues/3044[#3044] [diagram] Fix an issue that caused the selection between the diagram and the explorer to be desynchronized
- https://github.com/eclipse-sirius/sirius-web/issues/2956[#2956] [diagram] Fix an issue where diagram performance were degraded over time when moving elements.
- https://github.com/eclipse-sirius/sirius-web/issues/3228[#3228] [diagram] Fix an issue where list child could be moved outside its container
- 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 @@ -157,7 +157,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 @@ -280,7 +283,10 @@ private Palette getEdgePalette(IEditingContext editingContext, EdgeDescription e

String edgePaletteId = "siriusComponents://edgePalette?edgeId=" + sourceElementId;
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 @@ -60,12 +60,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 @@ -78,9 +83,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 @@ -96,6 +107,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 bc5a894

Please sign in to comment.