Search in sources :

Example 1 with Label

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);
}
Also used : LabelDescription(org.eclipse.sirius.components.diagrams.description.LabelDescription) BeforeEach(org.junit.jupiter.api.BeforeEach) Node(org.eclipse.sirius.components.diagrams.Node) Size(org.eclipse.sirius.components.diagrams.Size) ChildModelOperationHandler(org.eclipse.sirius.components.emf.compatibility.modeloperations.ChildModelOperationHandler) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) ToolFactory(org.eclipse.sirius.viewpoint.description.tool.ToolFactory) ViewDeletionRequest(org.eclipse.sirius.components.diagrams.ViewDeletionRequest) SynchronizationPolicy(org.eclipse.sirius.components.diagrams.description.SynchronizationPolicy) Position(org.eclipse.sirius.components.diagrams.Position) 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) EditingDomainFactory(org.eclipse.sirius.components.emf.services.EditingDomainFactory) DeleteView(org.eclipse.sirius.viewpoint.description.tool.DeleteView) Diagram(org.eclipse.sirius.components.diagrams.Diagram) EditingContext(org.eclipse.sirius.components.emf.services.EditingContext) IStatus(org.eclipse.sirius.components.representations.IStatus) LineStyle(org.eclipse.sirius.components.diagrams.LineStyle) Label(org.eclipse.sirius.components.diagrams.Label) LabelStyle(org.eclipse.sirius.components.diagrams.LabelStyle) IDiagramContext(org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramContext) Failure(org.eclipse.sirius.components.representations.Failure) ImageNodeStyle(org.eclipse.sirius.components.diagrams.ImageNodeStyle) Success(org.eclipse.sirius.components.representations.Success) LabelStyleDescription(org.eclipse.sirius.components.diagrams.description.LabelStyleDescription) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test) List(java.util.List) DeleteViewOperationHandler(org.eclipse.sirius.components.emf.compatibility.modeloperations.DeleteViewOperationHandler) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) VariableManager(org.eclipse.sirius.components.representations.VariableManager) ChangeContext(org.eclipse.sirius.viewpoint.description.tool.ChangeContext) AdapterFactoryEditingDomain(org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain) AdapterFactoryEditingDomain(org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain) Node(org.eclipse.sirius.components.diagrams.Node) DeleteViewOperationHandler(org.eclipse.sirius.components.emf.compatibility.modeloperations.DeleteViewOperationHandler) ArrayList(java.util.ArrayList) DiagramDescription(org.eclipse.sirius.components.diagrams.description.DiagramDescription) ChildModelOperationHandler(org.eclipse.sirius.components.emf.compatibility.modeloperations.ChildModelOperationHandler) Diagram(org.eclipse.sirius.components.diagrams.Diagram) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) EditingContext(org.eclipse.sirius.components.emf.services.EditingContext) IDiagramContext(org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramContext) ViewDeletionRequest(org.eclipse.sirius.components.diagrams.ViewDeletionRequest) EditingDomainFactory(org.eclipse.sirius.components.emf.services.EditingDomainFactory) Failure(org.eclipse.sirius.components.representations.Failure) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with Label

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>");
}
Also used : Position(org.eclipse.sirius.components.diagrams.Position) Size(org.eclipse.sirius.components.diagrams.Size) Label(org.eclipse.sirius.components.diagrams.Label)

Example 3 with Label

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);
}
Also used : 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) VariableManager(org.eclipse.sirius.components.representations.VariableManager) Element(org.eclipse.sirius.components.representations.Element) ArrayList(java.util.ArrayList) LabelStyleDescription(org.eclipse.sirius.components.diagrams.description.LabelStyleDescription) DiagramDescription(org.eclipse.sirius.components.diagrams.description.DiagramDescription) Success(org.eclipse.sirius.components.representations.Success) LabelDescription(org.eclipse.sirius.components.diagrams.description.LabelDescription) NodeDescription(org.eclipse.sirius.components.diagrams.description.NodeDescription) Failure(org.eclipse.sirius.components.representations.Failure) DiagramComponentProps(org.eclipse.sirius.components.diagrams.components.DiagramComponentProps)

Example 4 with Label

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);
}
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 5 with Label

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

Aggregations

Label (org.eclipse.sirius.components.diagrams.Label)19 Size (org.eclipse.sirius.components.diagrams.Size)11 Node (org.eclipse.sirius.components.diagrams.Node)10 Position (org.eclipse.sirius.components.diagrams.Position)10 ArrayList (java.util.ArrayList)8 List (java.util.List)7 UUID (java.util.UUID)7 CustomizableProperties (org.eclipse.sirius.components.diagrams.CustomizableProperties)7 INodeStyle (org.eclipse.sirius.components.diagrams.INodeStyle)7 LabelDescription (org.eclipse.sirius.components.diagrams.description.LabelDescription)7 Optional (java.util.Optional)6 NodeDescription (org.eclipse.sirius.components.diagrams.description.NodeDescription)6 Element (org.eclipse.sirius.components.representations.Element)6 VariableManager (org.eclipse.sirius.components.representations.VariableManager)6 Set (java.util.Set)5 ImageNodeStyle (org.eclipse.sirius.components.diagrams.ImageNodeStyle)5 LabelStyle (org.eclipse.sirius.components.diagrams.LabelStyle)5 LineStyle (org.eclipse.sirius.components.diagrams.LineStyle)5 RectangularNodeStyle (org.eclipse.sirius.components.diagrams.RectangularNodeStyle)5 DiagramDescription (org.eclipse.sirius.components.diagrams.description.DiagramDescription)5