Skip to content

Commit e175c5e

Browse files
committed
[5651] Add support for undo redo on label appearance and label layout data
Bug: #5651 Signed-off-by: Michaël Charfadi <michael.charfadi@obeosoft.com>
1 parent 1b9dd51 commit e175c5e

File tree

27 files changed

+1479
-63
lines changed

27 files changed

+1479
-63
lines changed

CHANGELOG.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ In conjonction of the `workbenchViewContributionExtensionPoint` frontend extensi
212212
- https://github.com/eclipse-sirius/sirius-web/issues/5958[#5958] [diagram] Allow the execution of adjust size tool on a multi selection
213213
- https://github.com/eclipse-sirius/sirius-web/issues/5937[#5937] [diagram] Add support for bending points for oblique edges
214214
- https://github.com/eclipse-sirius/sirius-web/issues/5300[#5300] [diagram] Add undo redo for node layout
215+
- https://github.com/eclipse-sirius/sirius-web/issues/5651[#5651] [diagram] Add undo redo for label layout and appearance
215216

216217

217218
=== Improvements

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.eclipse.sirius.components.diagrams.components.DiagramComponentProps.Builder;
4040
import org.eclipse.sirius.components.diagrams.description.DiagramDescription;
4141
import org.eclipse.sirius.components.diagrams.events.IDiagramEvent;
42+
import org.eclipse.sirius.components.diagrams.events.undoredo.DiagramLabelLayoutEvent;
4243
import org.eclipse.sirius.components.diagrams.events.undoredo.DiagramNodeLayoutEvent;
4344
import org.eclipse.sirius.components.diagrams.layoutdata.DiagramLayoutData;
4445
import org.eclipse.sirius.components.diagrams.layoutdata.EdgeLayoutData;
@@ -174,11 +175,18 @@ private Diagram doRender(Object targetObject, IEditingContext editingContext, Di
174175

175176
List<DiagramNodeLayoutEvent> diagramNodeLayoutEvents = diagramEvents.stream()
176177
.filter(DiagramNodeLayoutEvent.class::isInstance)
177-
.map(DiagramNodeLayoutEvent.class::cast).toList();
178+
.map(DiagramNodeLayoutEvent.class::cast)
179+
.toList();
180+
181+
List<DiagramLabelLayoutEvent> diagramLabelLayoutEvents = diagramEvents.stream()
182+
.filter(DiagramLabelLayoutEvent.class::isInstance)
183+
.map(DiagramLabelLayoutEvent.class::cast)
184+
.toList();
178185

179186
var newLayoutData = optionalPreviousDiagram.map(Diagram::getLayoutData).orElse(new DiagramLayoutData(Map.of(), Map.of(), Map.of()));
180187

181188
diagramNodeLayoutEvents.forEach(nodeLayoutDataEvent -> newLayoutData.nodeLayoutData().put(nodeLayoutDataEvent.nodeId(), nodeLayoutDataEvent.nodeLayoutData()));
189+
diagramLabelLayoutEvents.forEach(nodeLabelDataEvent -> newLayoutData.labelLayoutData().put(nodeLabelDataEvent.nodeId(), nodeLabelDataEvent.labelLayoutData()));
182190

183191
newDiagram = Diagram.newDiagram(newDiagram)
184192
.layoutData(newLayoutData)

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2021, 2025 Obeo.
2+
* Copyright (c) 2021, 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
@@ -40,10 +40,9 @@ public Optional<Node> findNodeById(Diagram diagram, String nodeId) {
4040
@Override
4141
public Optional<Node> findNodeByLabelId(Diagram diagram, String labelId) {
4242
return this.findNode(node -> {
43-
if (node.getInsideLabel() != null) {
44-
return Objects.equals(node.getInsideLabel().getId(), labelId);
45-
}
46-
return node.getOutsideLabels().stream().anyMatch(label -> Objects.equals(label.id(), labelId));
43+
boolean isCandidateNode = node.getInsideLabel() != null && Objects.equals(node.getInsideLabel().getId(), labelId);
44+
isCandidateNode = isCandidateNode || node.getOutsideLabels().stream().anyMatch(label -> Objects.equals(label.id(), labelId));
45+
return isCandidateNode;
4746
}, diagram.getNodes());
4847
}
4948

packages/diagrams/backend/sirius-components-collaborative-diagrams/src/main/java/org/eclipse/sirius/components/collaborative/diagrams/handlers/appearance/EditLabelAppearanceEventHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2025 Obeo.
2+
* Copyright (c) 2025, 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
@@ -102,7 +102,7 @@ public void handle(Sinks.One<IPayload> payloadSink, Sinks.Many<ChangeDescription
102102
for (String labelId : editAppearanceInput.labelIds()) {
103103
if (node.getOutsideLabels().stream().map(OutsideLabel::id).toList().contains(labelId)) {
104104
diagramElementIdToLabelId.put(diagramElementId, labelId);
105-
} else if (node.getInsideLabel().getId().equals(labelId)) {
105+
} else if (node.getInsideLabel() != null && node.getInsideLabel().getId().equals(labelId)) {
106106
diagramElementIdToLabelId.put(diagramElementId, labelId);
107107
}
108108
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025, 2026 Obeo.
3+
* This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v2.0
5+
* which accompanies this distribution, and is available at
6+
* https://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*
10+
* Contributors:
11+
* Obeo - initial API and implementation
12+
*******************************************************************************/
13+
package org.eclipse.sirius.components.diagrams.events.undoredo;
14+
15+
import org.eclipse.sirius.components.diagrams.events.IDiagramEvent;
16+
import org.eclipse.sirius.components.diagrams.layoutdata.LabelLayoutData;
17+
18+
/**
19+
* Diagram label layout position event.
20+
*
21+
* @author mcharfadi
22+
*/
23+
public record DiagramLabelLayoutEvent(String nodeId, LabelLayoutData labelLayoutData) implements IDiagramEvent {
24+
}

packages/diagrams/frontend/sirius-components-diagrams/src/renderer/layout-events/useLayoutOnBoundsChange.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -116,26 +116,12 @@ export const useLayoutOnBoundsChange = (): UseLayoutOnBoundsChangeValue => {
116116
edges: laidOutDiagram.edges,
117117
};
118118

119-
var id = crypto.randomUUID();
120-
synchronizeLayoutData(id, 'layout', finalDiagram);
121-
addUndoForLayout(id);
119+
synchronizeLayoutData(crypto.randomUUID(), 'layout', finalDiagram);
122120
});
123121
}
124122
},
125123
[synchronizeLayoutData, getNodes]
126124
);
127125

