Skip to content

Commit

Permalink
[672] Add support for a ViewDeletionRequest
Browse files Browse the repository at this point in the history
Bug: #672
Signed-off-by: Hugo Marchadour <[email protected]>
  • Loading branch information
Hugo Marchadour authored and sbegaudeau committed Sep 22, 2021
1 parent 62f1b19 commit 53c32ad
Show file tree
Hide file tree
Showing 13 changed files with 304 additions and 69 deletions.
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -38,6 +39,8 @@ public final class DiagramComponentProps implements IProps {

private List<ViewCreationRequest> viewCreationRequests;

private List<ViewDeletionRequest> viewDeletionRequests;

private DiagramComponentProps() {
// Prevent instantiation
}
Expand All @@ -58,6 +61,10 @@ public List<ViewCreationRequest> getViewCreationRequests() {
return this.viewCreationRequests;
}

public List<ViewDeletionRequest> getViewDeletionRequests() {
return this.viewDeletionRequests;
}

public static Builder newDiagramComponentProps() {
return new Builder();
}
Expand All @@ -77,6 +84,8 @@ public static final class Builder {

private List<ViewCreationRequest> viewCreationRequests;

private List<ViewDeletionRequest> viewDeletionRequests;

public Builder variableManager(VariableManager variableManager) {
this.variableManager = Objects.requireNonNull(variableManager);
return this;
Expand All @@ -97,12 +106,18 @@ public Builder viewCreationRequests(List<ViewCreationRequest> viewCreationReques
return this;
}

public Builder viewDeletionRequests(List<ViewDeletionRequest> 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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,12 @@ private boolean shouldRender(String targetObjectId, Optional<Node> 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;
}
Expand All @@ -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<Node> optionalPreviousNode) {
NodeDescription nodeDescription = this.props.getNodeDescription();
NodeContainmentKind containmentKind = this.props.getContainmentKind();
Expand Down Expand Up @@ -216,6 +228,7 @@ private List<Element> getBorderNodes(Optional<Node> optionalPreviousNode, Variab
.containmentKind(NodeContainmentKind.BORDER_NODE)
.cache(cache)
.viewCreationRequests(this.props.getViewCreationRequests())
.viewDeletionRequests(this.props.getViewDeletionRequests())
.parentElementId(nodeId)
.build();
//@formatter:on
Expand All @@ -238,6 +251,7 @@ private List<Element> getChildNodes(Optional<Node> optionalPreviousNode, Variabl
.containmentKind(NodeContainmentKind.CHILD_NODE)
.cache(cache)
.viewCreationRequests(this.props.getViewCreationRequests())
.viewDeletionRequests(this.props.getViewDeletionRequests())
.parentElementId(nodeId)
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -43,6 +44,8 @@ public final class NodeComponentProps implements IProps {

private List<ViewCreationRequest> viewCreationRequests;

private List<ViewDeletionRequest> viewDeletionRequests;

private UUID parentElementId;

private NodeComponentProps() {
Expand Down Expand Up @@ -73,6 +76,10 @@ public List<ViewCreationRequest> getViewCreationRequests() {
return this.viewCreationRequests;
}

public List<ViewDeletionRequest> getViewDeletionRequests() {
return this.viewDeletionRequests;
}

public UUID getParentElementId() {
return this.parentElementId;
}
Expand Down Expand Up @@ -100,6 +107,8 @@ public static final class Builder {

private List<ViewCreationRequest> viewCreationRequests;

private List<ViewDeletionRequest> viewDeletionRequests;

private UUID parentElementId;

public Builder variableManager(VariableManager variableManager) {
Expand Down Expand Up @@ -132,6 +141,11 @@ public Builder viewCreationRequests(List<ViewCreationRequest> viewCreationReques
return this;
}

public Builder viewDeletionRequests(List<ViewDeletionRequest> viewDeletionRequests) {
this.viewDeletionRequests = Objects.requireNonNull(viewDeletionRequests);
return this;
}

public Builder parentElementId(UUID parentElementId) {
this.parentElementId = Objects.requireNonNull(parentElementId);
return this;
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ private Diagram renderDiagram(List<NodeDescription> nodeDescriptions, List<EdgeD
.variableManager(variableManager)
.diagramDescription(diagramDescription)
.viewCreationRequests(List.of())
.viewDeletionRequests(List.of())
.previousDiagram(Optional.empty())
.build();
// @formatter:on
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ private Diagram createDiagram(Function<VariableManager, INodeStyle> styleProvide
.variableManager(variableManager)
.diagramDescription(diagramDescription)
.viewCreationRequests(List.of())
.viewDeletionRequests(List.of())
.previousDiagram(previousDiagram)
.build();
// @formatter:on
Expand Down
Loading

0 comments on commit 53c32ad

Please sign in to comment.