Search in sources :

Example 1 with RectangularNodeStyle

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

the class NodeExportService method export.

public StringBuilder export(Node node) {
    StringBuilder nodeExport = new StringBuilder();
    INodeStyle style = node.getStyle();
    if (style instanceof ImageNodeStyle) {
        nodeExport.append(this.exportImage(node, (ImageNodeStyle) style));
    } else if (style instanceof ListNodeStyle) {
        nodeExport.append(this.exportList(node, (ListNodeStyle) style));
    } else if (style instanceof ListItemNodeStyle) {
        nodeExport.append(this.exportListItem(node, (ListItemNodeStyle) style));
    } else if (style instanceof RectangularNodeStyle) {
        nodeExport.append(this.exportRectangle(node, (RectangularNodeStyle) style));
    }
    return nodeExport;
}
Also used : ListNodeStyle(org.eclipse.sirius.components.diagrams.ListNodeStyle) ListItemNodeStyle(org.eclipse.sirius.components.diagrams.ListItemNodeStyle) ImageNodeStyle(org.eclipse.sirius.components.diagrams.ImageNodeStyle) INodeStyle(org.eclipse.sirius.components.diagrams.INodeStyle) RectangularNodeStyle(org.eclipse.sirius.components.diagrams.RectangularNodeStyle)

Example 2 with RectangularNodeStyle

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

the class DiagramRendererNodeTests method testSimpleNodeRendering.

/**
 * Creates a diagram with a single node.
 */
@Test
public void testSimpleNodeRendering() {
    Function<VariableManager, INodeStyle> styleProvider = variableManager -> {
        // @formatter:off
        return RectangularNodeStyle.newRectangularNodeStyle().color(// $NON-NLS-1$
        "").borderColor(// $NON-NLS-1$
        "").borderSize(0).borderStyle(LineStyle.Solid).build();
    // @formatter:on
    };
    Diagram diagram = this.createDiagram(styleProvider, variableManager -> NODE_RECTANGULAR, VariableManager -> Size.UNDEFINED, Optional.empty());
    assertThat(diagram).isNotNull();
    assertThat(diagram.getId()).asString().isNotBlank();
    assertThat(diagram.getLabel()).isEqualTo(DIAGRAM_LABEL);
    assertThat(diagram.getTargetObjectId()).isNotBlank();
    assertThat(diagram.getNodes()).hasSize(1);
    assertThat(diagram.getNodes()).extracting(Node::getTargetObjectId).noneMatch(String::isBlank);
    assertThat(diagram.getNodes()).extracting(Node::getDescriptionId).noneMatch(t -> t.toString().isBlank());
    assertThat(diagram.getNodes()).extracting(Node::getType).noneMatch(String::isBlank);
    assertThat(diagram.getNodes()).extracting(Node::getType).allMatch(t -> NODE_RECTANGULAR.equals(t));
    assertThat(diagram.getNodes()).extracting(Node::getBorderNodes).allMatch(List::isEmpty);
    assertThat(diagram.getNodes()).extracting(Node::getStyle).allMatch(s -> s instanceof RectangularNodeStyle);
    assertThat(diagram.getNodes()).extracting(Node::getSize).allMatch(s -> s.getHeight() == -1 && s.getWidth() == -1);
    assertThat(diagram.getNodes()).extracting(Node::getLabel).extracting(Label::getId).allMatch(id -> UUID.nameUUIDFromBytes(LABEL_ID.getBytes()).toString().equals(id));
    assertThat(diagram.getNodes()).extracting(Node::getLabel).extracting(Label::getText).allMatch(text -> LABEL_TEXT.equals(text));
    assertThat(diagram.getNodes()).extracting(Node::getLabel).extracting(Label::getStyle).extracting(LabelStyle::getColor).allMatch(color -> LABEL_COLOR.equals(color));
    assertThat(diagram.getNodes()).extracting(Node::getLabel).extracting(Label::getStyle).extracting(LabelStyle::getFontSize).allMatch(size -> LABEL_FONT_SIZE == size);
    assertThat(diagram.getNodes()).extracting(Node::getLabel).extracting(Label::getStyle).extracting(LabelStyle::isBold).allMatch(bold -> bold);
    assertThat(diagram.getNodes()).extracting(Node::getLabel).extracting(Label::getStyle).extracting(LabelStyle::isItalic).allMatch(italic -> italic);
    assertThat(diagram.getNodes()).extracting(Node::getLabel).extracting(Label::getStyle).extracting(LabelStyle::isUnderline).allMatch(underline -> underline);
    assertThat(diagram.getNodes()).extracting(Node::getLabel).extracting(Label::getStyle).extracting(LabelStyle::isStrikeThrough).allMatch(strikeThrough -> strikeThrough);
}
Also used : VariableManager(org.eclipse.sirius.components.representations.VariableManager) LabelDescription(org.eclipse.sirius.components.diagrams.description.LabelDescription) Node(org.eclipse.sirius.components.diagrams.Node) Size(org.eclipse.sirius.components.diagrams.Size) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) DiagramDescription(org.eclipse.sirius.components.diagrams.description.DiagramDescription) 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) LineStyle(org.eclipse.sirius.components.diagrams.LineStyle) Label(org.eclipse.sirius.components.diagrams.Label) LabelStyle(org.eclipse.sirius.components.diagrams.LabelStyle) Failure(org.eclipse.sirius.components.representations.Failure) ImageNodeStyle(org.eclipse.sirius.components.diagrams.ImageNodeStyle) Success(org.eclipse.sirius.components.representations.Success) Set(java.util.Set) LabelStyleDescription(org.eclipse.sirius.components.diagrams.description.LabelStyleDescription) UUID(java.util.UUID) CustomizableProperties(org.eclipse.sirius.components.diagrams.CustomizableProperties) Element(org.eclipse.sirius.components.representations.Element) Test(org.junit.jupiter.api.Test) List(java.util.List) DiagramComponentProps(org.eclipse.sirius.components.diagrams.components.DiagramComponentProps) Optional(java.util.Optional) DiagramComponent(org.eclipse.sirius.components.diagrams.components.DiagramComponent) VariableManager(org.eclipse.sirius.components.representations.VariableManager) Node(org.eclipse.sirius.components.diagrams.Node) INodeStyle(org.eclipse.sirius.components.diagrams.INodeStyle) Label(org.eclipse.sirius.components.diagrams.Label) RectangularNodeStyle(org.eclipse.sirius.components.diagrams.RectangularNodeStyle) ArrayList(java.util.ArrayList) List(java.util.List) Diagram(org.eclipse.sirius.components.diagrams.Diagram) Test(org.junit.jupiter.api.Test)

