Search in sources :

Example 1 with LineStyle

use of org.eclipse.sirius.components.diagrams.LineStyle in project sirius-components by eclipse-sirius.

the class AbstractNodeMappingStyleProvider method createRectangularNodeStyle.

private RectangularNodeStyle createRectangularNodeStyle(VariableManager variableManager, FlatContainerStyleDescription flatContainerStyleDescription) {
    Map<String, Object> variables = variableManager.getVariables();
    ColorDescriptionConverter colorProvider = new ColorDescriptionConverter(this.interpreter, variables);
    String color = colorProvider.convert(flatContainerStyleDescription.getBackgroundColor());
    String borderColor = colorProvider.convert(flatContainerStyleDescription.getBorderColor());
    LineStyle borderStyle = new LineStyleConverter().getStyle(flatContainerStyleDescription.getBorderLineStyle());
    int borderRadius = this.getBorderRadius(flatContainerStyleDescription);
    Result result = this.interpreter.evaluateExpression(variables, flatContainerStyleDescription.getBorderSizeComputationExpression());
    int borderSize = result.asInt().getAsInt();
    // @formatter:off
    return RectangularNodeStyle.newRectangularNodeStyle().color(color).borderColor(borderColor).borderSize(borderSize).borderRadius(borderRadius).borderStyle(borderStyle).build();
// @formatter:on
}
Also used : LineStyle(org.eclipse.sirius.components.diagrams.LineStyle) Result(org.eclipse.sirius.components.interpreter.Result)

Example 2 with LineStyle

use of org.eclipse.sirius.components.diagrams.LineStyle in project sirius-components by eclipse-sirius.

the class AbstractNodeMappingStyleProvider method createRectangularNodeStyle.

private RectangularNodeStyle createRectangularNodeStyle(VariableManager variableManager, SquareDescription squareDescription) {
    ColorDescriptionConverter colorProvider = new ColorDescriptionConverter(this.interpreter, variableManager.getVariables());
    String color = colorProvider.convert(squareDescription.getColor());
    String borderColor = colorProvider.convert(squareDescription.getBorderColor());
    LineStyle borderStyle = new LineStyleConverter().getStyle(squareDescription.getBorderLineStyle());
    Result result = this.interpreter.evaluateExpression(variableManager.getVariables(), squareDescription.getBorderSizeComputationExpression());
    int borderSize = result.asInt().getAsInt();
    // @formatter:off
    return RectangularNodeStyle.newRectangularNodeStyle().color(color).borderColor(borderColor).borderSize(borderSize).borderStyle(borderStyle).build();
// @formatter:on
}
Also used : LineStyle(org.eclipse.sirius.components.diagrams.LineStyle) Result(org.eclipse.sirius.components.interpreter.Result)

Example 3 with LineStyle

use of org.eclipse.sirius.components.diagrams.LineStyle in project sirius-components by eclipse-sirius.

the class AbstractNodeMappingStyleProvider method createRectangularNodeStyle.

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
}
Also used : LineStyle(org.eclipse.sirius.components.diagrams.LineStyle) Result(org.eclipse.sirius.components.interpreter.Result)

Example 4 with LineStyle

use of org.eclipse.sirius.components.diagrams.LineStyle in project sirius-components by eclipse-sirius.

the class DiagramRendererEdgeTests method getEdgeDescription.

