use of org.eclipse.sirius.components.diagrams.Label in project sirius-components by eclipse-sirius.
the class DeleteViewOperationHandlerTests method initialize.
@BeforeEach
public void initialize() {
this.operationTestContext = new OperationTestContext();
// @formatter:off
DiagramDescription diagramDescription = DiagramDescription.newDiagramDescription(UUID.randomUUID()).label(// $NON-NLS-1$
"DiagramDescriptionTest").targetObjectIdProvider(// $NON-NLS-1$
variableManager -> "diagramTargetObjectId").canCreatePredicate(variableManager -> true).labelProvider(// $NON-NLS-1$
variableManager -> "Diagram").toolSections(List.of()).nodeDescriptions(List.of(this.getNodeDescription(UUID.randomUUID()))).edgeDescriptions(List.of()).dropHandler(// $NON-NLS-1$
variableManager -> new Failure("")).build();
Node node = Node.newNode(UUID.randomUUID().toString()).descriptionId(UUID.randomUUID()).type(// $NON-NLS-1$
"Node").targetObjectId(UUID.randomUUID().toString()).targetObjectKind(// $NON-NLS-1$
"ecore::EPackage").targetObjectLabel(OperationTestContext.ROOT_PACKAGE_NAME).label(Label.newLabel(UUID.randomUUID().toString()).type(// $NON-NLS-1$
"Label").text(OperationTestContext.ROOT_PACKAGE_NAME).position(Position.at(0, 0)).size(Size.of(10, 10)).alignment(Position.at(0, 0)).style(// $NON-NLS-1$ //$NON-NLS-2$
LabelStyle.newLabelStyle().color("").fontSize(0).iconURL("").build()).build()).style(// $NON-NLS-1$
ImageNodeStyle.newImageNodeStyle().imageURL("").scalingFactor(0).build()).position(Position.at(0, 0)).size(Size.of(10, 10)).borderNodes(List.of()).childNodes(List.of()).build();
Diagram diagram = Diagram.newDiagram(UUID.randomUUID().toString()).descriptionId(diagramDescription.getId()).targetObjectId(UUID.randomUUID().toString()).label(// $NON-NLS-1$
"DiagramTest").position(Position.at(0, 0)).size(Size.of(100, 100)).nodes(List.of(node)).edges(List.of()).build();
IDiagramContext diagramContext = new IDiagramContext.NoOp() {
@Override
public List<ViewDeletionRequest> getViewDeletionRequests() {
return new ArrayList<>();
}
};
this.operationTestContext.getVariables().put(IDiagramContext.DIAGRAM_CONTEXT, diagramContext);
// @formatter:on
AdapterFactoryEditingDomain editingDomain = new EditingDomainFactory().create();
EditingContext editingContext = new EditingContext(UUID.randomUUID().toString(), editingDomain);
this.operationTestContext.getVariables().put(IEditingContext.EDITING_CONTEXT, editingContext);
this.operationTestContext.getVariables().put(CONTAINER_VIEW, diagram);
this.operationTestContext.getVariables().put(VariableManager.SELF, diagram.getNodes().get(0));
this.deleteViewOperation = ToolFactory.eINSTANCE.createDeleteView();
this.deleteViewOperationHandler = new DeleteViewOperationHandler(this.operationTestContext.getObjectService(), this.operationTestContext.getRepresentationMetadataSearchService(), this.operationTestContext.getIdentifierProvider(), this.operationTestContext.getInterpreter(), new ChildModelOperationHandler(List.of()), this.deleteViewOperation);
}
use of org.eclipse.sirius.components.diagrams.Label in project sirius-components by eclipse-sirius.
the class NodeExportService method exportImage.
private StringBuilder exportImage(Node node, ImageNodeStyle style) {
StringBuilder imageExport = new StringBuilder();
Size size = node.getSize();
Label label = node.getLabel();
imageExport.append(this.elementExport.exportGNodeElement(node));
// adapt the size and position to show the full width of the border
Size imageSize = Size.of(node.getSize().getWidth() + style.getBorderSize(), node.getSize().getHeight() + style.getBorderSize());
Position position = Position.at(-style.getBorderSize() / 2., -style.getBorderSize() / 2.);
imageExport.append(this.elementExport.exportRectangleElement(imageSize, position, Optional.of(style.getBorderRadius()), Optional.empty(), Optional.of(style.getBorderColor()), Optional.of(style.getBorderSize()), Optional.of(style.getBorderStyle())));
imageExport.append(this.elementExport.exportImageElement(style.getImageURL(), 0, 0, Optional.of(size)));
imageExport.append(this.elementExport.exportLabel(label));
imageExport.append(this.exportChildren(node));
// $NON-NLS-1$
return imageExport.append("</g>");
}
use of org.eclipse.sirius.components.diagrams.Label in project sirius-components by eclipse-sirius.
the class DiagramRendererNodeTests method createDiagram.
/**
* Create a diagram with one element that match with the given styleProvider/typeProvider.
*/
private Diagram createDiagram(Function<VariableManager, INodeStyle> styleProvider, Function<VariableManager, String> typeProvider, Function<VariableManager, Size> sizeProvider, Optional<Diagram> previousDiagram) {
// @formatter:off
LabelStyleDescription labelStyleDescription = LabelStyleDescription.newLabelStyleDescription().italicProvider(VariableManager -> true).boldProvider(VariableManager -> true).underlineProvider(VariableManager -> true).strikeThroughProvider(VariableManager -> true).colorProvider(VariableManager -> LABEL_COLOR).fontSizeProvider(variableManager -> LABEL_FONT_SIZE).iconURLProvider(// $NON-NLS-1$
VariableManager -> "").build();
LabelDescription labelDescription = // $NON-NLS-1$
LabelDescription.newLabelDescription("labelDescriptionId").idProvider(variableManager -> LABEL_ID).textProvider(variableManager -> LABEL_TEXT).styleDescriptionProvider(variableManager -> labelStyleDescription).build();
NodeDescription nodeDescription = NodeDescription.newNodeDescription(NODE_DESCRIPTION_ID).typeProvider(typeProvider).semanticElementsProvider(variableManager -> List.of(new Object())).targetObjectIdProvider(// $NON-NLS-1$
variableManager -> "targetObjectId").targetObjectKindProvider(// $NON-NLS-1$
variableManager -> "").targetObjectLabelProvider(// $NON-NLS-1$
variableManager -> "").labelDescription(labelDescription).styleProvider(styleProvider).sizeProvider(sizeProvider).borderNodeDescriptions(new ArrayList<>()).childNodeDescriptions(new ArrayList<>()).labelEditHandler((variableManager, newLabel) -> new Success()).deleteHandler(variableManager -> new Success()).build();
DiagramDescription diagramDescription = DiagramDescription.newDiagramDescription(UUID.randomUUID()).label(// $NON-NLS-1$
"").canCreatePredicate(variableManager -> true).targetObjectIdProvider(// $NON-NLS-1$
variableManager -> "diagramTargetObjectId").labelProvider(variableManager -> DIAGRAM_LABEL).nodeDescriptions(List.of(nodeDescription)).edgeDescriptions(new ArrayList<>()).toolSections(List.of()).dropHandler(// $NON-NLS-1$
variableManager -> new Failure("")).build();
// @formatter:on
VariableManager variableManager = new VariableManager();
// @formatter:off
DiagramComponentProps props = DiagramComponentProps.newDiagramComponentProps().variableManager(variableManager).diagramDescription(diagramDescription).viewCreationRequests(List.of()).viewDeletionRequests(List.of()).previousDiagram(previousDiagram).build();
// @formatter:on
Element element = new Element(DiagramComponent.class, props);
return new DiagramRenderer().render(element);
}
use of org.eclipse.sirius.components.diagrams.Label 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.Label in project sirius-components by eclipse-sirius.
the class TestDiagramBuilder method getNode.
public Node getNode(String id) {
// @formatter:off
LabelStyle labelStyle = LabelStyle.newLabelStyle().color(// $NON-NLS-1$
"#000000").fontSize(16).iconURL(// $NON-NLS-1$
"").build();
Label label = Label.newLabel(UUID.randomUUID().toString()).type(// $NON-NLS-1$
"labelType").text(// $NON-NLS-1$
"text").position(Position.UNDEFINED).size(Size.UNDEFINED).alignment(Position.UNDEFINED).style(labelStyle).build();
return Node.newNode(id).type(NodeType.NODE_RECTANGLE).targetObjectId(// $NON-NLS-1$
"nodeTargetObjectId").targetObjectKind(// $NON-NLS-1$
"").targetObjectLabel(// $NON-NLS-1$
"").descriptionId(UUID.randomUUID()).label(label).style(this.getRectangularNodeStyle()).position(Position.UNDEFINED).size(Size.UNDEFINED).borderNodes(List.of()).childNodes(List.of()).build();
// @formatter:on
}
Aggregations