Example 3 with RectangularNodeStyle

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

the class ContainerMappingStyleProviderTests method testFirstMatchingConditionalStyleIsUsed.

/**
 * Non-regression test for Conditional styles issue on containers.
 * <p>
 * When a mapping has several custom styles whose condition is true, the first one is selected: not the main style,
 * neither another of the matching conditional styles.
 * <p>
 * We use the border color attribute to identify which of the style candidates are actually selected
 */
@Test
public void testFirstMatchingConditionalStyleIsUsed() {
    ContainerMapping containerMapping = DescriptionFactory.eINSTANCE.createContainerMapping();
    containerMapping.setStyle(this.createFlatStyle(0, 0, 0));
    containerMapping.getConditionnalStyles().add(this.createConditionalStyle(EXPRESSION_FALSE, this.createFlatStyle(1, 1, 1)));
    containerMapping.getConditionnalStyles().add(this.createConditionalStyle(EXPRESSION_TRUE, this.createFlatStyle(2, 2, 2)));
    containerMapping.getConditionnalStyles().add(this.createConditionalStyle(EXPRESSION_TRUE, this.createFlatStyle(3, 3, 3)));
    VariableManager variableManager = new VariableManager();
    AQLInterpreter interpreter = new AQLInterpreter(List.of(), List.of(EcorePackage.eINSTANCE));
    INodeStyle nodeStyle = new AbstractNodeMappingStyleProvider(interpreter, containerMapping).apply(variableManager);
    assertThat(nodeStyle).isInstanceOf(RectangularNodeStyle.class);
    RectangularNodeStyle rectangularNodeStyle = (RectangularNodeStyle) nodeStyle;
    // $NON-NLS-1$
    assertThat(rectangularNodeStyle.getBorderColor()).isEqualTo("#020202");
}
Also used : VariableManager(org.eclipse.sirius.components.representations.VariableManager) AQLInterpreter(org.eclipse.sirius.components.interpreter.AQLInterpreter) INodeStyle(org.eclipse.sirius.components.diagrams.INodeStyle) RectangularNodeStyle(org.eclipse.sirius.components.diagrams.RectangularNodeStyle) ContainerMapping(org.eclipse.sirius.diagram.description.ContainerMapping) Test(org.junit.jupiter.api.Test)

Example 4 with RectangularNodeStyle

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

the class ContainerMappingStyleProviderTests method testBorderLineStyleConversion.

