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;
}
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);
}
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");
}
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());
}
}
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());
}
}
Aggregations