Skip to content

Commit af1c2b1

Browse files
committed
[6118] Support auto_until_change layout option
Bug: #6118 Signed-off-by: Florian ROUËNÉ <florian.rouene@obeosoft.com>
1 parent b0892f5 commit af1c2b1

File tree

35 files changed

+292
-133
lines changed

35 files changed

+292
-133
lines changed

CHANGELOG.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ The key bindings are visible in the palette next to the tool name.
9595
A key binding needs to contain at least one of `Control`, `Alt`, or `Meta` to be executed by the frontend.
9696
- https://github.com/eclipse-sirius/sirius-web/issues/3488[#3488] [diagram] Restore auto-layout support for diagrams
9797
- https://github.com/eclipse-sirius/sirius-web/issues/5062[#5062] [sirius-web] Add new "views explorer" view
98+
- https://github.com/eclipse-sirius/sirius-web/issues/6118[#6118] [diagram] Add support for auto layout until change
9899

99100

100101
=== Improvements

integration-tests-playwright/playwright/e2e/diagrams/auto-layout.spec.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,40 @@ test.describe('diagram - auto-layout', () => {
8282
);
8383
});
8484
});
85+
86+
test.describe('diagram - auto-until-manual', () => {
87+
let projectId;
88+
test.beforeEach(async ({ page, request }) => {
89+
const project = await new PlaywrightProject(request).createProject('Studio', 'studio-template');
90+
projectId = project.projectId;
91+
92+
await page.goto(`/projects/${projectId}/edit/`);
93+
});
94+
95+
test.afterEach(async ({ request }) => {
96+
await new PlaywrightProject(request).deleteProject(projectId);
97+
});
98+
99+
test('when a diagram with auto-until-manual is opened, then all nodes are positioned according to the elk layout', async ({
100+
page,
101+
}) => {
102+
await expect(page.getByTestId('rf__wrapper')).toBeAttached();
103+
104+
const node = new PlaywrightNode(page, 'Entity1', 'List');
105+
const position = await node.getReactFlowXYPosition();
106+
expect(position.x).toBe(12);
107+
expect(position.y).toBe(242);
108+
});
109+
110+
test('when moving a node on an auto-until-manual diagram, then move is not reset', async ({ page }) => {
111+
await expect(page.getByTestId('rf__wrapper')).toBeAttached();
112+
113+
const rootNode = new PlaywrightNode(page, 'Entity1', 'List');
114+
const rootPositionBefore = await rootNode.getDOMXYPosition();
115+
await rootNode.move({ x: 100, y: 100 });
116+
117+
const rootPositionAfter = await rootNode.getDOMXYPosition();
118+
expect(rootPositionAfter.x).not.toBe(rootPositionBefore.x);
119+
expect(rootPositionAfter.y).not.toBe(rootPositionBefore.y);
120+
});
121+
});

packages/diagrams/backend/sirius-components-collaborative-diagrams/src/main/java/org/eclipse/sirius/components/collaborative/diagrams/DiagramCreationService.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.eclipse.sirius.components.diagrams.components.DiagramComponentProps;
3939
import org.eclipse.sirius.components.diagrams.components.DiagramComponentProps.Builder;
4040
import org.eclipse.sirius.components.diagrams.description.DiagramDescription;
41+
import org.eclipse.sirius.components.diagrams.description.DiagramLayoutOption;
4142
import org.eclipse.sirius.components.diagrams.events.IDiagramEvent;
4243
import org.eclipse.sirius.components.diagrams.events.undoredo.DiagramEdgeLayoutEvent;
4344
import org.eclipse.sirius.components.diagrams.events.undoredo.DiagramLabelLayoutEvent;
@@ -186,7 +187,8 @@ private Diagram doRender(Object targetObject, IEditingContext editingContext, Di
186187
.filter(DiagramEdgeLayoutEvent.class::isInstance)
187188
.map(DiagramEdgeLayoutEvent.class::cast).toList();
188189

189-
var newLayoutData = optionalPreviousDiagram.map(Diagram::getLayoutData).orElse(new DiagramLayoutData(Map.of(), Map.of(), Map.of()));
190+
var newLayoutData = optionalPreviousDiagram.map(Diagram::getLayoutData).orElse(new DiagramLayoutData(Map.of(), Map.of(), Map.of(),
191+
!diagramDescription.getLayoutOption().equals(DiagramLayoutOption.NONE)));
190192

191193
diagramNodeLayoutEvents.forEach(nodeLayoutDataEvent ->
192194
newLayoutData.nodeLayoutData().put(nodeLayoutDataEvent.nodeId(), nodeLayoutDataEvent.nodeLayoutData()));
@@ -230,7 +232,14 @@ public Diagram updateLayout(IEditingContext editingContext, Diagram diagram, Lay
230232
(oldValue, newValue) -> newValue
231233
));
232234