@Test
public void testBorderLineStyleConversion() {
    // @formatter:off
    var conversions = Map.of(LineStyle.DASH_DOT_LITERAL, org.eclipse.sirius.components.diagrams.LineStyle.Dash_Dot, LineStyle.DASH_LITERAL, org.eclipse.sirius.components.diagrams.LineStyle.Dash, LineStyle.DOT_LITERAL, org.eclipse.sirius.components.diagrams.LineStyle.Dot, LineStyle.SOLID_LITERAL, org.eclipse.sirius.components.diagrams.LineStyle.Solid);
    for (var entry : conversions.entrySet()) {
        ContainerMapping containerMapping = DescriptionFactory.eINSTANCE.createContainerMapping();
        ContainerStyleDescription style = this.createFlatStyle(0, 0, 0);
        style.setBorderLineStyle(entry.getKey());
        containerMapping.setStyle(style);
        VariableManager variableManager = new VariableManager();
        AQLInterpreter interpreter = new AQLInterpreter(List.of(), List.of(EcorePackage.eINSTANCE));
        INodeStyle nodeStyle = new AbstractNodeMappingStyleProvider(interpreter, containerMapping).apply(variableManager);
        assertThat(nodeStyle).isInstanceOf(RectangularNodeStyle.class);
        RectangularNodeStyle rectangularNodeStyle = (RectangularNodeStyle) nodeStyle;
        assertThat(rectangularNodeStyle.getBorderStyle()).isEqualTo(entry.getValue());
    }
}
Also used : VariableManager(org.eclipse.sirius.components.representations.VariableManager) AQLInterpreter(org.eclipse.sirius.components.interpreter.AQLInterpreter) INodeStyle(org.eclipse.sirius.components.diagrams.INodeStyle) RectangularNodeStyle(org.eclipse.sirius.components.diagrams.RectangularNodeStyle) ContainerMapping(org.eclipse.sirius.diagram.description.ContainerMapping) FlatContainerStyleDescription(org.eclipse.sirius.diagram.description.style.FlatContainerStyleDescription) ContainerStyleDescription(org.eclipse.sirius.diagram.description.style.ContainerStyleDescription) ConditionalContainerStyleDescription(org.eclipse.sirius.diagram.description.ConditionalContainerStyleDescription) Test(org.junit.jupiter.api.Test)

Example 5 with RectangularNodeStyle

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

the class NodeMappingStyleProviderTests method testBorderLineStyleConversion.

@Test
public void testBorderLineStyleConversion() {
    // @formatter:off
    var conversions = Map.of(LineStyle.DASH_DOT_LITERAL, org.eclipse.sirius.components.diagrams.LineStyle.Dash_Dot, LineStyle.DASH_LITERAL, org.eclipse.sirius.components.diagrams.LineStyle.Dash, LineStyle.DOT_LITERAL, org.eclipse.sirius.components.diagrams.LineStyle.Dot, LineStyle.SOLID_LITERAL, org.eclipse.sirius.components.diagrams.LineStyle.Solid);
    for (var entry : conversions.entrySet()) {
        NodeMapping nodeMapping = DescriptionFactory.eINSTANCE.createNodeMapping();
        NodeStyleDescription style = this.createSquareStyle(0, 0, 0);
        style.setBorderLineStyle(entry.getKey());
        nodeMapping.setStyle(style);
        VariableManager variableManager = new VariableManager();
        AQLInterpreter interpreter = new AQLInterpreter(List.of(), List.of(EcorePackage.eINSTANCE));
        INodeStyle nodeStyle = new AbstractNodeMappingStyleProvider(interpreter, nodeMapping).apply(variableManager);
        assertThat(nodeStyle).isInstanceOf(RectangularNodeStyle.class);
        RectangularNodeStyle rectangularNodeStyle = (RectangularNodeStyle) nodeStyle;
        assertThat(rectangularNodeStyle.getBorderStyle()).isEqualTo(entry.getValue());
    }
}
Also used : VariableManager(org.eclipse.sirius.components.representations.VariableManager) NodeMapping(org.eclipse.sirius.diagram.description.NodeMapping) AQLInterpreter(org.eclipse.sirius.components.interpreter.AQLInterpreter) ConditionalNodeStyleDescription(org.eclipse.sirius.diagram.description.ConditionalNodeStyleDescription) NodeStyleDescription(org.eclipse.sirius.diagram.description.style.NodeStyleDescription) INodeStyle(org.eclipse.sirius.components.diagrams.INodeStyle) RectangularNodeStyle(org.eclipse.sirius.components.diagrams.RectangularNodeStyle) Test(org.junit.jupiter.api.Test)

Aggregations

RectangularNodeStyle (org.eclipse.sirius.components.diagrams.RectangularNodeStyle)8 INodeStyle (org.eclipse.sirius.components.diagrams.INodeStyle)7 VariableManager (org.eclipse.sirius.components.representations.VariableManager)6 Test (org.junit.jupiter.api.Test)6 ImageNodeStyle (org.eclipse.sirius.components.diagrams.ImageNodeStyle)4 AQLInterpreter (org.eclipse.sirius.components.interpreter.AQLInterpreter)4 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Optional (java.util.Optional)2 Set (java.util.Set)2 UUID (java.util.UUID)2 Function (java.util.function.Function)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 CustomizableProperties (org.eclipse.sirius.components.diagrams.CustomizableProperties)2 Diagram (org.eclipse.sirius.components.diagrams.Diagram)2 Label (org.eclipse.sirius.components.diagrams.Label)2 LabelStyle (org.eclipse.sirius.components.diagrams.LabelStyle)2 LineStyle (org.eclipse.sirius.components.diagrams.LineStyle)2 Node (org.eclipse.sirius.components.diagrams.Node)2 Size (org.eclipse.sirius.components.diagrams.Size)2