diff --git a/backend/sirius-web-diagrams/src/main/java/org/eclipse/sirius/web/diagrams/ViewDeletionRequest.java b/backend/sirius-web-diagrams/src/main/java/org/eclipse/sirius/web/diagrams/ViewDeletionRequest.java new file mode 100644 index 00000000000..51989e02403 --- /dev/null +++ b/backend/sirius-web-diagrams/src/main/java/org/eclipse/sirius/web/diagrams/ViewDeletionRequest.java @@ -0,0 +1,74 @@ +/******************************************************************************* + * Copyright (c) 2021 Obeo. + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Obeo - initial API and implementation + *******************************************************************************/ +package org.eclipse.sirius.web.diagrams; + +import java.text.MessageFormat; +import java.util.Objects; +import java.util.UUID; + +import org.eclipse.sirius.web.annotations.Immutable; + +/** + * A view deletion request. + * + * @author hmarchadour + */ +@Immutable +public final class ViewDeletionRequest { + + private UUID elementId; + + private ViewDeletionRequest() { + // Prevent instantiation + } + + public UUID getElementId() { + return this.elementId; + } + + public static Builder newViewDeletionRequest() { + return new Builder(); + } + + @Override + public String toString() { + String pattern = "{0} '{'elementId: {1}'}'"; //$NON-NLS-1$ + return MessageFormat.format(pattern, this.getClass().getSimpleName(), this.elementId); + } + + /** + * The builder used to create a new {@link ViewDeletionRequest}. + * + * @author hmarchadour + */ + @SuppressWarnings("checkstyle:HiddenField") + public static final class Builder { + + private UUID elementId; + + private Builder() { + // Prevent instantiation + } + + public Builder elementId(UUID elementId) { + this.elementId = Objects.requireNonNull(elementId); + return this; + } + + public ViewDeletionRequest build() { + ViewDeletionRequest viewDeletionRequest = new ViewDeletionRequest(); + viewDeletionRequest.elementId = Objects.requireNonNull(this.elementId); + return viewDeletionRequest; + } + } +} diff --git a/backend/sirius-web-diagrams/src/main/java/org/eclipse/sirius/web/diagrams/components/DiagramComponent.java b/backend/sirius-web-diagrams/src/main/java/org/eclipse/sirius/web/diagrams/components/DiagramComponent.java index 241acfdd275..26a23d1920c 100644 --- a/backend/sirius-web-diagrams/src/main/java/org/eclipse/sirius/web/diagrams/components/DiagramComponent.java +++ b/backend/sirius-web-diagrams/src/main/java/org/eclipse/sirius/web/diagrams/components/DiagramComponent.java @@ -67,6 +67,7 @@ public Element render() { .containmentKind(NodeContainmentKind.CHILD_NODE) .cache(cache) .viewCreationRequests(this.props.getViewCreationRequests()) + .viewDeletionRequests(this.props.getViewDeletionRequests()) .parentElementId(diagramId) .build(); return new Element(NodeComponent.class, nodeComponentProps); diff --git a/backend/sirius-web-diagrams/src/main/java/org/eclipse/sirius/web/diagrams/components/DiagramComponentProps.java b/backend/sirius-web-diagrams/src/main/java/org/eclipse/sirius/web/diagrams/components/DiagramComponentProps.java index facfbf22e7d..f6746965361 100644 --- a/backend/sirius-web-diagrams/src/main/java/org/eclipse/sirius/web/diagrams/components/DiagramComponentProps.java +++ b/backend/sirius-web-diagrams/src/main/java/org/eclipse/sirius/web/diagrams/components/DiagramComponentProps.java @@ -20,6 +20,7 @@ import org.eclipse.sirius.web.components.IProps; import org.eclipse.sirius.web.diagrams.Diagram; import org.eclipse.sirius.web.diagrams.ViewCreationRequest; +import org.eclipse.sirius.web.diagrams.ViewDeletionRequest; import org.eclipse.sirius.web.diagrams.description.DiagramDescription; import org.eclipse.sirius.web.representations.VariableManager; @@ -38,6 +39,8 @@ public final class DiagramComponentProps implements IProps { private List viewCreationRequests; + private List viewDeletionRequests; + private DiagramComponentProps() { // Prevent instantiation } @@ -58,6 +61,10 @@ public List getViewCreationRequests() { return this.viewCreationRequests; } + public List getViewDeletionRequests() { + return this.viewDeletionRequests; + } + public static Builder newDiagramComponentProps() { return new Builder(); } @@ -77,6 +84,8 @@ public static final class Builder { private List viewCreationRequests; + private List viewDeletionRequests; + public Builder variableManager(VariableManager variableManager) { this.variableManager = Objects.requireNonNull(variableManager); return this; @@ -97,12 +106,18 @@ public Builder viewCreationRequests(List viewCreationReques return this; } + public Builder viewDeletionRequests(List viewDeletionRequests) { + this.viewDeletionRequests = Objects.requireNonNull(viewDeletionRequests); + return this; + } + public DiagramComponentProps build() { DiagramComponentProps diagramComponentProps = new DiagramComponentProps(); diagramComponentProps.variableManager = Objects.requireNonNull(this.variableManager); diagramComponentProps.diagramDescription = Objects.requireNonNull(this.diagramDescription); diagramComponentProps.previousDiagram = Objects.requireNonNull(this.previousDiagram); diagramComponentProps.viewCreationRequests = List.copyOf(Objects.requireNonNull(this.viewCreationRequests)); + diagramComponentProps.viewDeletionRequests = List.copyOf(Objects.requireNonNull(this.viewDeletionRequests)); return diagramComponentProps; } } diff --git a/backend/sirius-web-diagrams/src/main/java/org/eclipse/sirius/web/diagrams/components/NodeComponent.java b/backend/sirius-web-diagrams/src/main/java/org/eclipse/sirius/web/diagrams/components/NodeComponent.java index 1b3166e7f4a..61f1daad7ce 100644 --- a/backend/sirius-web-diagrams/src/main/java/org/eclipse/sirius/web/diagrams/components/NodeComponent.java +++ b/backend/sirius-web-diagrams/src/main/java/org/eclipse/sirius/web/diagrams/components/NodeComponent.java @@ -89,7 +89,12 @@ private boolean shouldRender(String targetObjectId, Optional optionalPrevi if (synchronizationPolicy == SynchronizationPolicy.SYNCHRONIZED) { shouldRender = true; } else if (synchronizationPolicy == SynchronizationPolicy.UNSYNCHRONIZED) { - shouldRender = optionalPreviousNode.isPresent() || this.existsViewCreationRequested(targetObjectId); + if (optionalPreviousNode.isPresent()) { + Node previousNode = optionalPreviousNode.get(); + shouldRender = !this.existsViewDeletionRequested(previousNode.getId()); + } else { + shouldRender = this.existsViewCreationRequested(targetObjectId); + } } return shouldRender; } @@ -105,6 +110,13 @@ private boolean existsViewCreationRequested(String targetObjectId) { // @formatter:on } + private boolean existsViewDeletionRequested(UUID elementId) { + // @formatter:off + return this.props.getViewDeletionRequests().stream() + .anyMatch(viewDeletionRequest -> Objects.equals(viewDeletionRequest.getElementId(), elementId)); + // @formatter:on + } + private Element doRender(VariableManager nodeVariableManager, String targetObjectId, Optional optionalPreviousNode) { NodeDescription nodeDescription = this.props.getNodeDescription(); NodeContainmentKind containmentKind = this.props.getContainmentKind(); @@ -216,6 +228,7 @@ private List getBorderNodes(Optional optionalPreviousNode, Variab .containmentKind(NodeContainmentKind.BORDER_NODE) .cache(cache) .viewCreationRequests(this.props.getViewCreationRequests()) + .viewDeletionRequests(this.props.getViewDeletionRequests()) .parentElementId(nodeId) .build(); //@formatter:on @@ -238,6 +251,7 @@ private List getChildNodes(Optional optionalPreviousNode, Variabl .containmentKind(NodeContainmentKind.CHILD_NODE) .cache(cache) .viewCreationRequests(this.props.getViewCreationRequests()) + .viewDeletionRequests(this.props.getViewDeletionRequests()) .parentElementId(nodeId) .build(); diff --git a/backend/sirius-web-diagrams/src/main/java/org/eclipse/sirius/web/diagrams/components/NodeComponentProps.java b/backend/sirius-web-diagrams/src/main/java/org/eclipse/sirius/web/diagrams/components/NodeComponentProps.java index 2588ff671e0..60b739667af 100644 --- a/backend/sirius-web-diagrams/src/main/java/org/eclipse/sirius/web/diagrams/components/NodeComponentProps.java +++ b/backend/sirius-web-diagrams/src/main/java/org/eclipse/sirius/web/diagrams/components/NodeComponentProps.java @@ -19,6 +19,7 @@ import org.eclipse.sirius.web.annotations.Immutable; import org.eclipse.sirius.web.components.IProps; import org.eclipse.sirius.web.diagrams.ViewCreationRequest; +import org.eclipse.sirius.web.diagrams.ViewDeletionRequest; import org.eclipse.sirius.web.diagrams.description.NodeDescription; import org.eclipse.sirius.web.diagrams.renderer.DiagramRenderingCache; import org.eclipse.sirius.web.representations.VariableManager; @@ -43,6 +44,8 @@ public final class NodeComponentProps implements IProps { private List viewCreationRequests; + private List viewDeletionRequests; + private UUID parentElementId; private NodeComponentProps() { @@ -73,6 +76,10 @@ public List getViewCreationRequests() { return this.viewCreationRequests; } + public List getViewDeletionRequests() { + return this.viewDeletionRequests; + } + public UUID getParentElementId() { return this.parentElementId; } @@ -100,6 +107,8 @@ public static final class Builder { private List viewCreationRequests; + private List viewDeletionRequests; + private UUID parentElementId; public Builder variableManager(VariableManager variableManager) { @@ -132,6 +141,11 @@ public Builder viewCreationRequests(List viewCreationReques return this; } + public Builder viewDeletionRequests(List viewDeletionRequests) { + this.viewDeletionRequests = Objects.requireNonNull(viewDeletionRequests); + return this; + } + public Builder parentElementId(UUID parentElementId) { this.parentElementId = Objects.requireNonNull(parentElementId); return this; @@ -145,6 +159,7 @@ public NodeComponentProps build() { nodeComponentProps.containmentKind = Objects.requireNonNull(this.containmentKind); nodeComponentProps.cache = Objects.requireNonNull(this.cache); nodeComponentProps.viewCreationRequests = Objects.requireNonNull(this.viewCreationRequests); + nodeComponentProps.viewDeletionRequests = Objects.requireNonNull(this.viewDeletionRequests); nodeComponentProps.parentElementId = Objects.requireNonNull(this.parentElementId); return nodeComponentProps; } diff --git a/backend/sirius-web-diagrams/src/test/java/org/eclipse/sirius/web/diagrams/renderer/DiagramRendererEdgeTests.java b/backend/sirius-web-diagrams/src/test/java/org/eclipse/sirius/web/diagrams/renderer/DiagramRendererEdgeTests.java index 5dbcfbcf43f..004e127bc44 100644 --- a/backend/sirius-web-diagrams/src/test/java/org/eclipse/sirius/web/diagrams/renderer/DiagramRendererEdgeTests.java +++ b/backend/sirius-web-diagrams/src/test/java/org/eclipse/sirius/web/diagrams/renderer/DiagramRendererEdgeTests.java @@ -153,6 +153,7 @@ private Diagram renderDiagram(List nodeDescriptions, List styleProvide .variableManager(variableManager) .diagramDescription(diagramDescription) .viewCreationRequests(List.of()) + .viewDeletionRequests(List.of()) .previousDiagram(previousDiagram) .build(); // @formatter:on diff --git a/backend/sirius-web-diagrams/src/test/java/org/eclipse/sirius/web/diagrams/renderer/UnsynchronizedDiagramTests.java b/backend/sirius-web-diagrams/src/test/java/org/eclipse/sirius/web/diagrams/renderer/UnsynchronizedDiagramTests.java index 8e296e5819b..c2e81146486 100644 --- a/backend/sirius-web-diagrams/src/test/java/org/eclipse/sirius/web/diagrams/renderer/UnsynchronizedDiagramTests.java +++ b/backend/sirius-web-diagrams/src/test/java/org/eclipse/sirius/web/diagrams/renderer/UnsynchronizedDiagramTests.java @@ -28,6 +28,7 @@ import org.eclipse.sirius.web.diagrams.RectangularNodeStyle; import org.eclipse.sirius.web.diagrams.Size; import org.eclipse.sirius.web.diagrams.ViewCreationRequest; +import org.eclipse.sirius.web.diagrams.ViewDeletionRequest; import org.eclipse.sirius.web.diagrams.components.DiagramComponent; import org.eclipse.sirius.web.diagrams.components.DiagramComponentProps; import org.eclipse.sirius.web.diagrams.description.DiagramDescription; @@ -50,6 +51,27 @@ public class UnsynchronizedDiagramTests { private static final String TARGET_OBJECT_ID = "targetObjectId"; //$NON-NLS-1$ + /** + * This very simple test will validate that we can render synchronized diagram elements. We will use a diagram + * description containing one synchronized node description and one unsynchronized node description. We will test + * the following sequence of events: + * + *
    + *
  • render the diagram from scratch: only the synchronized element should appear
  • + *
  • refresh the diagram: nothing should change
  • + *
+ */ + @Test + public void testRenderingOnRoot() { + DiagramDescription diagramDescription = this.getDiagramDescription(); + + Diagram initialDiagram = this.render(diagramDescription, List.of(), List.of(), Optional.empty()); + assertThat(initialDiagram.getNodes()).hasSize(1); + + Diagram refreshedDiagram = this.render(diagramDescription, List.of(), List.of(), Optional.of(initialDiagram)); + assertThat(refreshedDiagram.getNodes()).hasSize(1); + } + /** * This very simple test will validate that we can render synchronized and unsynchronized diagram elements. We will * use a diagram description containing one synchronized node description and one unsynchronized node description. @@ -57,7 +79,6 @@ public class UnsynchronizedDiagramTests { * *
    *
  • render the diagram from scratch: only the synchronized element should appear
  • - *
  • refresh the diagram: nothing should change
  • *
  • create a ViewCreationRequest on a node and refresh this new diagram: two nodes should be visible, the * synchronized one and the unsynchronized one
  • *
@@ -66,23 +87,59 @@ public class UnsynchronizedDiagramTests { public void testUnsynchronizedRenderingOnRoot() { DiagramDescription diagramDescription = this.getDiagramDescription(); - Diagram initialDiagram = this.render(diagramDescription, List.of(), Optional.empty()); - assertThat(initialDiagram.getNodes()).hasSize(1); - - Diagram refreshedDiagram = this.render(diagramDescription, List.of(), Optional.of(initialDiagram)); - assertThat(refreshedDiagram.getNodes()).hasSize(1); + Diagram initialDiagram = this.render(diagramDescription, List.of(), List.of(), Optional.empty()); // @formatter:off ViewCreationRequest viewCreationRequest = ViewCreationRequest.newViewCreationRequest() .descriptionId(diagramDescription.getNodeDescriptions().get(0).getId()) - .parentElementId(refreshedDiagram.getId()) + .parentElementId(initialDiagram.getId()) .targetObjectId(TARGET_OBJECT_ID) .build(); // @formatter:on - Diagram refreshedDiagramAfterNodeCreation = this.render(diagramDescription, List.of(viewCreationRequest), Optional.of(refreshedDiagram)); + Diagram refreshedDiagramAfterNodeCreation = this.render(diagramDescription, List.of(viewCreationRequest), List.of(), Optional.of(initialDiagram)); assertThat(refreshedDiagramAfterNodeCreation.getNodes()).hasSize(2); } + /** + * This very simple test will validate that we can render synchronized and unsynchronized diagram elements. We will + * use a diagram description containing one synchronized node description and one unsynchronized node description. + * We will test the following sequence of events: + * + *
    + *
  • render the diagram from scratch: only the synchronized element should appear
  • + *
  • create a ViewCreationRequest on a node and refresh this new diagram: two nodes should be visible, the + * synchronized one and the unsynchronized one
  • + *
  • create a ViewDeletionRequest on a node and refresh this new diagram: one node should be visible, the + * synchronized one
  • + *
+ */ + @Test + public void testUnsynchronizedRenderingOnRootAfterDeletion() { + DiagramDescription diagramDescription = this.getDiagramDescription(); + + Diagram initialDiagram = this.render(diagramDescription, List.of(), List.of(), Optional.empty()); + + // @formatter:off + ViewCreationRequest viewCreationRequest = ViewCreationRequest.newViewCreationRequest() + .descriptionId(diagramDescription.getNodeDescriptions().get(0).getId()) + .parentElementId(initialDiagram.getId()) + .targetObjectId(TARGET_OBJECT_ID) + .build(); + // @formatter:on + Diagram refreshedDiagramAfterNodeCreation = this.render(diagramDescription, List.of(viewCreationRequest), List.of(), Optional.of(initialDiagram)); + + UUID nodeIdToDelete = refreshedDiagramAfterNodeCreation.getNodes().get(0).getId(); + + // @formatter:off + ViewDeletionRequest viewDeletionRequest = ViewDeletionRequest.newViewDeletionRequest() + .elementId(nodeIdToDelete) + .build(); + // @formatter:on + Diagram refreshedDiagramAfterNodeDeletion = this.render(diagramDescription, List.of(), List.of(viewDeletionRequest), Optional.of(refreshedDiagramAfterNodeCreation)); + assertThat(refreshedDiagramAfterNodeDeletion.getNodes()).hasSize(1); + + } + /** * This very simple test will validate that we can add an unsynchronized node thanks to a ViewCreationRequest on a * node container. We will test the following sequence of events: @@ -97,7 +154,7 @@ public void testUnsynchronizedRenderingOnRoot() { public void testUnsynchronizedRenderingOnNodeContainer() { DiagramDescription diagramDescription = this.getDiagramDescription(); - Diagram initialDiagram = this.render(diagramDescription, List.of(), Optional.empty()); + Diagram initialDiagram = this.render(diagramDescription, List.of(), List.of(), Optional.empty()); // @formatter:off ViewCreationRequest viewCreationRequest = ViewCreationRequest.newViewCreationRequest() .descriptionId(diagramDescription.getNodeDescriptions().get(0).getId()) @@ -105,7 +162,7 @@ public void testUnsynchronizedRenderingOnNodeContainer() { .targetObjectId(TARGET_OBJECT_ID) .build(); // @formatter:on - Diagram diagramAfterFirstNodeCreation = this.render(diagramDescription, List.of(viewCreationRequest), Optional.of(initialDiagram)); + Diagram diagramAfterFirstNodeCreation = this.render(diagramDescription, List.of(viewCreationRequest), List.of(), Optional.of(initialDiagram)); UUID descriptionId = diagramDescription.getNodeDescriptions().get(0).getChildNodeDescriptions().get(0).getId(); UUID parentNodeId = diagramAfterFirstNodeCreation.getNodes().get(0).getId(); // @formatter:off @@ -115,7 +172,7 @@ public void testUnsynchronizedRenderingOnNodeContainer() { .targetObjectId(TARGET_OBJECT_ID) .build(); // @formatter:on - Diagram diagramAfterSecondNodeCreation = this.render(diagramDescription, List.of(childViewCreationRequest), Optional.of(diagramAfterFirstNodeCreation)); + Diagram diagramAfterSecondNodeCreation = this.render(diagramDescription, List.of(childViewCreationRequest), List.of(), Optional.of(diagramAfterFirstNodeCreation)); assertThat(diagramAfterSecondNodeCreation.getNodes()).hasSize(2); Node firstRootNode = diagramAfterSecondNodeCreation.getNodes().get(0); @@ -127,13 +184,67 @@ public void testUnsynchronizedRenderingOnNodeContainer() { assertThat(secondRootNode.getChildNodes()).isEmpty(); } - private Diagram render(DiagramDescription diagramDescription, List viewCreationRequests, Optional optionalPreviousDiagram) { + /** + * This very simple test will validate that we can add and remove an unsynchronized node thanks to a + * ViewCreationRequest/ViewDeletionRequest on a node container. We will test the following sequence of events: + * + *
    + *
  • render the diagram with two nodes (the first is unsynchronized, the second is synchronized)
  • + *
  • create a new node thanks to a ViewCreationRequest during a refresh diagram
  • + *
  • delete the node thanks to a ViewDeletionRequest during a refresh diagram: no child nodes should be visible on + * the first unsynchronized node children
  • + *
+ */ + @Test + public void testUnsynchronizedRenderingOnNodeContainerAfterDeletion() { + DiagramDescription diagramDescription = this.getDiagramDescription(); + + Diagram initialDiagram = this.render(diagramDescription, List.of(), List.of(), Optional.empty()); + // @formatter:off + ViewCreationRequest viewCreationRequest = ViewCreationRequest.newViewCreationRequest() + .descriptionId(diagramDescription.getNodeDescriptions().get(0).getId()) + .parentElementId(initialDiagram.getId()) + .targetObjectId(TARGET_OBJECT_ID) + .build(); + // @formatter:on + Diagram diagramAfterFirstNodeCreation = this.render(diagramDescription, List.of(viewCreationRequest), List.of(), Optional.of(initialDiagram)); + UUID descriptionId = diagramDescription.getNodeDescriptions().get(0).getChildNodeDescriptions().get(0).getId(); + UUID parentNodeId = diagramAfterFirstNodeCreation.getNodes().get(0).getId(); + // @formatter:off + ViewCreationRequest childViewCreationRequest = ViewCreationRequest.newViewCreationRequest() + .descriptionId(descriptionId) + .parentElementId(parentNodeId) + .targetObjectId(TARGET_OBJECT_ID) + .build(); + // @formatter:on + Diagram diagramAfterSecondNodeCreation = this.render(diagramDescription, List.of(childViewCreationRequest), List.of(), Optional.of(diagramAfterFirstNodeCreation)); + UUID nodeIdToDelete = diagramAfterSecondNodeCreation.getNodes().get(0).getChildNodes().get(0).getId(); + // @formatter:off + ViewDeletionRequest viewDeletionRequest = ViewDeletionRequest.newViewDeletionRequest() + .elementId(nodeIdToDelete) + .build(); + // @formatter:on + Diagram diagramAfterSecondNodeDeletion = this.render(diagramDescription, List.of(), List.of(viewDeletionRequest), Optional.of(diagramAfterFirstNodeCreation)); + + assertThat(diagramAfterSecondNodeDeletion.getNodes()).hasSize(2); + Node firstRootNode = diagramAfterSecondNodeDeletion.getNodes().get(0); + assertThat(firstRootNode.getBorderNodes()).isEmpty(); + assertThat(firstRootNode.getChildNodes()).isEmpty(); + + Node secondRootNode = diagramAfterSecondNodeCreation.getNodes().get(1); + assertThat(secondRootNode.getBorderNodes()).isEmpty(); + assertThat(secondRootNode.getChildNodes()).isEmpty(); + } + + private Diagram render(DiagramDescription diagramDescription, List viewCreationRequests, List viewDeletionRequests, + Optional optionalPreviousDiagram) { VariableManager variableManager = new VariableManager(); // @formatter:off DiagramComponentProps props = DiagramComponentProps.newDiagramComponentProps() .variableManager(variableManager) .diagramDescription(diagramDescription) .viewCreationRequests(viewCreationRequests) + .viewDeletionRequests(viewDeletionRequests) .previousDiagram(optionalPreviousDiagram) .build(); // @formatter:on diff --git a/backend/sirius-web-spring-collaborative-diagrams/src/main/java/org/eclipse/sirius/web/spring/collaborative/diagrams/DiagramContext.java b/backend/sirius-web-spring-collaborative-diagrams/src/main/java/org/eclipse/sirius/web/spring/collaborative/diagrams/DiagramContext.java index 780986f0717..31dd535fe5d 100644 --- a/backend/sirius-web-spring-collaborative-diagrams/src/main/java/org/eclipse/sirius/web/spring/collaborative/diagrams/DiagramContext.java +++ b/backend/sirius-web-spring-collaborative-diagrams/src/main/java/org/eclipse/sirius/web/spring/collaborative/diagrams/DiagramContext.java @@ -18,6 +18,7 @@ import org.eclipse.sirius.web.diagrams.Diagram; import org.eclipse.sirius.web.diagrams.ViewCreationRequest; +import org.eclipse.sirius.web.diagrams.ViewDeletionRequest; import org.eclipse.sirius.web.diagrams.events.IDiagramEvent; import org.eclipse.sirius.web.spring.collaborative.diagrams.api.IDiagramContext; @@ -32,11 +33,14 @@ public class DiagramContext implements IDiagramContext { private final List viewCreationRequests; + private final List viewDeletionRequests; + private IDiagramEvent diagramEvent; public DiagramContext(Diagram initialDiagram) { this.diagram = Objects.requireNonNull(initialDiagram); this.viewCreationRequests = new ArrayList<>(); + this.viewDeletionRequests = new ArrayList<>(); } @Override @@ -54,6 +58,11 @@ public List getViewCreationRequests() { return this.viewCreationRequests; } + @Override + public List getViewDeletionRequests() { + return this.viewDeletionRequests; + } + @Override public IDiagramEvent getDiagramEvent() { return this.diagramEvent; @@ -67,5 +76,7 @@ public void setDiagramEvent(IDiagramEvent diagramEvent) { @Override public void reset() { this.diagramEvent = null; + this.viewCreationRequests.clear(); + this.viewDeletionRequests.clear(); } } diff --git a/backend/sirius-web-spring-collaborative-diagrams/src/main/java/org/eclipse/sirius/web/spring/collaborative/diagrams/DiagramCreationService.java b/backend/sirius-web-spring-collaborative-diagrams/src/main/java/org/eclipse/sirius/web/spring/collaborative/diagrams/DiagramCreationService.java index 96b6bad7b48..9f9ed11f78e 100644 --- a/backend/sirius-web-spring-collaborative-diagrams/src/main/java/org/eclipse/sirius/web/spring/collaborative/diagrams/DiagramCreationService.java +++ b/backend/sirius-web-spring-collaborative-diagrams/src/main/java/org/eclipse/sirius/web/spring/collaborative/diagrams/DiagramCreationService.java @@ -23,6 +23,7 @@ import org.eclipse.sirius.web.core.api.IRepresentationDescriptionSearchService; import org.eclipse.sirius.web.diagrams.Diagram; import org.eclipse.sirius.web.diagrams.ViewCreationRequest; +import org.eclipse.sirius.web.diagrams.ViewDeletionRequest; import org.eclipse.sirius.web.diagrams.components.DiagramComponent; import org.eclipse.sirius.web.diagrams.components.DiagramComponentProps; import org.eclipse.sirius.web.diagrams.components.DiagramComponentProps.Builder; @@ -108,12 +109,14 @@ private Diagram doRender(String label, Object targetObject, IEditingContext edit Optional optionalDiagramElementEvent = optionalDiagramContext.map(IDiagramContext::getDiagramEvent); Optional optionalPreviousDiagram = optionalDiagramContext.map(IDiagramContext::getDiagram); List viewCreationRequests = optionalDiagramContext.map(IDiagramContext::getViewCreationRequests).orElse(List.of()); + List viewDeletionRequests = optionalDiagramContext.map(IDiagramContext::getViewDeletionRequests).orElse(List.of()); //@formatter:off Builder builder = DiagramComponentProps.newDiagramComponentProps() .variableManager(variableManager) .diagramDescription(diagramDescription) .viewCreationRequests(viewCreationRequests) + .viewDeletionRequests(viewDeletionRequests) .previousDiagram(optionalPreviousDiagram); //@formatter:on diff --git a/backend/sirius-web-spring-collaborative-diagrams/src/main/java/org/eclipse/sirius/web/spring/collaborative/diagrams/api/IDiagramContext.java b/backend/sirius-web-spring-collaborative-diagrams/src/main/java/org/eclipse/sirius/web/spring/collaborative/diagrams/api/IDiagramContext.java index 4b114f0e860..95912d19e01 100644 --- a/backend/sirius-web-spring-collaborative-diagrams/src/main/java/org/eclipse/sirius/web/spring/collaborative/diagrams/api/IDiagramContext.java +++ b/backend/sirius-web-spring-collaborative-diagrams/src/main/java/org/eclipse/sirius/web/spring/collaborative/diagrams/api/IDiagramContext.java @@ -16,6 +16,7 @@ import org.eclipse.sirius.web.diagrams.Diagram; import org.eclipse.sirius.web.diagrams.ViewCreationRequest; +import org.eclipse.sirius.web.diagrams.ViewDeletionRequest; import org.eclipse.sirius.web.diagrams.events.IDiagramEvent; /** @@ -38,6 +39,8 @@ public interface IDiagramContext { List getViewCreationRequests(); + List getViewDeletionRequests(); + IDiagramEvent getDiagramEvent(); void setDiagramEvent(IDiagramEvent diagramElementEvent); diff --git a/backend/sirius-web-spring-collaborative-diagrams/src/test/java/org/eclipse/sirius/web/spring/collaborative/diagrams/handlers/NoOpDiagramContext.java b/backend/sirius-web-spring-collaborative-diagrams/src/test/java/org/eclipse/sirius/web/spring/collaborative/diagrams/handlers/NoOpDiagramContext.java index 6032596d7a0..229060f5f32 100644 --- a/backend/sirius-web-spring-collaborative-diagrams/src/test/java/org/eclipse/sirius/web/spring/collaborative/diagrams/handlers/NoOpDiagramContext.java +++ b/backend/sirius-web-spring-collaborative-diagrams/src/test/java/org/eclipse/sirius/web/spring/collaborative/diagrams/handlers/NoOpDiagramContext.java @@ -16,6 +16,7 @@ import org.eclipse.sirius.web.diagrams.Diagram; import org.eclipse.sirius.web.diagrams.ViewCreationRequest; +import org.eclipse.sirius.web.diagrams.ViewDeletionRequest; import org.eclipse.sirius.web.diagrams.events.IDiagramEvent; import org.eclipse.sirius.web.spring.collaborative.diagrams.api.IDiagramContext; @@ -40,6 +41,11 @@ public List getViewCreationRequests() { return List.of(); } + @Override + public List getViewDeletionRequests() { + return List.of(); + } + @Override public void reset() { }