From a574cc6ac8695c447dad1ff93333862a778197b3 Mon Sep 17 00:00:00 2001 From: Axel RICHARD Date: Tue, 16 Feb 2021 09:34:32 +0100 Subject: [PATCH] [315] Fix conditional style handling for containers and nodes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In Sirius-Web representations displayed to users, the label of elements with mapping 'MyMapping' should be the one of the conditional style. Some other properties (bold, italic, ...) of the conditional style were not also taking into account. Bug: https://github.com/eclipse-sirius/sirius-components/issues/315 Signed-off-by: Axel RICHARD Signed-off-by: Stéphane Bégaudeau --- .../diagrams/ContainerMappingConverter.java | 48 ++-- .../ContainerMappingStyleProvider.java | 24 +- .../ContainerStyleDescriptionProvider.java | 54 +++++ .../compat/diagrams/EdgeMappingConverter.java | 15 +- .../diagrams/EdgeMappingStyleProvider.java | 23 +- .../EdgeStyleDescriptionProvider.java | 54 +++++ .../LabelStyleDescriptionConverter.java | 1 - .../compat/diagrams/NodeMappingConverter.java | 35 +-- .../diagrams/NodeMappingStyleProvider.java | 24 +- .../NodeStyleDescriptionProvider.java | 55 +++++ .../AllSiriusWebCompatibilityTests.java | 2 + .../BasicLabelStyleDescriptionPopulator.java | 72 ++++++ .../diagrams/MappingConverterTestCases.java | 226 ++++++++++++++++++ .../tests/TestDiagramDescriptionBuilder.java | 4 +- .../diagrams/components/LabelComponent.java | 2 +- .../description/LabelDescription.java | 14 +- .../DiagramRendererEdgeTestCases.java | 4 +- .../DiagramRendererNodeTestCases.java | 4 +- .../UnsynchronizedDiagramTestCases.java | 4 +- .../EdgeMappingConverterTestCases.java | 2 +- 20 files changed, 544 insertions(+), 123 deletions(-) create mode 100644 backend/sirius-web-compatibility/src/main/java/org/eclipse/sirius/web/compat/diagrams/ContainerStyleDescriptionProvider.java create mode 100644 backend/sirius-web-compatibility/src/main/java/org/eclipse/sirius/web/compat/diagrams/EdgeStyleDescriptionProvider.java create mode 100644 backend/sirius-web-compatibility/src/main/java/org/eclipse/sirius/web/compat/diagrams/NodeStyleDescriptionProvider.java create mode 100644 backend/sirius-web-compatibility/src/test/java/org/eclipse/sirius/web/compat/diagrams/BasicLabelStyleDescriptionPopulator.java create mode 100644 backend/sirius-web-compatibility/src/test/java/org/eclipse/sirius/web/compat/diagrams/MappingConverterTestCases.java diff --git a/backend/sirius-web-compatibility/src/main/java/org/eclipse/sirius/web/compat/diagrams/ContainerMappingConverter.java b/backend/sirius-web-compatibility/src/main/java/org/eclipse/sirius/web/compat/diagrams/ContainerMappingConverter.java index 0342d6c69d..5bcb67049b 100644 --- a/backend/sirius-web-compatibility/src/main/java/org/eclipse/sirius/web/compat/diagrams/ContainerMappingConverter.java +++ b/backend/sirius-web-compatibility/src/main/java/org/eclipse/sirius/web/compat/diagrams/ContainerMappingConverter.java @@ -19,12 +19,13 @@ import java.util.Optional; import java.util.UUID; import java.util.function.Function; -import java.util.function.Supplier; import java.util.stream.Collectors; import org.eclipse.sirius.diagram.description.ContainerMapping; import org.eclipse.sirius.diagram.description.style.ContainerStyleDescription; import org.eclipse.sirius.diagram.description.style.WorkspaceImageDescription; +import org.eclipse.sirius.viewpoint.description.style.BasicLabelStyleDescription; +import org.eclipse.sirius.viewpoint.description.style.StyleFactory; import org.eclipse.sirius.web.compat.api.IIdentifierProvider; import org.eclipse.sirius.web.compat.api.IModelOperationHandlerSwitchProvider; import org.eclipse.sirius.web.compat.api.ISemanticCandidatesProviderFactory; @@ -72,34 +73,27 @@ public ContainerMappingConverter(IObjectService objectService, IEditService edit } public NodeDescription convert(ContainerMapping containerMapping, Map id2NodeDescriptions) { - // @formatter:off - String labelExpression = Optional.ofNullable(containerMapping.getStyle()).map(ContainerStyleDescription::getLabelExpression).orElse(""); //$NON-NLS-1$ - Supplier defaultLabelStyleDescription = () -> LabelStyleDescription.newLabelStyleDescription() - .colorProvider(variableManager -> "#000000") //$NON-NLS-1$ - .fontSizeProvider(variableManager -> 16) - .italicProvider(variableManager -> false) - .boldProvider(variableManager -> false) - .underlineProvider(variableManager -> false) - .strikeThroughProvider(variableManager -> false) - .iconURLProvider(variableManager -> "") //$NON-NLS-1$ - .build(); + ContainerStyleDescriptionProvider containerStyleDescriptionProvider = new ContainerStyleDescriptionProvider(this.interpreter, containerMapping); - LabelStyleDescription labelStyleDescription = Optional.ofNullable(containerMapping.getStyle()) - .map(this.labelStyleDescriptionConverter::convert) - .orElseGet(defaultLabelStyleDescription); + Function labelStyleDescriptionProvider = variableManager -> { + ContainerStyleDescription styleDescription = containerStyleDescriptionProvider.getContainerStyleDescription(variableManager); + BasicLabelStyleDescription basicLabelStyleDescription = Optional.ofNullable(styleDescription).map(BasicLabelStyleDescription.class::cast).orElse(this.getDefaultLabelStyle()); + return this.labelStyleDescriptionConverter.convert(basicLabelStyleDescription); + }; + + Function labelExpressionProvider = variableManager -> { + ContainerStyleDescription styleDescription = containerStyleDescriptionProvider.getContainerStyleDescription(variableManager); + String labelExpression = Optional.ofNullable(styleDescription).map(ContainerStyleDescription::getLabelExpression).orElse(""); //$NON-NLS-1$ + return new StringValueProvider(this.interpreter, labelExpression).apply(variableManager); + }; Function labelIdProvider = variableManager -> { Object parentId = variableManager.getVariables().get(LabelDescription.OWNER_ID); return String.valueOf(parentId) + LabelDescription.LABEL_SUFFIX; }; - // @formatter:on - // @formatter:off - LabelDescription labelDescription = LabelDescription.newLabelDescription(this.identifierProvider.getIdentifier(containerMapping) + LabelDescription.LABEL_SUFFIX) - .idProvider(labelIdProvider) - .textProvider(new StringValueProvider(this.interpreter, labelExpression)) - .styleDescription(labelStyleDescription) - .build(); + LabelDescription labelDescription = LabelDescription.newLabelDescription(this.identifierProvider.getIdentifier(containerMapping) + LabelDescription.LABEL_SUFFIX).idProvider(labelIdProvider) + .textProvider(labelExpressionProvider).styleDescriptionProvider(labelStyleDescriptionProvider).build(); // @formatter:on Function semanticTargetIdProvider = variableManager -> { @@ -112,7 +106,8 @@ public NodeDescription convert(ContainerMapping containerMapping, Map typeProvider = variableManager -> { - if (containerMapping.getStyle() instanceof WorkspaceImageDescription) { + ContainerStyleDescription containerStyle = containerStyleDescriptionProvider.getContainerStyleDescription(variableManager); + if (containerStyle instanceof WorkspaceImageDescription) { return NodeType.NODE_IMAGE; } return NodeType.NODE_RECTANGLE; @@ -170,4 +165,11 @@ public NodeDescription convert(ContainerMapping containerMapping, Map conditionnalStyles = this.containerMapping.getConditionnalStyles(); - for (ConditionalContainerStyleDescription conditionalStyle : conditionnalStyles) { - String predicateExpression = conditionalStyle.getPredicateExpression(); - Result result = this.interpreter.evaluateExpression(variableManager.getVariables(), predicateExpression); - boolean shouldUseStyle = result.asBoolean().orElse(Boolean.FALSE).booleanValue(); - if (shouldUseStyle) { - style = this.getNodeStyle(variableManager, conditionalStyle.getStyle()); - break; - } - } - - if (style == null) { - style = this.getNodeStyle(variableManager, this.containerMapping.getStyle()); - } - - return style; + ContainerStyleDescription containerStyleDescription = new ContainerStyleDescriptionProvider(this.interpreter, this.containerMapping).getContainerStyleDescription(variableManager); + return this.getNodeStyle(variableManager, containerStyleDescription); } private INodeStyle getNodeStyle(VariableManager variableManager, ContainerStyleDescription containerStyleDescription) { diff --git a/backend/sirius-web-compatibility/src/main/java/org/eclipse/sirius/web/compat/diagrams/ContainerStyleDescriptionProvider.java b/backend/sirius-web-compatibility/src/main/java/org/eclipse/sirius/web/compat/diagrams/ContainerStyleDescriptionProvider.java new file mode 100644 index 0000000000..3ab14cdd1b --- /dev/null +++ b/backend/sirius-web-compatibility/src/main/java/org/eclipse/sirius/web/compat/diagrams/ContainerStyleDescriptionProvider.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * 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.compat.diagrams; + +import java.util.List; +import java.util.Objects; + +import org.eclipse.sirius.diagram.description.ConditionalContainerStyleDescription; +import org.eclipse.sirius.diagram.description.ContainerMapping; +import org.eclipse.sirius.diagram.description.style.ContainerStyleDescription; +import org.eclipse.sirius.web.interpreter.AQLInterpreter; +import org.eclipse.sirius.web.interpreter.Result; +import org.eclipse.sirius.web.representations.VariableManager; + +/** + * Compute the proper style description to use for a container mapping. + * + * @author sbegaudeau + */ +public class ContainerStyleDescriptionProvider { + private final AQLInterpreter interpreter; + + private final ContainerMapping containerMapping; + + public ContainerStyleDescriptionProvider(AQLInterpreter interpreter, ContainerMapping containerMapping) { + this.interpreter = Objects.requireNonNull(interpreter); + this.containerMapping = Objects.requireNonNull(containerMapping); + } + + public ContainerStyleDescription getContainerStyleDescription(VariableManager variableManager) { + ContainerStyleDescription styleDescription = this.containerMapping.getStyle(); + List conditionnalStyles = this.containerMapping.getConditionnalStyles(); + for (ConditionalContainerStyleDescription conditionalStyle : conditionnalStyles) { + String predicateExpression = conditionalStyle.getPredicateExpression(); + Result result = this.interpreter.evaluateExpression(variableManager.getVariables(), predicateExpression); + boolean shouldUseStyle = result.asBoolean().orElse(Boolean.FALSE).booleanValue(); + if (shouldUseStyle) { + styleDescription = conditionalStyle.getStyle(); + break; + } + } + return styleDescription; + } +} diff --git a/backend/sirius-web-compatibility/src/main/java/org/eclipse/sirius/web/compat/diagrams/EdgeMappingConverter.java b/backend/sirius-web-compatibility/src/main/java/org/eclipse/sirius/web/compat/diagrams/EdgeMappingConverter.java index 222921df3f..f20b113cd0 100644 --- a/backend/sirius-web-compatibility/src/main/java/org/eclipse/sirius/web/compat/diagrams/EdgeMappingConverter.java +++ b/backend/sirius-web-compatibility/src/main/java/org/eclipse/sirius/web/compat/diagrams/EdgeMappingConverter.java @@ -103,15 +103,17 @@ public EdgeDescription convert(EdgeMapping edgeMapping) { LabelStyleDescriptionConverter labelStyleDescriptionConverter = new LabelStyleDescriptionConverter(this.interpreter, this.objectService); // @formatter:off - Optional optionalBeginLabelDescription = Optional.ofNullable(edgeMapping.getStyle()) + EdgeStyleDescription style = edgeMapping.getStyle(); + + Optional optionalBeginLabelDescription = Optional.ofNullable(style) .map(EdgeStyleDescription::getBeginLabelStyleDescription) .map(labelDescription -> this.createLabelDescription(labelStyleDescriptionConverter, labelDescription, "_beginlabel", edgeMapping)); //$NON-NLS-1$ - Optional optionalCenterLabelDescription = Optional.ofNullable(edgeMapping.getStyle()) + Optional optionalCenterLabelDescription = Optional.ofNullable(style) .map(EdgeStyleDescription::getCenterLabelStyleDescription) .map(labelDescription -> this.createLabelDescription(labelStyleDescriptionConverter, labelDescription, "_centerlabel", edgeMapping)); //$NON-NLS-1$ - Optional optionalEndLabelDescription = Optional.ofNullable(edgeMapping.getStyle()) + Optional optionalEndLabelDescription = Optional.ofNullable(style) .map(EdgeStyleDescription::getEndLabelStyleDescription) .map(labelDescription -> this.createLabelDescription(labelStyleDescriptionConverter, labelDescription, "_endlabel", edgeMapping)); //$NON-NLS-1$ @@ -139,7 +141,10 @@ public EdgeDescription convert(EdgeMapping edgeMapping) { private LabelDescription createLabelDescription(LabelStyleDescriptionConverter labelStyleDescriptionConverter, BasicLabelStyleDescription siriusBasicLabelStyleDescription, String idSuffix, EdgeMapping edgeMapping) { String labelExpression = siriusBasicLabelStyleDescription.getLabelExpression(); - LabelStyleDescription labelStyleDescription = labelStyleDescriptionConverter.convert(siriusBasicLabelStyleDescription); + + Function labelStyleDescriptionProvider = variableManager -> { + return labelStyleDescriptionConverter.convert(siriusBasicLabelStyleDescription); + }; Function labelIdProvider = variableManager -> { Object parentId = variableManager.getVariables().get(LabelDescription.OWNER_ID); @@ -152,7 +157,7 @@ private LabelDescription createLabelDescription(LabelStyleDescriptionConverter l return LabelDescription.newLabelDescription(id) .idProvider(labelIdProvider) .textProvider(textProvider) - .styleDescription(labelStyleDescription) + .styleDescriptionProvider(labelStyleDescriptionProvider) .build(); // @formatter:on diff --git a/backend/sirius-web-compatibility/src/main/java/org/eclipse/sirius/web/compat/diagrams/EdgeMappingStyleProvider.java b/backend/sirius-web-compatibility/src/main/java/org/eclipse/sirius/web/compat/diagrams/EdgeMappingStyleProvider.java index cf2fcb323e..2b72883c37 100644 --- a/backend/sirius-web-compatibility/src/main/java/org/eclipse/sirius/web/compat/diagrams/EdgeMappingStyleProvider.java +++ b/backend/sirius-web-compatibility/src/main/java/org/eclipse/sirius/web/compat/diagrams/EdgeMappingStyleProvider.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2019, 2020 Obeo. + * Copyright (c) 2019, 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 @@ -15,14 +15,12 @@ import java.util.Objects; import java.util.function.Function; -import org.eclipse.sirius.diagram.description.ConditionalEdgeStyleDescription; import org.eclipse.sirius.diagram.description.EdgeMapping; import org.eclipse.sirius.diagram.description.style.EdgeStyleDescription; import org.eclipse.sirius.web.diagrams.ArrowStyle; import org.eclipse.sirius.web.diagrams.EdgeStyle; import org.eclipse.sirius.web.diagrams.LineStyle; import org.eclipse.sirius.web.interpreter.AQLInterpreter; -import org.eclipse.sirius.web.interpreter.Result; import org.eclipse.sirius.web.representations.VariableManager; /** @@ -43,23 +41,8 @@ public EdgeMappingStyleProvider(AQLInterpreter interpreter, EdgeMapping edgeMapp @Override public EdgeStyle apply(VariableManager variableManager) { - EdgeStyle edgeStyle = null; - - var conditionnalStyles = this.edgeMapping.getConditionnalStyles(); - for (ConditionalEdgeStyleDescription conditionalStyle : conditionnalStyles) { - String predicateExpression = conditionalStyle.getPredicateExpression(); - Result result = this.interpreter.evaluateExpression(variableManager.getVariables(), predicateExpression); - boolean shouldUseStyle = result.asBoolean().orElse(Boolean.FALSE).booleanValue(); - if (shouldUseStyle) { - edgeStyle = this.getEdgeStyle(variableManager, conditionalStyle.getStyle()); - break; - } - } - - if (edgeStyle == null) { - edgeStyle = this.getEdgeStyle(variableManager, this.edgeMapping.getStyle()); - } - return edgeStyle; + EdgeStyleDescription edgeStyleDescription = new EdgeStyleDescriptionProvider(this.interpreter, this.edgeMapping).getEdgeStyleDescription(variableManager); + return this.getEdgeStyle(variableManager, edgeStyleDescription); } private EdgeStyle getEdgeStyle(VariableManager variableManager, EdgeStyleDescription style) { diff --git a/backend/sirius-web-compatibility/src/main/java/org/eclipse/sirius/web/compat/diagrams/EdgeStyleDescriptionProvider.java b/backend/sirius-web-compatibility/src/main/java/org/eclipse/sirius/web/compat/diagrams/EdgeStyleDescriptionProvider.java new file mode 100644 index 0000000000..050bf2367b --- /dev/null +++ b/backend/sirius-web-compatibility/src/main/java/org/eclipse/sirius/web/compat/diagrams/EdgeStyleDescriptionProvider.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * 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.compat.diagrams; + +import java.util.List; +import java.util.Objects; + +import org.eclipse.sirius.diagram.description.ConditionalEdgeStyleDescription; +import org.eclipse.sirius.diagram.description.EdgeMapping; +import org.eclipse.sirius.diagram.description.style.EdgeStyleDescription; +import org.eclipse.sirius.web.interpreter.AQLInterpreter; +import org.eclipse.sirius.web.interpreter.Result; +import org.eclipse.sirius.web.representations.VariableManager; + +/** + * Compute the proper style description to use for a edge mapping. + * + * @author sbegaudeau + */ +public class EdgeStyleDescriptionProvider { + private final AQLInterpreter interpreter; + + private final EdgeMapping edgeMapping; + + public EdgeStyleDescriptionProvider(AQLInterpreter interpreter, EdgeMapping edgeMapping) { + this.interpreter = Objects.requireNonNull(interpreter); + this.edgeMapping = Objects.requireNonNull(edgeMapping); + } + + public EdgeStyleDescription getEdgeStyleDescription(VariableManager variableManager) { + EdgeStyleDescription styleDescription = this.edgeMapping.getStyle(); + List conditionnalStyles = this.edgeMapping.getConditionnalStyles(); + for (ConditionalEdgeStyleDescription conditionalStyle : conditionnalStyles) { + String predicateExpression = conditionalStyle.getPredicateExpression(); + Result result = this.interpreter.evaluateExpression(variableManager.getVariables(), predicateExpression); + boolean shouldUseStyle = result.asBoolean().orElse(Boolean.FALSE).booleanValue(); + if (shouldUseStyle) { + styleDescription = conditionalStyle.getStyle(); + break; + } + } + return styleDescription; + } +} diff --git a/backend/sirius-web-compatibility/src/main/java/org/eclipse/sirius/web/compat/diagrams/LabelStyleDescriptionConverter.java b/backend/sirius-web-compatibility/src/main/java/org/eclipse/sirius/web/compat/diagrams/LabelStyleDescriptionConverter.java index 72c1802bbe..f1aa5cae50 100644 --- a/backend/sirius-web-compatibility/src/main/java/org/eclipse/sirius/web/compat/diagrams/LabelStyleDescriptionConverter.java +++ b/backend/sirius-web-compatibility/src/main/java/org/eclipse/sirius/web/compat/diagrams/LabelStyleDescriptionConverter.java @@ -38,7 +38,6 @@ public LabelStyleDescriptionConverter(AQLInterpreter interpreter, IObjectService } public LabelStyleDescription convert(org.eclipse.sirius.viewpoint.description.style.BasicLabelStyleDescription labelStyleDescription) { - Objects.requireNonNull(labelStyleDescription); List fontFormats = labelStyleDescription.getLabelFormat(); Function iconURLProvider = (variableManager) -> { diff --git a/backend/sirius-web-compatibility/src/main/java/org/eclipse/sirius/web/compat/diagrams/NodeMappingConverter.java b/backend/sirius-web-compatibility/src/main/java/org/eclipse/sirius/web/compat/diagrams/NodeMappingConverter.java index b5c1c28227..d24398481a 100644 --- a/backend/sirius-web-compatibility/src/main/java/org/eclipse/sirius/web/compat/diagrams/NodeMappingConverter.java +++ b/backend/sirius-web-compatibility/src/main/java/org/eclipse/sirius/web/compat/diagrams/NodeMappingConverter.java @@ -16,6 +16,7 @@ import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.Optional; import java.util.UUID; import java.util.function.Function; import java.util.stream.Collectors; @@ -23,6 +24,7 @@ import org.eclipse.sirius.diagram.description.NodeMapping; import org.eclipse.sirius.diagram.description.style.NodeStyleDescription; import org.eclipse.sirius.diagram.description.style.WorkspaceImageDescription; +import org.eclipse.sirius.viewpoint.description.style.BasicLabelStyleDescription; import org.eclipse.sirius.viewpoint.description.style.StyleFactory; import org.eclipse.sirius.web.compat.api.IIdentifierProvider; import org.eclipse.sirius.web.compat.api.IModelOperationHandlerSwitchProvider; @@ -71,18 +73,20 @@ public NodeMappingConverter(IObjectService objectService, IEditService editServi } public NodeDescription convert(NodeMapping nodeMapping, Map id2NodeDescriptions) { - NodeStyleDescription nodeStyle = nodeMapping.getStyle(); - - String labelExpression = ""; //$NON-NLS-1$ - if (nodeStyle != null) { - labelExpression = nodeStyle.getLabelExpression(); - } - LabelStyleDescription labelStyleDescription; - if (nodeStyle != null) { - labelStyleDescription = this.labelStyleDescriptionConverter.convert(nodeStyle); - } else { - labelStyleDescription = this.labelStyleDescriptionConverter.convert(this.getDefaultLabelStyle()); - } + NodeStyleDescriptionProvider nodeStyleDescriptionProvider = new NodeStyleDescriptionProvider(this.interpreter, nodeMapping); + + Function labelStyleDescriptionProvider = variableManager -> { + NodeStyleDescription styleDescription = nodeStyleDescriptionProvider.getNodeStyleDescription(variableManager); + BasicLabelStyleDescription basicLabelStyleDescription = Optional.ofNullable(styleDescription).map(BasicLabelStyleDescription.class::cast).orElse(this.getDefaultLabelStyle()); + return this.labelStyleDescriptionConverter.convert(basicLabelStyleDescription); + }; + + Function labelExpressionProvider = variableManager -> { + NodeStyleDescription styleDescription = nodeStyleDescriptionProvider.getNodeStyleDescription(variableManager); + String labelExpression = Optional.ofNullable(styleDescription).map(NodeStyleDescription::getLabelExpression).orElse(""); //$NON-NLS-1$ + return new StringValueProvider(this.interpreter, labelExpression).apply(variableManager); + }; + Function labelIdProvider = variableManager -> { Object parentId = variableManager.getVariables().get(LabelDescription.OWNER_ID); return String.valueOf(parentId) + LabelDescription.LABEL_SUFFIX; @@ -91,8 +95,8 @@ public NodeDescription convert(NodeMapping nodeMapping, Map typeProvider = variableManager -> { + NodeStyleDescription nodeStyle = nodeStyleDescriptionProvider.getNodeStyleDescription(variableManager); if (nodeStyle instanceof WorkspaceImageDescription) { return NodeType.NODE_IMAGE; } @@ -151,7 +156,7 @@ public NodeDescription convert(NodeMapping nodeMapping, Map conditionnalStyles = this.nodeMapping.getConditionnalStyles(); - for (ConditionalNodeStyleDescription conditionalStyle : conditionnalStyles) { - String predicateExpression = conditionalStyle.getPredicateExpression(); - Result result = this.interpreter.evaluateExpression(variableManager.getVariables(), predicateExpression); - boolean shouldUseStyle = result.asBoolean().orElse(Boolean.FALSE).booleanValue(); - if (shouldUseStyle) { - style = this.getNodeStyle(variableManager, conditionalStyle.getStyle()); - break; - } - } - - if (style == null) { - style = this.getNodeStyle(variableManager, this.nodeMapping.getStyle()); - } - - return style; + NodeStyleDescription nodeStyleDescription = new NodeStyleDescriptionProvider(this.interpreter, this.nodeMapping).getNodeStyleDescription(variableManager); + return this.getNodeStyle(variableManager, nodeStyleDescription); } private INodeStyle getNodeStyle(VariableManager variableManager, NodeStyleDescription nodeStyleDescription) { diff --git a/backend/sirius-web-compatibility/src/main/java/org/eclipse/sirius/web/compat/diagrams/NodeStyleDescriptionProvider.java b/backend/sirius-web-compatibility/src/main/java/org/eclipse/sirius/web/compat/diagrams/NodeStyleDescriptionProvider.java new file mode 100644 index 0000000000..82f3a7f309 --- /dev/null +++ b/backend/sirius-web-compatibility/src/main/java/org/eclipse/sirius/web/compat/diagrams/NodeStyleDescriptionProvider.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * 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.compat.diagrams; + +import java.util.List; +import java.util.Objects; + +import org.eclipse.sirius.diagram.description.ConditionalNodeStyleDescription; +import org.eclipse.sirius.diagram.description.NodeMapping; +import org.eclipse.sirius.diagram.description.style.NodeStyleDescription; +import org.eclipse.sirius.web.interpreter.AQLInterpreter; +import org.eclipse.sirius.web.interpreter.Result; +import org.eclipse.sirius.web.representations.VariableManager; + +/** + * Compute the proper style description to use for a node mapping. + * + * @author arichard + */ +public class NodeStyleDescriptionProvider { + + private final AQLInterpreter interpreter; + + private final NodeMapping nodeMapping; + + public NodeStyleDescriptionProvider(AQLInterpreter interpreter, NodeMapping nodeMapping) { + this.interpreter = Objects.requireNonNull(interpreter); + this.nodeMapping = Objects.requireNonNull(nodeMapping); + } + + public NodeStyleDescription getNodeStyleDescription(VariableManager variableManager) { + NodeStyleDescription styleDescription = this.nodeMapping.getStyle(); + List conditionnalStyles = this.nodeMapping.getConditionnalStyles(); + for (ConditionalNodeStyleDescription conditionalStyle : conditionnalStyles) { + String predicateExpression = conditionalStyle.getPredicateExpression(); + Result result = this.interpreter.evaluateExpression(variableManager.getVariables(), predicateExpression); + boolean shouldUseStyle = result.asBoolean().orElse(Boolean.FALSE).booleanValue(); + if (shouldUseStyle) { + styleDescription = conditionalStyle.getStyle(); + break; + } + } + return styleDescription; + } +} diff --git a/backend/sirius-web-compatibility/src/test/java/org/eclipse/sirius/web/compat/AllSiriusWebCompatibilityTests.java b/backend/sirius-web-compatibility/src/test/java/org/eclipse/sirius/web/compat/AllSiriusWebCompatibilityTests.java index 83f0fc18ca..1021c5b746 100644 --- a/backend/sirius-web-compatibility/src/test/java/org/eclipse/sirius/web/compat/AllSiriusWebCompatibilityTests.java +++ b/backend/sirius-web-compatibility/src/test/java/org/eclipse/sirius/web/compat/AllSiriusWebCompatibilityTests.java @@ -22,6 +22,7 @@ import org.eclipse.sirius.web.compat.diagrams.DomainBasedSourceNodesProviderTestCases; import org.eclipse.sirius.web.compat.diagrams.EdgeMappingStyleProviderTestCases; import org.eclipse.sirius.web.compat.diagrams.LabelStyleDescriptionConverterTestCases; +import org.eclipse.sirius.web.compat.diagrams.MappingConverterTestCases; import org.eclipse.sirius.web.compat.diagrams.NodeMappingStyleProviderTestCases; import org.eclipse.sirius.web.compat.diagrams.RelationBasedSourceNodesProviderTestCases; import org.eclipse.sirius.web.compat.diagrams.WorkspaceImageDescriptionConverterTestCases; @@ -49,6 +50,7 @@ EdgeMappingStyleProviderTestCases.class, LabelStyleDescriptionConverterTestCases.class, + MappingConverterTestCases.class, NodeMappingStyleProviderTestCases.class, RelationBasedSourceNodesProviderTestCases.class, WorkspaceImageDescriptionConverterTestCases.class, diff --git a/backend/sirius-web-compatibility/src/test/java/org/eclipse/sirius/web/compat/diagrams/BasicLabelStyleDescriptionPopulator.java b/backend/sirius-web-compatibility/src/test/java/org/eclipse/sirius/web/compat/diagrams/BasicLabelStyleDescriptionPopulator.java new file mode 100644 index 0000000000..d1f677d950 --- /dev/null +++ b/backend/sirius-web-compatibility/src/test/java/org/eclipse/sirius/web/compat/diagrams/BasicLabelStyleDescriptionPopulator.java @@ -0,0 +1,72 @@ +/******************************************************************************* + * 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.compat.diagrams; + +import java.util.Objects; + +import org.eclipse.sirius.viewpoint.FontFormat; +import org.eclipse.sirius.viewpoint.description.ColorDescription; +import org.eclipse.sirius.viewpoint.description.style.BasicLabelStyleDescription; + +/** + * Used to populate easily a label style description. + * + * @author sbegaudeau + */ +public class BasicLabelStyleDescriptionPopulator { + private final BasicLabelStyleDescription basicLabelStyleDescription; + + public BasicLabelStyleDescriptionPopulator(BasicLabelStyleDescription basicLabelStyleDescription) { + this.basicLabelStyleDescription = Objects.requireNonNull(basicLabelStyleDescription); + } + + public BasicLabelStyleDescriptionPopulator labelExpression(String labelExpression) { + this.basicLabelStyleDescription.setLabelExpression(labelExpression); + return this; + } + + public BasicLabelStyleDescriptionPopulator labelSize(int labelSize) { + this.basicLabelStyleDescription.setLabelSize(labelSize); + return this; + } + + public BasicLabelStyleDescriptionPopulator bold() { + this.basicLabelStyleDescription.getLabelFormat().add(FontFormat.BOLD_LITERAL); + return this; + } + + public BasicLabelStyleDescriptionPopulator italic() { + this.basicLabelStyleDescription.getLabelFormat().add(FontFormat.ITALIC_LITERAL); + return this; + } + + public BasicLabelStyleDescriptionPopulator underline() { + this.basicLabelStyleDescription.getLabelFormat().add(FontFormat.UNDERLINE_LITERAL); + return this; + } + + public BasicLabelStyleDescriptionPopulator strikeThrough() { + this.basicLabelStyleDescription.getLabelFormat().add(FontFormat.STRIKE_THROUGH_LITERAL); + return this; + } + + public BasicLabelStyleDescriptionPopulator labelColor(ColorDescription colorDescription) { + this.basicLabelStyleDescription.setLabelColor(colorDescription); + return this; + } + + public BasicLabelStyleDescriptionPopulator iconPath(String iconPath) { + this.basicLabelStyleDescription.setIconPath(iconPath); + return this; + } +} diff --git a/backend/sirius-web-compatibility/src/test/java/org/eclipse/sirius/web/compat/diagrams/MappingConverterTestCases.java b/backend/sirius-web-compatibility/src/test/java/org/eclipse/sirius/web/compat/diagrams/MappingConverterTestCases.java new file mode 100644 index 0000000000..d8f2818328 --- /dev/null +++ b/backend/sirius-web-compatibility/src/test/java/org/eclipse/sirius/web/compat/diagrams/MappingConverterTestCases.java @@ -0,0 +1,226 @@ +/******************************************************************************* + * 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.compat.diagrams; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.HashMap; +import java.util.List; +import java.util.Optional; +import java.util.UUID; + +import org.eclipse.emf.ecore.EcorePackage; +import org.eclipse.sirius.diagram.description.ConditionalContainerStyleDescription; +import org.eclipse.sirius.diagram.description.ConditionalNodeStyleDescription; +import org.eclipse.sirius.diagram.description.ContainerMapping; +import org.eclipse.sirius.diagram.description.DescriptionFactory; +import org.eclipse.sirius.diagram.description.NodeMapping; +import org.eclipse.sirius.diagram.description.style.ContainerStyleDescription; +import org.eclipse.sirius.diagram.description.style.NodeStyleDescription; +import org.eclipse.sirius.diagram.description.style.StyleFactory; +import org.eclipse.sirius.viewpoint.description.FixedColor; +import org.eclipse.sirius.web.compat.api.IIdentifierProvider; +import org.eclipse.sirius.web.compat.api.IModelOperationHandlerSwitchProvider; +import org.eclipse.sirius.web.compat.api.ISemanticCandidatesProviderFactory; +import org.eclipse.sirius.web.diagrams.description.LabelDescription; +import org.eclipse.sirius.web.diagrams.description.LabelStyleDescription; +import org.eclipse.sirius.web.diagrams.description.NodeDescription; +import org.eclipse.sirius.web.interpreter.AQLInterpreter; +import org.eclipse.sirius.web.representations.VariableManager; +import org.junit.Test; + +/** + * Unit tests used to validate the proper retrieval of the conditional styles. + * + * @author arichard + */ +public class MappingConverterTestCases { + + private static final String EXPRESSION_FALSE = "aql:false"; //$NON-NLS-1$ + + private static final String EXPRESSION_TRUE = "aql:true"; //$NON-NLS-1$ + + private static final String PLUGIN_ID = "my.sirius.plugin"; //$NON-NLS-1$ + + private static final String ICON_PATH = "/my/icon/path/MyIcon.gif"; //$NON-NLS-1$ + + @Test + public void testContainerStylePropertiesFromConditionalStyle() { + ContainerMapping containerMapping = DescriptionFactory.eINSTANCE.createContainerMapping(); + String mappingName = "TestMapping"; //$NON-NLS-1$ + containerMapping.setName(mappingName); + + // @formatter:off + ContainerStyleDescription defaultStyle = StyleFactory.eINSTANCE.createFlatContainerStyleDescription(); + new BasicLabelStyleDescriptionPopulator(defaultStyle) + .labelExpression("aql: defaultStyle") //$NON-NLS-1$ + .labelSize(10) + .labelColor(this.getColor(1, 1, 1)); + + ContainerStyleDescription firstConditionalStyle = StyleFactory.eINSTANCE.createFlatContainerStyleDescription(); + new BasicLabelStyleDescriptionPopulator(firstConditionalStyle) + .labelExpression("aql:'firstConditionalStyle'") //$NON-NLS-1$ + .labelSize(4) + .labelColor(this.getColor(3, 3, 3)); + + ContainerStyleDescription secondConditionalStyle = StyleFactory.eINSTANCE.createFlatContainerStyleDescription(); + new BasicLabelStyleDescriptionPopulator(secondConditionalStyle) + .labelExpression("aql:'secondConditionalStyle'") //$NON-NLS-1$ + .labelSize(6) + .bold() + .italic() + .underline() + .strikeThrough() + .labelColor(this.getColor(2, 2, 2)) + .iconPath(PLUGIN_ID + ICON_PATH); + + ContainerStyleDescription thirdConditionalStyle = StyleFactory.eINSTANCE.createFlatContainerStyleDescription(); + new BasicLabelStyleDescriptionPopulator(thirdConditionalStyle) + .labelExpression("aql:'thirdConditionalStyle'") //$NON-NLS-1$ + .labelSize(8) + .labelColor(this.getColor(4, 4, 4)); + // @formatter:on + + containerMapping.setStyle(defaultStyle); + containerMapping.getConditionnalStyles().add(this.createConditionalContainerStyle(EXPRESSION_FALSE, firstConditionalStyle)); + containerMapping.getConditionnalStyles().add(this.createConditionalContainerStyle(EXPRESSION_TRUE, secondConditionalStyle)); + containerMapping.getConditionnalStyles().add(this.createConditionalContainerStyle(EXPRESSION_TRUE, thirdConditionalStyle)); + + IIdentifierProvider identifierProvider = element -> UUID.randomUUID().toString(); + ISemanticCandidatesProviderFactory semanticCandidatesProviderFactory = (interpreter, domainClass, semanticCandidatesExpression, preconditionExpression) -> variableManager -> List.of(); + IModelOperationHandlerSwitchProvider modelOperationHandlerSwitchProvider = interpreter -> modelOperation -> Optional.empty(); + + VariableManager variableManager = new VariableManager(); + AQLInterpreter interpreter = new AQLInterpreter(List.of(), List.of(EcorePackage.eINSTANCE)); + ContainerMappingConverter converter = new ContainerMappingConverter(new NoOpObjectService(), new NoOpEditService(), interpreter, identifierProvider, semanticCandidatesProviderFactory, + modelOperationHandlerSwitchProvider); + + NodeDescription convertedNodeDescription = converter.convert(containerMapping, new HashMap()); + LabelDescription labelDescription = convertedNodeDescription.getLabelDescription(); + + String text = labelDescription.getTextProvider().apply(variableManager); + LabelStyleDescription labelStyleDescription = labelDescription.getStyleDescriptionProvider().apply(variableManager); + Integer fontSize = labelStyleDescription.getFontSizeProvider().apply(variableManager); + Boolean isBold = labelStyleDescription.getBoldProvider().apply(variableManager); + Boolean isItalic = labelStyleDescription.getItalicProvider().apply(variableManager); + Boolean isUnderline = labelStyleDescription.getUnderlineProvider().apply(variableManager); + Boolean isStrikeThrough = labelStyleDescription.getStrikeThroughProvider().apply(variableManager); + String color = labelStyleDescription.getColorProvider().apply(variableManager); + String iconURL = labelStyleDescription.getIconURLProvider().apply(variableManager); + + assertThat(text).isEqualTo("secondConditionalStyle"); //$NON-NLS-1$ + assertThat(fontSize).isEqualTo(6); + assertThat(isBold).isTrue(); + assertThat(isItalic).isTrue(); + assertThat(isUnderline).isTrue(); + assertThat(isStrikeThrough).isTrue(); + assertThat(color).isEqualTo("#020202"); //$NON-NLS-1$ + assertThat(iconURL).isEqualTo(ICON_PATH); + } + + @Test + public void testNodeStylePropertiesFromConditionalStyle() { + NodeMapping nodeMapping = DescriptionFactory.eINSTANCE.createNodeMapping(); + String mappingName = "TestMapping"; //$NON-NLS-1$ + nodeMapping.setName(mappingName); + + // @formatter:off + NodeStyleDescription defaultStyle = StyleFactory.eINSTANCE.createSquareDescription(); + new BasicLabelStyleDescriptionPopulator(defaultStyle) + .labelExpression("aql:'defaultStyle'") //$NON-NLS-1$ + .labelSize(10) + .labelColor(this.getColor(1, 1, 1)); + + NodeStyleDescription firstConditionalStyle = StyleFactory.eINSTANCE.createSquareDescription(); + new BasicLabelStyleDescriptionPopulator(firstConditionalStyle) + .labelExpression("aql:'firstConditionalStyle'") //$NON-NLS-1$ + .labelSize(4) + .labelColor(this.getColor(3, 3, 3)); + + NodeStyleDescription secondConditionalStyle = StyleFactory.eINSTANCE.createSquareDescription(); + new BasicLabelStyleDescriptionPopulator(secondConditionalStyle) + .labelExpression("aql:'secondConditionalStyle'") //$NON-NLS-1$ + .labelSize(6) + .bold() + .italic() + .underline() + .strikeThrough() + .labelColor(this.getColor(2, 2, 2)) + .iconPath(PLUGIN_ID + ICON_PATH); + + NodeStyleDescription thirdConditionalStyle = StyleFactory.eINSTANCE.createSquareDescription(); + new BasicLabelStyleDescriptionPopulator(thirdConditionalStyle) + .labelExpression("aql:'thirdConditionalStyle'") //$NON-NLS-1$ + .labelSize(8) + .labelColor(this.getColor(4, 4, 4)); + // @formatter:on + + nodeMapping.setStyle(defaultStyle); + nodeMapping.getConditionnalStyles().add(this.createConditionalNodeStyle(EXPRESSION_FALSE, firstConditionalStyle)); + nodeMapping.getConditionnalStyles().add(this.createConditionalNodeStyle(EXPRESSION_TRUE, secondConditionalStyle)); + nodeMapping.getConditionnalStyles().add(this.createConditionalNodeStyle(EXPRESSION_TRUE, thirdConditionalStyle)); + + IIdentifierProvider identifierProvider = element -> UUID.randomUUID().toString(); + ISemanticCandidatesProviderFactory semanticCandidatesProviderFactory = (interpreter, domainClass, semanticCandidatesExpression, preconditionExpression) -> variableManager -> List.of(); + IModelOperationHandlerSwitchProvider modelOperationHandlerSwitchProvider = interpreter -> modelOperation -> Optional.empty(); + + VariableManager variableManager = new VariableManager(); + AQLInterpreter interpreter = new AQLInterpreter(List.of(), List.of(EcorePackage.eINSTANCE)); + NodeMappingConverter converter = new NodeMappingConverter(new NoOpObjectService(), new NoOpEditService(), interpreter, identifierProvider, semanticCandidatesProviderFactory, + modelOperationHandlerSwitchProvider); + + NodeDescription convertedNodeDescription = converter.convert(nodeMapping, new HashMap()); + LabelDescription labelDescription = convertedNodeDescription.getLabelDescription(); + + String text = labelDescription.getTextProvider().apply(variableManager); + LabelStyleDescription labelStyleDescription = labelDescription.getStyleDescriptionProvider().apply(variableManager); + Integer fontSize = labelStyleDescription.getFontSizeProvider().apply(variableManager); + Boolean isBold = labelStyleDescription.getBoldProvider().apply(variableManager); + Boolean isItalic = labelStyleDescription.getItalicProvider().apply(variableManager); + Boolean isUnderline = labelStyleDescription.getUnderlineProvider().apply(variableManager); + Boolean isStrikeThrough = labelStyleDescription.getStrikeThroughProvider().apply(variableManager); + String color = labelStyleDescription.getColorProvider().apply(variableManager); + String iconURL = labelStyleDescription.getIconURLProvider().apply(variableManager); + + assertThat(text).isEqualTo("secondConditionalStyle"); //$NON-NLS-1$ + assertThat(fontSize).isEqualTo(6); + assertThat(isBold).isTrue(); + assertThat(isItalic).isTrue(); + assertThat(isUnderline).isTrue(); + assertThat(isStrikeThrough).isTrue(); + assertThat(color).isEqualTo("#020202"); //$NON-NLS-1$ + assertThat(iconURL).isEqualTo(ICON_PATH); + } + + private FixedColor getColor(int red, int green, int blue) { + FixedColor fixedColor = org.eclipse.sirius.viewpoint.description.DescriptionFactory.eINSTANCE.createFixedColor(); + fixedColor.setRed(red); + fixedColor.setGreen(green); + fixedColor.setBlue(blue); + return fixedColor; + } + + private ConditionalContainerStyleDescription createConditionalContainerStyle(String predicateExpression, ContainerStyleDescription containerStyleDescription) { + ConditionalContainerStyleDescription conditionalContainerStyle = DescriptionFactory.eINSTANCE.createConditionalContainerStyleDescription(); + conditionalContainerStyle.setPredicateExpression(predicateExpression); + conditionalContainerStyle.setStyle(containerStyleDescription); + return conditionalContainerStyle; + } + + private ConditionalNodeStyleDescription createConditionalNodeStyle(String predicateExpression, NodeStyleDescription nodeStyleDescription) { + ConditionalNodeStyleDescription conditionalNodeStyle = DescriptionFactory.eINSTANCE.createConditionalNodeStyleDescription(); + conditionalNodeStyle.setPredicateExpression(predicateExpression); + conditionalNodeStyle.setStyle(nodeStyleDescription); + return conditionalNodeStyle; + } +} diff --git a/backend/sirius-web-diagrams-tests/src/main/java/org/eclipse/sirius/web/diagrams/tests/TestDiagramDescriptionBuilder.java b/backend/sirius-web-diagrams-tests/src/main/java/org/eclipse/sirius/web/diagrams/tests/TestDiagramDescriptionBuilder.java index 346ddee5e9..b5e80af7c6 100644 --- a/backend/sirius-web-diagrams-tests/src/main/java/org/eclipse/sirius/web/diagrams/tests/TestDiagramDescriptionBuilder.java +++ b/backend/sirius-web-diagrams-tests/src/main/java/org/eclipse/sirius/web/diagrams/tests/TestDiagramDescriptionBuilder.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2019, 2020 Obeo. + * Copyright (c) 2019, 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 @@ -101,7 +101,7 @@ public NodeDescription getNodeDescription(UUID nodeDescriptionId, Function "labelId") //$NON-NLS-1$ .textProvider(variableManager -> "Node") //$NON-NLS-1$ - .styleDescription(labelStyleDescription) + .styleDescriptionProvider(variableManager -> labelStyleDescription) .build(); Function nodeStyleProvider = variableManager -> { diff --git a/backend/sirius-web-diagrams/src/main/java/org/eclipse/sirius/web/diagrams/components/LabelComponent.java b/backend/sirius-web-diagrams/src/main/java/org/eclipse/sirius/web/diagrams/components/LabelComponent.java index 3e39848ddf..57c5504ac4 100644 --- a/backend/sirius-web-diagrams/src/main/java/org/eclipse/sirius/web/diagrams/components/LabelComponent.java +++ b/backend/sirius-web-diagrams/src/main/java/org/eclipse/sirius/web/diagrams/components/LabelComponent.java @@ -52,7 +52,7 @@ public Element render() { String id = labelDescription.getIdProvider().apply(variableManager); String text = labelDescription.getTextProvider().apply(variableManager); - LabelStyleDescription labelStyleDescription = labelDescription.getStyleDescription(); + LabelStyleDescription labelStyleDescription = labelDescription.getStyleDescriptionProvider().apply(variableManager); String color = labelStyleDescription.getColorProvider().apply(variableManager); Integer fontSize = labelStyleDescription.getFontSizeProvider().apply(variableManager); diff --git a/backend/sirius-web-diagrams/src/main/java/org/eclipse/sirius/web/diagrams/description/LabelDescription.java b/backend/sirius-web-diagrams/src/main/java/org/eclipse/sirius/web/diagrams/description/LabelDescription.java index 670b96feef..e33cd99a3c 100644 --- a/backend/sirius-web-diagrams/src/main/java/org/eclipse/sirius/web/diagrams/description/LabelDescription.java +++ b/backend/sirius-web-diagrams/src/main/java/org/eclipse/sirius/web/diagrams/description/LabelDescription.java @@ -43,7 +43,7 @@ public final class LabelDescription { private Function textProvider; - private LabelStyleDescription styleDescription; + private Function styleDescriptionProvider; private LabelDescription() { // Prevent instantiation @@ -65,8 +65,8 @@ public static Builder newLabelDescription(String id) { return new Builder(id); } - public LabelStyleDescription getStyleDescription() { - return this.styleDescription; + public Function getStyleDescriptionProvider() { + return this.styleDescriptionProvider; } @Override @@ -88,7 +88,7 @@ public static final class Builder { private Function textProvider; - private LabelStyleDescription styleDescription; + private Function styleDescriptionProvider; private Builder(String id) { this.id = Objects.requireNonNull(id); @@ -104,8 +104,8 @@ public Builder textProvider(Function textProvider) { return this; } - public Builder styleDescription(LabelStyleDescription styleDescription) { - this.styleDescription = Objects.requireNonNull(styleDescription); + public Builder styleDescriptionProvider(Function styleDescriptionProvider) { + this.styleDescriptionProvider = Objects.requireNonNull(styleDescriptionProvider); return this; } @@ -114,7 +114,7 @@ public LabelDescription build() { labelDescription.id = Objects.requireNonNull(this.id); labelDescription.idProvider = Objects.requireNonNull(this.idProvider); labelDescription.textProvider = Objects.requireNonNull(this.textProvider); - labelDescription.styleDescription = Objects.requireNonNull(this.styleDescription); + labelDescription.styleDescriptionProvider = Objects.requireNonNull(this.styleDescriptionProvider); return labelDescription; } } diff --git a/backend/sirius-web-diagrams/src/test/java/org/eclipse/sirius/web/diagrams/renderer/DiagramRendererEdgeTestCases.java b/backend/sirius-web-diagrams/src/test/java/org/eclipse/sirius/web/diagrams/renderer/DiagramRendererEdgeTestCases.java index fc2f3bbcf2..204971d223 100644 --- a/backend/sirius-web-diagrams/src/test/java/org/eclipse/sirius/web/diagrams/renderer/DiagramRendererEdgeTestCases.java +++ b/backend/sirius-web-diagrams/src/test/java/org/eclipse/sirius/web/diagrams/renderer/DiagramRendererEdgeTestCases.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2019, 2020 Obeo. + * Copyright (c) 2019, 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 @@ -166,7 +166,7 @@ private NodeDescription getNodeDescription(UUID nodeDescriptionId) { LabelDescription labelDescription = LabelDescription.newLabelDescription("labelDescriptionId") //$NON-NLS-1$ .idProvider(variableManager -> "labelId") //$NON-NLS-1$ .textProvider(variableManager -> "Node") //$NON-NLS-1$ - .styleDescription(labelStyleDescription) + .styleDescriptionProvider(variableManager -> labelStyleDescription) .build(); Function nodeStyleProvider = variableManager -> { diff --git a/backend/sirius-web-diagrams/src/test/java/org/eclipse/sirius/web/diagrams/renderer/DiagramRendererNodeTestCases.java b/backend/sirius-web-diagrams/src/test/java/org/eclipse/sirius/web/diagrams/renderer/DiagramRendererNodeTestCases.java index 81803e2b60..918df0b186 100644 --- a/backend/sirius-web-diagrams/src/test/java/org/eclipse/sirius/web/diagrams/renderer/DiagramRendererNodeTestCases.java +++ b/backend/sirius-web-diagrams/src/test/java/org/eclipse/sirius/web/diagrams/renderer/DiagramRendererNodeTestCases.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2019, 2020 Obeo. + * Copyright (c) 2019, 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 @@ -161,7 +161,7 @@ private Diagram createDiagram(Function styleProvide LabelDescription labelDescription = LabelDescription.newLabelDescription("labelDescriptionId") //$NON-NLS-1$ .idProvider(variableManager -> LABEL_ID) .textProvider(variableManager -> LABEL_TEXT) - .styleDescription(labelStyleDescription) + .styleDescriptionProvider(variableManager -> labelStyleDescription) .build(); NodeDescription nodeDescription = NodeDescription.newNodeDescription(NODE_DESCRIPTION_ID) diff --git a/backend/sirius-web-diagrams/src/test/java/org/eclipse/sirius/web/diagrams/renderer/UnsynchronizedDiagramTestCases.java b/backend/sirius-web-diagrams/src/test/java/org/eclipse/sirius/web/diagrams/renderer/UnsynchronizedDiagramTestCases.java index 4ad357f667..e9fd68ded7 100644 --- a/backend/sirius-web-diagrams/src/test/java/org/eclipse/sirius/web/diagrams/renderer/UnsynchronizedDiagramTestCases.java +++ b/backend/sirius-web-diagrams/src/test/java/org/eclipse/sirius/web/diagrams/renderer/UnsynchronizedDiagramTestCases.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2019, 2020 Obeo. + * Copyright (c) 2019, 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 @@ -153,7 +153,7 @@ private DiagramDescription getDiagramDescription() { LabelDescription labelDescription = LabelDescription.newLabelDescription("labelDescriptionId") //$NON-NLS-1$ .idProvider(variableManager -> "labelid") //$NON-NLS-1$ .textProvider(variableManager -> "label") //$NON-NLS-1$ - .styleDescription(labelStyleDescription) + .styleDescriptionProvider(variableManager -> labelStyleDescription) .build(); Function styleProvider = variableManager -> { diff --git a/backend/sirius-web-emf/src/test/java/org/eclipse/sirius/web/emf/compatibility/diagrams/EdgeMappingConverterTestCases.java b/backend/sirius-web-emf/src/test/java/org/eclipse/sirius/web/emf/compatibility/diagrams/EdgeMappingConverterTestCases.java index db2199bf5a..70317c3641 100644 --- a/backend/sirius-web-emf/src/test/java/org/eclipse/sirius/web/emf/compatibility/diagrams/EdgeMappingConverterTestCases.java +++ b/backend/sirius-web-emf/src/test/java/org/eclipse/sirius/web/emf/compatibility/diagrams/EdgeMappingConverterTestCases.java @@ -92,7 +92,7 @@ private NodeDescription createNodeDescription(UUID id) { LabelDescription labelDescription = LabelDescription.newLabelDescription(id.toString()) .idProvider(variableManager -> "") //$NON-NLS-1$ .textProvider(variableManager -> "") //$NON-NLS-1$ - .styleDescription(styleDescription) + .styleDescriptionProvider(variableManager -> styleDescription) .build(); return NodeDescription.newNodeDescription(id)