use of org.eclipse.sirius.components.diagrams.INodeStyle 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.INodeStyle in project sirius-components by eclipse-sirius.
the class DiagramRendererNodeTests method testImageNodeRendering.
/**
* Creates a diagram with an image node.
*/
@Test
public void testImageNodeRendering() {
Function<VariableManager, INodeStyle> styleProvider = variableManager -> {
// @formatter:off
return ImageNodeStyle.newImageNodeStyle().imageURL(// $NON-NLS-1$
"test").scalingFactor(1).build();
// @formatter:on
};
Diagram diagram = this.createDiagram(styleProvider, variableManager -> NODE_IMAGE, 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_IMAGE.equals(t));
assertThat(diagram.getNodes()).extracting(Node::getBorderNodes).allMatch(List::isEmpty);
assertThat(diagram.getNodes()).extracting(Node::getStyle).allMatch(s -> s instanceof ImageNodeStyle);
// @formatter:off
assertThat(diagram.getNodes()).extracting(n -> (ImageNodeStyle) n.getStyle()).extracting(ImageNodeStyle::getImageURL).noneMatch(String::isBlank);
assertThat(diagram.getNodes()).extracting(n -> (ImageNodeStyle) n.getStyle()).extracting(ImageNodeStyle::getScalingFactor).allMatch(scalingFactor -> scalingFactor == 1);
// @formatter:on
}
use of org.eclipse.sirius.components.diagrams.INodeStyle in project sirius-components by eclipse-sirius.
the class UnsynchronizedDiagramTests method getDiagramDescription.
private DiagramDescription getDiagramDescription() {
// @formatter:off
LabelStyleDescription labelStyleDescription = LabelStyleDescription.newLabelStyleDescription().italicProvider(VariableManager -> true).boldProvider(VariableManager -> true).underlineProvider(VariableManager -> true).strikeThroughProvider(VariableManager -> true).colorProvider(// $NON-NLS-1$
VariableManager -> "#FFFFFF").fontSizeProvider(variableManager -> 10).iconURLProvider(// $NON-NLS-1$
VariableManager -> "").build();
LabelDescription labelDescription = // $NON-NLS-1$
LabelDescription.newLabelDescription("labelDescriptionId").idProvider(// $NON-NLS-1$
variableManager -> "labelid").textProvider(// $NON-NLS-1$
variableManager -> "label").styleDescriptionProvider(variableManager -> labelStyleDescription).build();
Function<VariableManager, INodeStyle> styleProvider = variableManager -> {
return RectangularNodeStyle.newRectangularNodeStyle().color(// $NON-NLS-1$
"").borderColor(// $NON-NLS-1$
"").borderSize(0).borderStyle(LineStyle.Solid).build();
};
NodeDescription subUnsynchronizedNodeDescription = // $NON-NLS-1$
NodeDescription.newNodeDescription(UUID.nameUUIDFromBytes("subUnsynchronized".getBytes())).synchronizationPolicy(SynchronizationPolicy.UNSYNCHRONIZED).typeProvider(variableManager -> NODE_TYPE).semanticElementsProvider(variableManager -> List.of(new Object())).targetObjectIdProvider(variableManager -> TARGET_OBJECT_ID).targetObjectKindProvider(// $NON-NLS-1$
variableManager -> "").targetObjectLabelProvider(// $NON-NLS-1$
variableManager -> "").labelDescription(labelDescription).styleProvider(styleProvider).sizeProvider(variableManager -> Size.UNDEFINED).borderNodeDescriptions(new ArrayList<>()).childNodeDescriptions(new ArrayList<>()).labelEditHandler((variableManager, newLabel) -> new Success()).deleteHandler(variableManager -> new Success()).build();
NodeDescription unsynchronizedNodeDescription = // $NON-NLS-1$
NodeDescription.newNodeDescription(UUID.nameUUIDFromBytes("unsynchronized".getBytes())).synchronizationPolicy(SynchronizationPolicy.UNSYNCHRONIZED).typeProvider(variableManager -> NODE_TYPE).semanticElementsProvider(variableManager -> List.of(new Object())).targetObjectIdProvider(variableManager -> TARGET_OBJECT_ID).targetObjectKindProvider(// $NON-NLS-1$
variableManager -> "").targetObjectLabelProvider(// $NON-NLS-1$
variableManager -> "").labelDescription(labelDescription).styleProvider(styleProvider).sizeProvider(variableManager -> Size.UNDEFINED).borderNodeDescriptions(new ArrayList<>()).childNodeDescriptions(List.of(subUnsynchronizedNodeDescription)).labelEditHandler((variableManager, newLabel) -> new Success()).deleteHandler(variableManager -> new Success()).build();
NodeDescription synchronizedNodeDescription = // $NON-NLS-1$
NodeDescription.newNodeDescription(UUID.nameUUIDFromBytes("synchronized".getBytes())).synchronizationPolicy(SynchronizationPolicy.SYNCHRONIZED).typeProvider(variableManager -> NODE_TYPE).semanticElementsProvider(variableManager -> List.of(new Object())).targetObjectIdProvider(variableManager -> TARGET_OBJECT_ID).targetObjectKindProvider(// $NON-NLS-1$
variableManager -> "").targetObjectLabelProvider(// $NON-NLS-1$
variableManager -> "").labelDescription(labelDescription).styleProvider(styleProvider).sizeProvider(variableManager -> Size.UNDEFINED).borderNodeDescriptions(new ArrayList<>()).childNodeDescriptions(new ArrayList<>()).labelEditHandler((variableManager, newLabel) -> new Success()).deleteHandler(variableManager -> new Success()).build();
DiagramDescription diagramDescription = // $NON-NLS-1$
DiagramDescription.newDiagramDescription(UUID.nameUUIDFromBytes("diagram".getBytes())).label(// $NON-NLS-1$
"").canCreatePredicate(variableManager -> true).targetObjectIdProvider(// $NON-NLS-1$
variableManager -> "diagramTargetObjectId").labelProvider(// $NON-NLS-1$
variableManager -> "label").nodeDescriptions(List.of(unsynchronizedNodeDescription, synchronizedNodeDescription)).edgeDescriptions(List.of()).toolSections(List.of()).dropHandler(// $NON-NLS-1$
variableManager -> new Failure("")).build();
return diagramDescription;
}
use of org.eclipse.sirius.components.diagrams.INodeStyle in project sirius-components by eclipse-sirius.
the class TestDiagramDescriptionBuilder method getNodeDescription.
public NodeDescription getNodeDescription(UUID nodeDescriptionId, Function<VariableManager, List<?>> semanticElementsProvider) {
// @formatter:off
LabelStyleDescription labelStyleDescription = LabelStyleDescription.newLabelStyleDescription().colorProvider(// $NON-NLS-1$
variableManager -> "#000000").fontSizeProvider(variableManager -> 16).boldProvider(variableManager -> false).italicProvider(variableManager -> false).underlineProvider(variableManager -> false).strikeThroughProvider(variableManager -> false).iconURLProvider(// $NON-NLS-1$
variableManager -> "").build();
LabelDescription labelDescription = // $NON-NLS-1$
LabelDescription.newLabelDescription("labelDescriptionId").idProvider(// $NON-NLS-1$
variableManager -> "labelId").textProvider(// $NON-NLS-1$
variableManager -> "Node").styleDescriptionProvider(variableManager -> labelStyleDescription).build();
Function<VariableManager, INodeStyle> nodeStyleProvider = variableManager -> {
return RectangularNodeStyle.newRectangularNodeStyle().color(// $NON-NLS-1$
"").borderColor(// $NON-NLS-1$
"").borderSize(0).borderStyle(LineStyle.Solid).build();
};
Function<VariableManager, String> idProvider = variableManager -> {
Object object = variableManager.getVariables().get(VariableManager.SELF);
if (object instanceof String) {
return this.getNodeId(nodeDescriptionId, (String) object);
}
return null;
};
return NodeDescription.newNodeDescription(nodeDescriptionId).typeProvider(// $NON-NLS-1$
variableManager -> "").semanticElementsProvider(semanticElementsProvider).targetObjectIdProvider(idProvider).targetObjectKindProvider(// $NON-NLS-1$
variableManager -> "").targetObjectLabelProvider(// $NON-NLS-1$
variableManager -> "").labelDescription(labelDescription).styleProvider(nodeStyleProvider).sizeProvider(variableManager -> Size.UNDEFINED).borderNodeDescriptions(new ArrayList<>()).childNodeDescriptions(new ArrayList<>()).labelEditHandler((variableManager, newLabel) -> new Success()).deleteHandler(variableManager -> new Success()).build();
// @formatter:on
}
use of org.eclipse.sirius.components.diagrams.INodeStyle in project sirius-components by eclipse-sirius.
the class RectangleNodeBuilder method build.
@Override
public Node build(Map<String, String> targetObjectIdToNodeId) {
List<Node> borderNodes = Optional.ofNullable(this.borderNodesBuilder).map(nodesBuilder -> nodesBuilder.build(targetObjectIdToNodeId)).orElse(List.of());
List<Node> childNodes = Optional.ofNullable(this.childNodesBuilder).map(nodesBuilder -> nodesBuilder.build(targetObjectIdToNodeId)).orElse(List.of());
// @formatter:off
INodeStyle style = RectangularNodeStyle.newRectangularNodeStyle().color(// $NON-NLS-1$
"#E5F5F8").borderColor(// $NON-NLS-1$
"#33B0C3").borderSize(1).borderRadius(3).borderStyle(LineStyle.Solid).build();
// @formatter:on
String labeltext = this.label.getText();
String nodeId = UUID.randomUUID().toString();
targetObjectIdToNodeId.put(labeltext, nodeId);
UUID descriptionId = TestLayoutDiagramBuilder.NODE_DESCRIPTION_ID;
if (this.nodesBuilder.and() instanceof NodeBuilder) {
descriptionId = TestLayoutDiagramBuilder.CHILD_NODE_DESCRIPTION_ID;
}
// @formatter:off
return Node.newNode(nodeId).type(NodeType.NODE_RECTANGLE).label(this.label).position(Objects.requireNonNull(this.position)).size(Objects.requireNonNull(this.size)).borderNode(this.borderNode).borderNodes(borderNodes).childNodes(childNodes).customizedProperties(this.customizedProperties).descriptionId(descriptionId).targetObjectId(labeltext).targetObjectKind(// $NON-NLS-1$
"").targetObjectLabel(this.label.getText()).style(Objects.requireNonNull(style)).build();
// @formatter:on
}
Aggregations