Skip to content

Commit

Permalink
[897] Handle Dot style for Bordered Nodes
Browse files Browse the repository at this point in the history
Bug: eclipse-sirius#897
Change-Id: Id41b42e980bd80b67778a9195dd51013636edc1d
Signed-off-by: Axel RICHARD <axel.richard@obeo.fr>
  • Loading branch information
AxelRICHARD committed Dec 17, 2021
1 parent beef83c commit 76561a5
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ Currently it is not possible to compute different values for width and height.
- https://github.com/eclipse-sirius/sirius-components/issues/134[#134] [workbench] The internal API of the workbench is now ready to accept features leveraging a multi-selection
- [form] Add a tooltip to always make the full label available
- [core] Customize the Spring `ObjectMapper` instead of creating a brand new one from scratch in our `ObjectMapperConfiguration`
- https://github.com/eclipse-sirius/sirius-components/issues/871[#871] An `IEditingContextEventProcessorExecutorServiceProvider` can be given to the `EditingContextEventProcessor` in order to customize the `ExecutorService` which will be used to handle the processing of the `IInput` received. This will allow consumers to change the thread management policy of Sirius Components
- https://github.com/eclipse-sirius/sirius-components/issues/897[#897] [compatibility] The Bordered Node Dot Style is now handled in the compatibility layer

=== Bug fixes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.function.Function;

import org.eclipse.sirius.diagram.description.AbstractNodeMapping;
import org.eclipse.sirius.diagram.description.style.DotDescription;
import org.eclipse.sirius.diagram.description.style.FlatContainerStyleDescription;
import org.eclipse.sirius.diagram.description.style.SquareDescription;
import org.eclipse.sirius.viewpoint.description.style.LabelStyleDescription;
Expand Down Expand Up @@ -84,6 +85,17 @@ public Size apply(VariableManager variableManager) {
height = computedHeight * SIZE_FACTOR;
}
size = Size.of(width, height);
} else if (labelStyleDescription instanceof DotDescription) {
int width = -1;
int height = -1;
DotDescription dotDescription = (DotDescription) labelStyleDescription;
Result result = this.interpreter.evaluateExpression(variableManager.getVariables(), dotDescription.getSizeComputationExpression());
int computedSize = result.asInt().getAsInt();
if (computedSize > 0) {
width = computedSize * SIZE_FACTOR;
height = computedSize * SIZE_FACTOR;
}
size = Size.of(width, height);
}
return size;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.eclipse.sirius.diagram.business.api.query.ContainerMappingQuery;
import org.eclipse.sirius.diagram.description.AbstractNodeMapping;
import org.eclipse.sirius.diagram.description.ContainerMapping;
import org.eclipse.sirius.diagram.description.style.DotDescription;
import org.eclipse.sirius.diagram.description.style.FlatContainerStyleDescription;
import org.eclipse.sirius.diagram.description.style.SquareDescription;
import org.eclipse.sirius.diagram.description.style.StylePackage;
Expand Down Expand Up @@ -63,6 +64,9 @@ private INodeStyle getNodeStyle(VariableManager variableManager, LabelStyleDescr
} else if (nodeStyleDescription instanceof SquareDescription) {
SquareDescription squareDescription = (SquareDescription) nodeStyleDescription;
style = this.createRectangularNodeStyle(variableManager, squareDescription);
} else if (nodeStyleDescription instanceof DotDescription) {
DotDescription dotDescription = (DotDescription) nodeStyleDescription;
style = this.createRectangularNodeStyle(variableManager, dotDescription);
} else if (nodeStyleDescription instanceof FlatContainerStyleDescription) {
FlatContainerStyleDescription flatContainerStyleDescription = (FlatContainerStyleDescription) nodeStyleDescription;
if (this.abstractNodeMapping instanceof ContainerMapping && new ContainerMappingQuery((ContainerMapping) this.abstractNodeMapping).isListContainer()) {
Expand Down Expand Up @@ -197,4 +201,27 @@ private RectangularNodeStyle createRectangularNodeStyle(VariableManager variable
// @formatter:on
}

private RectangularNodeStyle createRectangularNodeStyle(VariableManager variableManager, DotDescription dotDescription) {
Map<String, Object> variables = variableManager.getVariables();
ColorDescriptionConverter colorProvider = new ColorDescriptionConverter(this.interpreter, variables);

String color = colorProvider.convert(dotDescription.getBackgroundColor());
String borderColor = colorProvider.convert(dotDescription.getBorderColor());

LineStyle borderStyle = new LineStyleConverter().getStyle(dotDescription.getBorderLineStyle());
int borderRadius = 100;
Result result = this.interpreter.evaluateExpression(variables, dotDescription.getBorderSizeComputationExpression());
int borderSize = result.asInt().getAsInt();

// @formatter:off
return RectangularNodeStyle.newRectangularNodeStyle()
.color(color)
.borderColor(borderColor)
.borderSize(borderSize)
.borderRadius(borderRadius)
.borderStyle(borderStyle)
.build();
// @formatter:on
}

}

0 comments on commit 76561a5

Please sign in to comment.