private EdgeDescription getEdgeDescription(NodeDescription nodeDescription, UUID id) {
    // @formatter:off
    Function<VariableManager, List<Element>> sourceNodesProvider = variableManager -> {
        var optionalCache = variableManager.get(DiagramDescription.CACHE, DiagramRenderingCache.class);
        Map<Object, List<Element>> objectToNodes = optionalCache.map(DiagramRenderingCache::getObjectToNodes).orElse(new HashMap<>());
        List<Element> sourceNodes = objectToNodes.get(FIRST_OBJECT_ID).stream().filter(node -> ((NodeElementProps) node.getProps()).getDescriptionId().equals(nodeDescription.getId())).filter(Objects::nonNull).collect(Collectors.toList());
        return sourceNodes;
    };
    Function<VariableManager, List<Element>> targetNodesProvider = variableManager -> {
        var optionalCache = variableManager.get(DiagramDescription.CACHE, DiagramRenderingCache.class);
        Map<Object, List<Element>> objectToNodes = optionalCache.map(DiagramRenderingCache::getObjectToNodes).orElse(new HashMap<>());
        List<Element> targetNodes = objectToNodes.get(SECOND_OBJECT_ID).stream().filter(node -> ((NodeElementProps) node.getProps()).getDescriptionId().equals(nodeDescription.getId())).filter(Objects::nonNull).collect(Collectors.toList());
        return targetNodes;
    };
    Function<VariableManager, EdgeStyle> edgeStyleProvider = variableManager -> {
        return EdgeStyle.newEdgeStyle().size(2).lineStyle(LineStyle.Dash_Dot).sourceArrow(ArrowStyle.InputArrowWithDiamond).targetArrow(ArrowStyle.None).color(// $NON-NLS-1$
        "rgb(1, 2, 3)").build();
    };
    Function<VariableManager, String> idProvider = variableManager -> {
        return variableManager.get(VariableManager.SELF, String.class).orElse(null);
    };
    return EdgeDescription.newEdgeDescription(id).semanticElementsProvider(variableManager -> List.of(FIRST_OBJECT_ID)).sourceNodesProvider(sourceNodesProvider).targetNodesProvider(targetNodesProvider).sourceNodeDescriptions(List.of(nodeDescription)).targetNodeDescriptions(List.of(nodeDescription)).targetObjectIdProvider(idProvider).targetObjectKindProvider(// $NON-NLS-1$
    variableManager -> "").targetObjectLabelProvider(// $NON-NLS-1$
    variableManager -> "").styleProvider(edgeStyleProvider).deleteHandler(// $NON-NLS-1$
    variableManager -> new Failure("")).labelEditHandler(// $NON-NLS-1$
    (variableManager, newLabel) -> new Failure("")).build();
// @formatter:on
}
Also used : VariableManager(org.eclipse.sirius.components.representations.VariableManager) Edge(org.eclipse.sirius.components.diagrams.Edge) LabelDescription(org.eclipse.sirius.components.diagrams.description.LabelDescription) Node(org.eclipse.sirius.components.diagrams.Node) Size(org.eclipse.sirius.components.diagrams.Size) ArrowStyle(org.eclipse.sirius.components.diagrams.ArrowStyle) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) DiagramDescription(org.eclipse.sirius.components.diagrams.description.DiagramDescription) HashMap(java.util.HashMap) INodeStyle(org.eclipse.sirius.components.diagrams.INodeStyle) Function(java.util.function.Function) NodeDescription(org.eclipse.sirius.components.diagrams.description.NodeDescription) ArrayList(java.util.ArrayList) RectangularNodeStyle(org.eclipse.sirius.components.diagrams.RectangularNodeStyle) Diagram(org.eclipse.sirius.components.diagrams.Diagram) Map(java.util.Map) LineStyle(org.eclipse.sirius.components.diagrams.LineStyle) EdgeStyle(org.eclipse.sirius.components.diagrams.EdgeStyle) Failure(org.eclipse.sirius.components.representations.Failure) Success(org.eclipse.sirius.components.representations.Success) LabelStyleDescription(org.eclipse.sirius.components.diagrams.description.LabelStyleDescription) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Element(org.eclipse.sirius.components.representations.Element) Objects(java.util.Objects) Test(org.junit.jupiter.api.Test) List(java.util.List) EdgeDescription(org.eclipse.sirius.components.diagrams.description.EdgeDescription) DiagramComponentProps(org.eclipse.sirius.components.diagrams.components.DiagramComponentProps) NodeElementProps(org.eclipse.sirius.components.diagrams.elements.NodeElementProps) Optional(java.util.Optional) DiagramComponent(org.eclipse.sirius.components.diagrams.components.DiagramComponent) VariableManager(org.eclipse.sirius.components.representations.VariableManager) HashMap(java.util.HashMap) Element(org.eclipse.sirius.components.representations.Element) Objects(java.util.Objects) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) EdgeStyle(org.eclipse.sirius.components.diagrams.EdgeStyle) Failure(org.eclipse.sirius.components.representations.Failure)

Example 5 with LineStyle

use of org.eclipse.sirius.components.diagrams.LineStyle in project sirius-components by eclipse-sirius.