128-
const addUndoForLayout = (mutationId: string) => {
129-
var storedUndoStack = sessionStorage.getItem('undoStack');
130-
var storedRedoStack = sessionStorage.getItem('redoStack');
131-
132-
if (storedUndoStack && storedRedoStack) {
133-
var undoStack: String[] = JSON.parse(storedUndoStack);
134-
if (!undoStack.find((id) => id === mutationId)) {
135-
sessionStorage.setItem('undoStack', JSON.stringify([mutationId, ...undoStack]));
136-
}
137-
}
138-
};
139-
140126
return { layoutOnBoundsChange };
141127
};

packages/diagrams/frontend/sirius-components-diagrams/src/renderer/layout/useSynchronizeLayoutData.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,18 @@ const isErrorPayload = (payload: GQLLayoutDiagramPayload): payload is GQLErrorPa
6161
const isSuccessPayload = (payload: GQLLayoutDiagramPayload): payload is GQLSuccessPayload =>
6262
payload.__typename === 'SuccessPayload';
6363

64+
const addUndoForLayout = (mutationId: string) => {
65+
var storedUndoStack = sessionStorage.getItem('undoStack');
66+
var storedRedoStack = sessionStorage.getItem('redoStack');
67+
68+
if (storedUndoStack && storedRedoStack) {
69+
var undoStack: String[] = JSON.parse(storedUndoStack);
70+
if (!undoStack.find((id) => id === mutationId)) {
71+
sessionStorage.setItem('undoStack', JSON.stringify([mutationId, ...undoStack]));
72+
}
73+
}
74+
};
75+
6476
export const useSynchronizeLayoutData = (): UseSynchronizeLayoutDataValue => {
6577
const { t } = useTranslation('sirius-components-diagrams', { keyPrefix: 'useSynchronizeLayoutData' });
6678
const { diagramId: representationId, editingContextId } = useContext<DiagramContextValue>(DiagramContext);
@@ -251,6 +263,11 @@ export const useSynchronizeLayoutData = (): UseSynchronizeLayoutDataValue => {
251263
};
252264

253265
const variables: GQLLayoutDiagramVariables = { input };
266+
267+
if (cause === 'layout') {
268+
addUndoForLayout(id);
269+
}
270+
254271
layoutDiagram({ variables });
255272
};
256273

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025, 2026 Obeo.
3+
* This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v2.0
5+
* which accompanies this distribution, and is available at
6+
* https://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*
10+
* Contributors:
11+
* Obeo - initial API and implementation
12+
*******************************************************************************/
13+
package org.eclipse.sirius.web.application.undo.services.api;
14+
15+
import org.eclipse.sirius.components.diagrams.LabelStyle;
16+
import org.eclipse.sirius.components.diagrams.events.appearance.IAppearanceChange;
17+
import org.eclipse.sirius.components.diagrams.events.appearance.label.ILabelAppearanceChange;
18+
19+
import java.util.List;
20+
import java.util.Set;
21+
22+
/**
23+
* Use to provide new appearance changes from previous Label and previous Customized StyleProperties.
24+
*
25+
* @author mcharfadi
26+
*/
27+
public interface ILabelAppearanceChangeProvider {
28+
29+
List<IAppearanceChange> getAppearanceChanges(ILabelAppearanceChange change, Set<String> previousCustomizedStyleProperties, LabelStyle previousLabelStyle);
30+
31+
List<IAppearanceChange> getResetLabelAppearanceChange(String labelId, Set<String> previousCustomizedStyleProperties, LabelStyle previousLabelStyle);
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025, 2026 Obeo.
3+
* This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v2.0
5+
* which accompanies this distribution, and is available at
6+
* https://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*
10+
* Contributors:
11+
* Obeo - initial API and implementation
12+
*******************************************************************************/
13+
package org.eclipse.sirius.web.application.undo.services.api;
14+
15+
import org.eclipse.sirius.components.diagrams.IDiagramElement;
16+
import org.eclipse.sirius.components.diagrams.events.appearance.IAppearanceChange;
17+
import org.eclipse.sirius.components.diagrams.events.appearance.label.ILabelAppearanceChange;
18+
19+
import java.util.List;
20+
import java.util.Optional;
21+
22+
/**
23+
* Use to compute undo label appearance change.
24+
*
25+
* @author mcharfadi
26+
*/
27+
public interface ILabelAppearanceChangeUndoRecorder {
28+
29+
boolean canHandle(IDiagramElement diagramElement);
30+
31+
List<IAppearanceChange> computeUndoLabelAppearanceChanges(IDiagramElement diagramElement, String labelId, Optional<ILabelAppearanceChange> change);
32+
33+
}

packages/sirius-web/backend/sirius-web-application/src/main/java/org/eclipse/sirius/web/application/undo/services/api/INodeAppearanceChangeUndoRecorder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2025 Obeo.
2+
* Copyright (c) 2025, 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
@@ -20,7 +20,7 @@
2020
import java.util.Optional;
2121

2222
/**
23-
* Use to compute undo appearance change.
23+
* Use to compute undo node appearance change.
2424
*
2525
* @author mcharfadi
2626
*/

0 commit comments

Comments
 (0)