Skip to content

Commit

Permalink
[1397] Add support for reused node descriptions
Browse files Browse the repository at this point in the history
Bug: #1397
Signed-off-by: Stéphane Bégaudeau <[email protected]>
  • Loading branch information
sbegaudeau committed Oct 12, 2022
1 parent 8ee526e commit 2c6eb1a
Show file tree
Hide file tree
Showing 22 changed files with 382 additions and 35 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

- https://github.com/eclipse-sirius/sirius-components/issues/1316[#1316] [diagram] Support parametric svg node style
- https://github.com/eclipse-sirius/sirius-components/issues/997[#997] [diagram] Add support for edition of routing points in diagrams
- https://github.com/eclipse-sirius/sirius-components/issues/1397[1397] [diagram] Add support for reused node descriptions


== v2022.9.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public Element render() {
DiagramRenderingCache cache = new DiagramRenderingCache();

IDiagramElementRequestor diagramElementRequestor = new DiagramElementRequestor();
INodeDescriptionRequestor nodeDescriptionRequestor = new NodeDescriptionRequestor(diagramDescription);
// @formatter:off
var nodes = diagramDescription.getNodeDescriptions().stream()
.map(nodeDescription -> {
Expand All @@ -65,6 +66,7 @@ public Element render() {
.variableManager(variableManager)
.nodeDescription(nodeDescription)
.nodesRequestor(nodesRequestor)
.nodeDescriptionRequestor(nodeDescriptionRequestor)
.containmentKind(NodeContainmentKind.CHILD_NODE)
.cache(cache)
.viewCreationRequests(this.props.getViewCreationRequests())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*******************************************************************************
* Copyright (c) 2022 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.components.diagrams.components;

import java.util.Optional;
import java.util.UUID;

import org.eclipse.sirius.components.diagrams.description.NodeDescription;

/**
* Used to find some node descriptions.
*
* @author sbegaudeau
*/
public interface INodeDescriptionRequestor {
Optional<NodeDescription> findById(UUID nodeDescriptionId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ private boolean existsViewDeletionRequested(String elementId) {
private Element doRender(VariableManager nodeVariableManager, String targetObjectId, Optional<Node> optionalPreviousNode) {
NodeDescription nodeDescription = this.props.getNodeDescription();
NodeContainmentKind containmentKind = this.props.getContainmentKind();
INodeDescriptionRequestor nodeDescriptionRequestor = this.props.getNodeDescriptionRequestor();

String nodeId = optionalPreviousNode.map(Node::getId).orElseGet(() -> this.computeNodeId(targetObjectId));
Optional<Label> optionalPreviousLabel = optionalPreviousNode.map(Node::getLabel);
Expand All @@ -152,8 +153,8 @@ private Element doRender(VariableManager nodeVariableManager, String targetObjec

ILayoutStrategy layoutStrategy = nodeDescription.getChildrenLayoutStrategyProvider().apply(nodeVariableManager);

var borderNodes = this.getBorderNodes(optionalPreviousNode, nodeVariableManager, nodeId);
var childNodes = this.getChildNodes(optionalPreviousNode, nodeVariableManager, nodeId);
var borderNodes = this.getBorderNodes(optionalPreviousNode, nodeVariableManager, nodeId, nodeDescriptionRequestor);
var childNodes = this.getChildNodes(optionalPreviousNode, nodeVariableManager, nodeId, nodeDescriptionRequestor);

LabelDescription labelDescription = nodeDescription.getLabelDescription();
nodeVariableManager.put(LabelDescription.OWNER_ID, nodeId);
Expand Down Expand Up @@ -242,44 +243,58 @@ private Size getSize(Optional<Node> optionalPreviousNode, NodeDescription nodeDe
return size;
}

private List<Element> getBorderNodes(Optional<Node> optionalPreviousNode, VariableManager nodeVariableManager, String nodeId) {
private List<Element> getBorderNodes(Optional<Node> optionalPreviousNode, VariableManager nodeVariableManager, String nodeId, INodeDescriptionRequestor nodeDescriptionRequestor) {
NodeDescription nodeDescription = this.props.getNodeDescription();
DiagramRenderingCache cache = this.props.getCache();

return nodeDescription.getBorderNodeDescriptions().stream().map(borderNodeDescription -> {
//@formatter:off
var borderNodeDescriptions = new ArrayList<>(nodeDescription.getBorderNodeDescriptions());
nodeDescription.getReusedBorderNodeDescriptionIds().stream()
.map(nodeDescriptionRequestor::findById)
.flatMap(Optional::stream)
.forEach(borderNodeDescriptions::add);

return borderNodeDescriptions.stream().map(borderNodeDescription -> {
List<Node> previousBorderNodes = optionalPreviousNode.map(previousNode -> new DiagramElementRequestor().getBorderNodes(previousNode, borderNodeDescription)).orElse(List.of());
List<String> previousBorderNodesTargetObjectIds = previousBorderNodes.stream().map(node -> node.getTargetObjectId()).collect(Collectors.toList());
INodesRequestor borderNodesRequestor = new NodesRequestor(previousBorderNodes);
//@formatter:off
var nodeComponentProps = NodeComponentProps.newNodeComponentProps()
.variableManager(nodeVariableManager)
.nodeDescription(borderNodeDescription)
.nodesRequestor(borderNodesRequestor)
.nodeDescriptionRequestor(nodeDescriptionRequestor)
.containmentKind(NodeContainmentKind.BORDER_NODE)
.cache(cache)
.viewCreationRequests(this.props.getViewCreationRequests())
.viewDeletionRequests(this.props.getViewDeletionRequests())
.parentElementId(nodeId)
.previousTargetObjectIds(previousBorderNodesTargetObjectIds)
.build();
//@formatter:on
return new Element(NodeComponent.class, nodeComponentProps);
}).collect(Collectors.toList());
//@formatter:on
}

private List<Element> getChildNodes(Optional<Node> optionalPreviousNode, VariableManager nodeVariableManager, String nodeId) {
private List<Element> getChildNodes(Optional<Node> optionalPreviousNode, VariableManager nodeVariableManager, String nodeId, INodeDescriptionRequestor nodeDescriptionRequestor) {
NodeDescription nodeDescription = this.props.getNodeDescription();
DiagramRenderingCache cache = this.props.getCache();

//@formatter:off
return nodeDescription.getChildNodeDescriptions().stream().map(childNodeDescription -> {
var childNodeDescriptions = new ArrayList<>(nodeDescription.getChildNodeDescriptions());
nodeDescription.getReusedChildNodeDescriptionIds().stream()
.map(nodeDescriptionRequestor::findById)
.flatMap(Optional::stream)
.forEach(childNodeDescriptions::add);

return childNodeDescriptions.stream().map(childNodeDescription -> {
List<Node> previousChildNodes = optionalPreviousNode.map(previousNode -> new DiagramElementRequestor().getChildNodes(previousNode, childNodeDescription)).orElse(List.of());
List<String> previousChildNodesTargetObjectIds = previousChildNodes.stream().map(node -> node.getTargetObjectId()).collect(Collectors.toList());
INodesRequestor childNodesRequestor = new NodesRequestor(previousChildNodes);
var nodeComponentProps = NodeComponentProps.newNodeComponentProps()
.variableManager(nodeVariableManager)
.nodeDescription(childNodeDescription)
.nodesRequestor(childNodesRequestor)
.nodeDescriptionRequestor(nodeDescriptionRequestor)
.containmentKind(NodeContainmentKind.CHILD_NODE)
.cache(cache)
.viewCreationRequests(this.props.getViewCreationRequests())
Expand All @@ -288,9 +303,9 @@ private List<Element> getChildNodes(Optional<Node> optionalPreviousNode, Variabl
.previousTargetObjectIds(previousChildNodesTargetObjectIds)
.build();

// @formatter:on
return new Element(NodeComponent.class, nodeComponentProps);
}).collect(Collectors.toList());
// @formatter:on
}

private String computeNodeId(String targetObjectId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public final class NodeComponentProps implements IProps {

private INodesRequestor nodesRequestor;

private INodeDescriptionRequestor nodeDescriptionRequestor;

private NodeContainmentKind containmentKind;

private DiagramRenderingCache cache;
Expand Down Expand Up @@ -65,6 +67,10 @@ public INodesRequestor getNodesRequestor() {
return this.nodesRequestor;
}

public INodeDescriptionRequestor getNodeDescriptionRequestor() {
return this.nodeDescriptionRequestor;
}

public NodeContainmentKind getContainmentKind() {
return this.containmentKind;
}
Expand Down Expand Up @@ -106,6 +112,8 @@ public static final class Builder {

private INodesRequestor nodesRequestor;

private INodeDescriptionRequestor nodeDescriptionRequestor;

private NodeContainmentKind containmentKind;

private DiagramRenderingCache cache;
Expand Down Expand Up @@ -133,6 +141,11 @@ public Builder nodesRequestor(INodesRequestor nodesRequestor) {
return this;
}

public Builder nodeDescriptionRequestor(INodeDescriptionRequestor nodeDescriptionRequestor) {
this.nodeDescriptionRequestor = Objects.requireNonNull(nodeDescriptionRequestor);
return this;
}

public Builder containmentKind(NodeContainmentKind containmentKind) {
this.containmentKind = Objects.requireNonNull(containmentKind);
return this;
Expand Down Expand Up @@ -168,6 +181,7 @@ public NodeComponentProps build() {
nodeComponentProps.variableManager = Objects.requireNonNull(this.variableManager);
nodeComponentProps.nodeDescription = Objects.requireNonNull(this.nodeDescription);
nodeComponentProps.nodesRequestor = Objects.requireNonNull(this.nodesRequestor);
nodeComponentProps.nodeDescriptionRequestor = Objects.requireNonNull(this.nodeDescriptionRequestor);
nodeComponentProps.containmentKind = Objects.requireNonNull(this.containmentKind);
nodeComponentProps.cache = Objects.requireNonNull(this.cache);
nodeComponentProps.viewCreationRequests = Objects.requireNonNull(this.viewCreationRequests);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*******************************************************************************
* Copyright (c) 2022 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.components.diagrams.components;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;

import org.eclipse.sirius.components.diagrams.description.DiagramDescription;
import org.eclipse.sirius.components.diagrams.description.NodeDescription;

/**
* Find the requested node descriptions.
*
* @author sbegaudeau
*/
public class NodeDescriptionRequestor implements INodeDescriptionRequestor {

private final Map<UUID, NodeDescription> id2nodeDescription = new HashMap<>();

public NodeDescriptionRequestor(DiagramDescription diagramDescription) {
diagramDescription.getNodeDescriptions().forEach(this::cache);
}

private void cache(NodeDescription nodeDescription) {
this.id2nodeDescription.put(nodeDescription.getId(), nodeDescription);
nodeDescription.getBorderNodeDescriptions().forEach(this::cache);
nodeDescription.getChildNodeDescriptions().forEach(this::cache);
}

@Override
public Optional<NodeDescription> findById(UUID nodeDescriptionId) {
return Optional.ofNullable(this.id2nodeDescription.get(nodeDescriptionId));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ public final class NodeDescription {

private List<NodeDescription> borderNodeDescriptions;

private List<NodeDescription> childNodeDescriptions = new ArrayList<>();
private List<NodeDescription> childNodeDescriptions;

private List<UUID> reusedBorderNodeDescriptionIds;

private List<UUID> reusedChildNodeDescriptionIds;

private BiFunction<VariableManager, String, IStatus> labelEditHandler;

Expand Down Expand Up @@ -120,6 +124,14 @@ public List<NodeDescription> getChildNodeDescriptions() {
return this.childNodeDescriptions;
}

public List<UUID> getReusedBorderNodeDescriptionIds() {
return this.reusedBorderNodeDescriptionIds;
}

public List<UUID> getReusedChildNodeDescriptionIds() {
return this.reusedChildNodeDescriptionIds;
}

public Function<VariableManager, IStatus> getDeleteHandler() {
return this.deleteHandler;
}
Expand Down Expand Up @@ -167,9 +179,13 @@ public static final class Builder {

private Function<VariableManager, Size> sizeProvider;

private List<NodeDescription> borderNodeDescriptions;
private List<NodeDescription> borderNodeDescriptions = new ArrayList<>();

private List<NodeDescription> childNodeDescriptions = new ArrayList<>();

private List<NodeDescription> childNodeDescriptions;
private List<UUID> reusedBorderNodeDescriptionIds = new ArrayList<>();

private List<UUID> reusedChildNodeDescriptionIds = new ArrayList<>();

private BiFunction<VariableManager, String, IStatus> labelEditHandler;

Expand Down Expand Up @@ -239,6 +255,16 @@ public Builder childNodeDescriptions(List<NodeDescription> childNodeDescriptions
return this;
}

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

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

public Builder deleteHandler(Function<VariableManager, IStatus> deleteHandler) {
this.deleteHandler = Objects.requireNonNull(deleteHandler);
return this;
Expand All @@ -264,6 +290,8 @@ public NodeDescription build() {
nodeDescription.childrenLayoutStrategyProvider = Objects.requireNonNull(this.childrenLayoutStrategyProvider);
nodeDescription.borderNodeDescriptions = Objects.requireNonNull(this.borderNodeDescriptions);
nodeDescription.childNodeDescriptions = Objects.requireNonNull(this.childNodeDescriptions);
nodeDescription.reusedBorderNodeDescriptionIds = Objects.requireNonNull(this.reusedBorderNodeDescriptionIds);
nodeDescription.reusedChildNodeDescriptionIds = Objects.requireNonNull(this.reusedChildNodeDescriptionIds);
nodeDescription.labelEditHandler = Objects.requireNonNull(this.labelEditHandler);
nodeDescription.deleteHandler = Objects.requireNonNull(this.deleteHandler);
return nodeDescription;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,39 @@ public List<IItemPropertyDescriptor> getPropertyDescriptors(Object object) {
if (this.itemPropertyDescriptors == null) {
super.getPropertyDescriptors(object);

this.addReusedChildNodeDescriptionsPropertyDescriptor(object);
this.addReusedBorderNodeDescriptionsPropertyDescriptor(object);
this.addChildrenLayoutStrategyPropertyDescriptor(object);
}
return this.itemPropertyDescriptors;
}

/**
* This adds a property descriptor for the Reused Child Node Descriptions feature. <!-- begin-user-doc --> <!--
* end-user-doc -->
*
* @generated
*/
protected void addReusedChildNodeDescriptionsPropertyDescriptor(Object object) {
this.itemPropertyDescriptors.add(this.createItemPropertyDescriptor(((ComposeableAdapterFactory) this.adapterFactory).getRootAdapterFactory(), this.getResourceLocator(),
this.getString("_UI_NodeDescription_reusedChildNodeDescriptions_feature"), //$NON-NLS-1$
this.getString("_UI_PropertyDescriptor_description", "_UI_NodeDescription_reusedChildNodeDescriptions_feature", "_UI_NodeDescription_type"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
ViewPackage.Literals.NODE_DESCRIPTION__REUSED_CHILD_NODE_DESCRIPTIONS, true, false, true, null, null, null));
}

/**
* This adds a property descriptor for the Reused Border Node Descriptions feature. <!-- begin-user-doc --> <!--
* end-user-doc -->
*
* @generated
*/
protected void addReusedBorderNodeDescriptionsPropertyDescriptor(Object object) {
this.itemPropertyDescriptors.add(this.createItemPropertyDescriptor(((ComposeableAdapterFactory) this.adapterFactory).getRootAdapterFactory(), this.getResourceLocator(),
this.getString("_UI_NodeDescription_reusedBorderNodeDescriptions_feature"), //$NON-NLS-1$
this.getString("_UI_PropertyDescriptor_description", "_UI_NodeDescription_reusedBorderNodeDescriptions_feature", "_UI_NodeDescription_type"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
ViewPackage.Literals.NODE_DESCRIPTION__REUSED_BORDER_NODE_DESCRIPTIONS, true, false, true, null, null, null));
}

/**
* This adds a property descriptor for the Children Layout Strategy feature. <!-- begin-user-doc --> <!--
* end-user-doc -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ _UI_DiagramElementDescription_labelEditTool_feature = Label Edit Tool
_UI_DiagramElementDescription_synchronizationPolicy_feature = Synchronization Policy
_UI_NodeDescription_childrenDescriptions_feature = Children Descriptions
_UI_NodeDescription_borderNodesDescriptions_feature = Border Nodes Descriptions
_UI_NodeDescription_reusedChildNodeDescriptions_feature = Reused Child Node Descriptions
_UI_NodeDescription_reusedBorderNodeDescriptions_feature = Reused Border Node Descriptions
_UI_NodeDescription_style_feature = Style
_UI_NodeDescription_nodeTools_feature = Node Tools
_UI_NodeDescription_conditionalStyles_feature = Conditional Styles
Expand Down Expand Up @@ -204,7 +206,7 @@ _UI_RadioDescription_style_feature = Style
_UI_RadioDescription_conditionalStyles_feature = Conditional Styles
_UI_BarChartDescription_valuesExpression_feature = Values Expression
_UI_BarChartDescription_keysExpression_feature = Keys Expression
_UI_BarChartDescription_yAxisLabelExpression_feature = Y Axis Label Expression
_UI_BarChartDescription_yAxisLabelExpression_feature = YAxis Label Expression
_UI_BarChartDescription_style_feature = Style
_UI_BarChartDescription_conditionalStyles_feature = Conditional Styles
_UI_PieChartDescription_valuesExpression_feature = Values Expression
Expand Down
Loading

0 comments on commit 2c6eb1a

Please sign in to comment.