the class WorkspaceImageDescriptionConverter method convert.

public ImageNodeStyle convert() {
    // @formatter:off
    String workspacePath = this.eAttributeCustomizationProvider.getEAttributeCustomization(this.workspaceImageDescription, WORKSPACE_PATH).map(EAttributeCustomization::getValue).flatMap(expression -> this.interpreter.evaluateExpression(this.variableManager.getVariables(), expression).asString()).orElse(this.workspaceImageDescription.getWorkspacePath());
    // @formatter:on
    Result scalingFactorResult = this.interpreter.evaluateExpression(this.variableManager.getVariables(), this.workspaceImageDescription.getSizeComputationExpression());
    int scalingFactor = scalingFactorResult.asInt().orElse(DEFAULT_SCALING_FACTOR);
    ColorDescriptionConverter colorDescriptionConverter = new ColorDescriptionConverter(this.interpreter, this.variableManager.getVariables());
    String borderColor = colorDescriptionConverter.convert(this.workspaceImageDescription.getBorderColor());
    LineStyle borderStyle = new LineStyleConverter().getStyle(this.workspaceImageDescription.getBorderLineStyle());
    int borderRadius = this.getBorderRadius(this.workspaceImageDescription);
    Result result = this.interpreter.evaluateExpression(this.variableManager.getVariables(), this.workspaceImageDescription.getBorderSizeComputationExpression());
    int borderSize = result.asInt().getAsInt();
    // @formatter:off
    return ImageNodeStyle.newImageNodeStyle().imageURL(workspacePath.substring(workspacePath.indexOf('/', 1))).scalingFactor(scalingFactor).borderColor(borderColor).borderRadius(borderRadius).borderSize(borderSize).borderStyle(borderStyle).build();
// @formatter:on
}
Also used : Objects(java.util.Objects) StylePackage(org.eclipse.sirius.diagram.description.style.StylePackage) ImageNodeStyle(org.eclipse.sirius.components.diagrams.ImageNodeStyle) LineStyle(org.eclipse.sirius.components.diagrams.LineStyle) ContainerStyleDescription(org.eclipse.sirius.diagram.description.style.ContainerStyleDescription) Result(org.eclipse.sirius.components.interpreter.Result) VariableManager(org.eclipse.sirius.components.representations.VariableManager) EAttributeCustomization(org.eclipse.sirius.viewpoint.description.EAttributeCustomization) AQLInterpreter(org.eclipse.sirius.components.interpreter.AQLInterpreter) WorkspaceImageDescription(org.eclipse.sirius.diagram.description.style.WorkspaceImageDescription) LineStyle(org.eclipse.sirius.components.diagrams.LineStyle) EAttributeCustomization(org.eclipse.sirius.viewpoint.description.EAttributeCustomization) Result(org.eclipse.sirius.components.interpreter.Result)

Aggregations

LineStyle (org.eclipse.sirius.components.diagrams.LineStyle)8 Result (org.eclipse.sirius.components.interpreter.Result)5 ArrowStyle (org.eclipse.sirius.components.diagrams.ArrowStyle)3 VariableManager (org.eclipse.sirius.components.representations.VariableManager)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Objects (java.util.Objects)2 UUID (java.util.UUID)2 Function (java.util.function.Function)2 EdgeStyle (org.eclipse.sirius.components.diagrams.EdgeStyle)2 INodeStyle (org.eclipse.sirius.components.diagrams.INodeStyle)2 RectangularNodeStyle (org.eclipse.sirius.components.diagrams.RectangularNodeStyle)2 Size (org.eclipse.sirius.components.diagrams.Size)2 DiagramDescription (org.eclipse.sirius.components.diagrams.description.DiagramDescription)2 EdgeDescription (org.eclipse.sirius.components.diagrams.description.EdgeDescription)2 LabelDescription (org.eclipse.sirius.components.diagrams.description.LabelDescription)2 LabelStyleDescription (org.eclipse.sirius.components.diagrams.description.LabelStyleDescription)2 NodeDescription (org.eclipse.sirius.components.diagrams.description.NodeDescription)2 Element (org.eclipse.sirius.components.representations.Element)2 Failure (org.eclipse.sirius.components.representations.Failure)2