233-
var layoutData = new DiagramLayoutData(nodeLayoutData, edgeLayoutData, labelLayoutData);
235+
boolean autoLaidOut = diagram.getLayoutData().autoLaidOut();
236+
if (layoutDiagramInput.diagramLayoutData().cancelAutoLayout()) {
237+
autoLaidOut = false;
238+
}
239+
if (layoutDiagramInput.diagramLayoutData().startAutoLayout()) {
240+
autoLaidOut = true;
241+
}
242+
var layoutData = new DiagramLayoutData(nodeLayoutData, edgeLayoutData, labelLayoutData, autoLaidOut);
234243
var laidOutDiagram = Diagram.newDiagram(diagram)
235244
.layoutData(layoutData)
236245
.build();

packages/diagrams/backend/sirius-components-collaborative-diagrams/src/main/java/org/eclipse/sirius/components/collaborative/diagrams/dto/DiagramLayoutDataInput.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2023, 2025 Obeo.
2+
* Copyright (c) 2023, 2026 Obeo.
33
* This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v2.0
55
* which accompanies this distribution, and is available at
@@ -19,6 +19,10 @@
1919
*
2020
* @author sbegaudeau
2121
*/
22-
public record DiagramLayoutDataInput(List<NodeLayoutDataInput> nodeLayoutData, List<EdgeLayoutDataInput> edgeLayoutData, List<LabelLayoutDataInput> labelLayoutData) {
22+
public record DiagramLayoutDataInput(List<NodeLayoutDataInput> nodeLayoutData,
23+
List<EdgeLayoutDataInput> edgeLayoutData,
24+
List<LabelLayoutDataInput> labelLayoutData,
25+
boolean cancelAutoLayout,
26+
boolean startAutoLayout) {
2327

2428
}

packages/diagrams/backend/sirius-components-collaborative-diagrams/src/main/java/org/eclipse/sirius/components/collaborative/diagrams/dto/DiagramLayoutDataPayload.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2023, 2025 Obeo.
2+
* Copyright (c) 2023, 2026 Obeo.
33
* This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v2.0
55
* which accompanies this distribution, and is available at
@@ -23,6 +23,6 @@
2323
*
2424
* @author sbegaudeau
2525
*/
26-
public record DiagramLayoutDataPayload(List<NodeLayoutData> nodeLayoutData, List<EdgeLayoutData> edgeLayoutData, List<LabelLayoutData> labelLayoutData) {
26+
public record DiagramLayoutDataPayload(List<NodeLayoutData> nodeLayoutData, List<EdgeLayoutData> edgeLayoutData, List<LabelLayoutData> labelLayoutData, boolean autoLaidOut) {
2727

2828
}

packages/diagrams/backend/sirius-components-collaborative-diagrams/src/main/resources/schema/diagram.graphqls

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ type DiagramLayoutData {
4141
nodeLayoutData: [NodeLayoutData!]!
4242
edgeLayoutData: [EdgeLayoutData!]!
4343
labelLayoutData: [LabelLayoutData!]!
44+
autoLaidOut: Boolean!
4445
}
4546

4647
type NodeLayoutData {
@@ -729,6 +730,8 @@ input DiagramLayoutDataInput {
729730
nodeLayoutData: [NodeLayoutDataInput!]!
730731
edgeLayoutData: [EdgeLayoutDataInput!]!
731732
labelLayoutData: [LabelLayoutDataInput!]!
733+
cancelAutoLayout: Boolean!
734+
startAutoLayout: Boolean!
732735
}
733736

734737
input NodeLayoutDataInput {

packages/diagrams/backend/sirius-components-collaborative-diagrams/src/test/java/org/eclipse/sirius/components/collaborative/diagrams/handlers/GetNodeDescriptionsEventHandlerTests.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2024, 2025 Obeo.
2+
* Copyright (c) 2024, 2026 Obeo.
33
* This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v2.0
55
* which accompanies this distribution, and is available at
@@ -81,6 +81,7 @@ public Optional<IRepresentationDescription> findById(IEditingContext editingCont
8181
}
8282
return desc;
8383
}
84+
8485
@Override
8586
public Map<String, IRepresentationDescription> findAll(IEditingContext editingContext) {
8687
var descriptions = new HashMap<String, IRepresentationDescription>();
@@ -103,7 +104,7 @@ public Map<String, IRepresentationDescription> findAll(IEditingContext editingCo
103104
var diagram = Diagram.newDiagram(UUID.randomUUID().toString())
104105
.descriptionId(DIAGRAM_DESCRIPTION_ID)
105106
.edges(List.of())
106-
.layoutData(new DiagramLayoutData(Map.of(), Map.of(), Map.of()))
107+
.layoutData(new DiagramLayoutData(Map.of(), Map.of(), Map.of(), false))
107108
.nodes(List.of())
108109
.targetObjectId("")
109110
.build();

packages/diagrams/backend/sirius-components-diagrams-graphql/src/main/java/org/eclipse/sirius/components/diagrams/graphql/datafetchers/diagram/DiagramLayoutDataDataFetcher.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2023, 2025 Obeo.
2+
* Copyright (c) 2023, 2026 Obeo.
33
* This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v2.0
55
* which accompanies this distribution, and is available at
@@ -48,6 +48,6 @@ public DiagramLayoutDataPayload get(DataFetchingEnvironment environment) throws
4848
.stream()
4949
.toList();
5050

51-
return new DiagramLayoutDataPayload(nodeLayoutData, edgeLayoutData, labelLayoutData);
51+
return new DiagramLayoutDataPayload(nodeLayoutData, edgeLayoutData, labelLayoutData, diagram.getLayoutData().autoLaidOut());
5252
}
5353
}

packages/diagrams/backend/sirius-components-diagrams/src/main/java/org/eclipse/sirius/components/diagrams/Diagram.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2019, 2024 Obeo.
2+
* Copyright (c) 2019, 2026 Obeo.
33
* This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v2.0
55
* which accompanies this distribution, and is available at
@@ -28,6 +28,7 @@
2828
*/
2929
@Immutable
3030
public final class Diagram implements IRepresentation {
31+
3132
public static final String KIND = IRepresentation.KIND_PREFIX + "?type=Diagram";
3233

3334
private String id;
@@ -101,9 +102,10 @@ public String toString() {
101102
*/
102103
@SuppressWarnings("checkstyle:HiddenField")
103104
public static final class Builder {
104-
private String id;
105105

106-
private String kind = KIND;
106+
private final String id;
107+
108+
private final String kind = KIND;
107109

108110
private String targetObjectId;
109111

@@ -113,7 +115,7 @@ public static final class Builder {
113115

114116
private List<Edge> edges;
115117

116-
private DiagramLayoutData layoutData = new DiagramLayoutData(Map.of(), Map.of(), Map.of());
118+
private DiagramLayoutData layoutData = new DiagramLayoutData(Map.of(), Map.of(), Map.of(), false);
117119

118120
private Builder(String id) {
119121
this.id = Objects.requireNonNull(id);

packages/diagrams/backend/sirius-components-diagrams/src/main/java/org/eclipse/sirius/components/diagrams/layoutdata/DiagramLayoutData.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2023 Obeo.
2+
* Copyright (c) 2023, 2026 Obeo.
33
* This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v2.0
55
* which accompanies this distribution, and is available at
@@ -23,7 +23,9 @@
2323
public record DiagramLayoutData(
2424
Map<String, NodeLayoutData> nodeLayoutData,
2525
Map<String, EdgeLayoutData> edgeLayoutData,
26-
Map<String, LabelLayoutData> labelLayoutData) {
26+
Map<String, LabelLayoutData> labelLayoutData,
27+
boolean autoLaidOut) {
28+
2729
public DiagramLayoutData {
2830
Objects.requireNonNull(nodeLayoutData);
2931
Objects.requireNonNull(edgeLayoutData);

0 commit comments

Comments
 (0)