Search in sources :

Example 1 with ImageNodeStyle

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

the class AbstractNodeMappingConverter method convert.

public NodeDescription convert(AbstractNodeMapping abstractNodeMapping, AQLInterpreter interpreter, Map<UUID, NodeDescription> id2NodeDescriptions) {
    LabelStyleDescriptionConverter labelStyleDescriptionConverter = new LabelStyleDescriptionConverter(interpreter, this.objectService);
    Function<VariableManager, org.eclipse.sirius.viewpoint.description.style.LabelStyleDescription> abstractNodeMappingDescriptionProvider = new LabelStyleDescriptionProvider(interpreter, abstractNodeMapping);
    Function<VariableManager, String> labelIdProvider = this.getLabelIdProvider();
    Function<VariableManager, String> labelExpressionProvider = this.getLabelExpressionProvider(interpreter, abstractNodeMappingDescriptionProvider);
    Function<VariableManager, LabelStyleDescription> labelStyleDescriptionProvider = this.getLabelStyleDescriptionProvider(labelStyleDescriptionConverter, abstractNodeMappingDescriptionProvider);
    // @formatter:off
    LabelDescription labelDescription = LabelDescription.newLabelDescription(this.identifierProvider.getIdentifier(abstractNodeMapping) + LabelDescription.LABEL_SUFFIX).idProvider(labelIdProvider).textProvider(labelExpressionProvider).styleDescriptionProvider(labelStyleDescriptionProvider).build();
    // @formatter:on
    Function<VariableManager, String> semanticTargetIdProvider = variableManager -> {
        return variableManager.get(VariableManager.SELF, Object.class).map(this.objectService::getId).orElse(null);
    };
    Function<VariableManager, String> semanticTargetKindProvider = variableManager -> {
        return variableManager.get(VariableManager.SELF, Object.class).map(this.objectService::getKind).orElse(null);
    };
    Function<VariableManager, String> semanticTargetLabelProvider = variableManager -> {
        return variableManager.get(VariableManager.SELF, Object.class).map(this.objectService::getLabel).orElse(null);
    };
    Function<VariableManager, INodeStyle> styleProvider = new AbstractNodeMappingStyleProvider(interpreter, abstractNodeMapping);
    Function<VariableManager, String> typeProvider = variableManager -> {
        var result = NodeType.NODE_RECTANGLE;
        INodeStyle style = styleProvider.apply(variableManager);
        if (style instanceof ImageNodeStyle) {
            result = NodeType.NODE_IMAGE;
        } else if (style instanceof ListItemNodeStyle) {
            result = NodeType.NODE_LIST_ITEM;
        } else if (style instanceof ListNodeStyle) {
            result = NodeType.NODE_LIST;
        }
        return result;
    };
    AbstractNodeMappingSizeProvider sizeProvider = new AbstractNodeMappingSizeProvider(interpreter, abstractNodeMapping);
    String domainClass = abstractNodeMapping.getDomainClass();
    String semanticCandidatesExpression = abstractNodeMapping.getSemanticCandidatesExpression();
    String preconditionExpression = abstractNodeMapping.getPreconditionExpression();
    Function<VariableManager, List<?>> semanticElementsProvider = this.semanticCandidatesProviderFactory.getSemanticCandidatesProvider(interpreter, domainClass, semanticCandidatesExpression, preconditionExpression);
    List<NodeDescription> childNodeDescriptions = this.getChildNodeDescriptions(abstractNodeMapping, interpreter, id2NodeDescriptions);
    // @formatter:off
    List<NodeDescription> borderNodeDescriptions = abstractNodeMapping.getBorderedNodeMappings().stream().map(borderNodeMapping -> this.convert(borderNodeMapping, interpreter, id2NodeDescriptions)).collect(Collectors.toList());
    // @formatter:on
    ToolConverter toolConverter = new ToolConverter(interpreter, this.editService, this.modelOperationHandlerSwitchProvider);
    var deleteHandler = toolConverter.createDeleteToolHandler(abstractNodeMapping.getDeletionDescription());
    var labelEditHandler = toolConverter.createDirectEditToolHandler(abstractNodeMapping.getLabelDirectEdit());
    SynchronizationPolicy synchronizationPolicy = SynchronizationPolicy.SYNCHRONIZED;
    if (!abstractNodeMapping.isCreateElements()) {
        synchronizationPolicy = SynchronizationPolicy.UNSYNCHRONIZED;
    }
    // @formatter:off
    NodeDescription description = NodeDescription.newNodeDescription(UUID.fromString(this.identifierProvider.getIdentifier(abstractNodeMapping))).typeProvider(typeProvider).targetObjectIdProvider(semanticTargetIdProvider).targetObjectKindProvider(semanticTargetKindProvider).targetObjectLabelProvider(semanticTargetLabelProvider).semanticElementsProvider(semanticElementsProvider).synchronizationPolicy(synchronizationPolicy).labelDescription(labelDescription).styleProvider(styleProvider).sizeProvider(sizeProvider).borderNodeDescriptions(borderNodeDescriptions).childNodeDescriptions(childNodeDescriptions).labelEditHandler(labelEditHandler).deleteHandler(deleteHandler).build();
    // @formatter:on
    id2NodeDescriptions.put(description.getId(), description);
    return description;
}
Also used : VariableManager(org.eclipse.sirius.components.representations.VariableManager) LabelDescription(org.eclipse.sirius.components.diagrams.description.LabelDescription) IObjectService(org.eclipse.sirius.components.core.api.IObjectService) SynchronizationPolicy(org.eclipse.sirius.components.diagrams.description.SynchronizationPolicy) AbstractNodeMapping(org.eclipse.sirius.diagram.description.AbstractNodeMapping) INodeStyle(org.eclipse.sirius.components.diagrams.INodeStyle) Function(java.util.function.Function) NodeDescription(org.eclipse.sirius.components.diagrams.description.NodeDescription) ArrayList(java.util.ArrayList) ListNodeStyle(org.eclipse.sirius.components.diagrams.ListNodeStyle) StringValueProvider(org.eclipse.sirius.components.compatibility.utils.StringValueProvider) Service(org.springframework.stereotype.Service) Map(java.util.Map) ISemanticCandidatesProviderFactory(org.eclipse.sirius.components.compatibility.api.ISemanticCandidatesProviderFactory) ContainerMapping(org.eclipse.sirius.diagram.description.ContainerMapping) BasicLabelStyleDescription(org.eclipse.sirius.viewpoint.description.style.BasicLabelStyleDescription) IEditService(org.eclipse.sirius.components.core.api.IEditService) StyleFactory(org.eclipse.sirius.viewpoint.description.style.StyleFactory) IModelOperationHandlerSwitchProvider(org.eclipse.sirius.components.compatibility.api.IModelOperationHandlerSwitchProvider) ImageNodeStyle(org.eclipse.sirius.components.diagrams.ImageNodeStyle) ListItemNodeStyle(org.eclipse.sirius.components.diagrams.ListItemNodeStyle) LabelStyleDescription(org.eclipse.sirius.components.diagrams.description.LabelStyleDescription) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) AQLInterpreter(org.eclipse.sirius.components.interpreter.AQLInterpreter) Objects(java.util.Objects) List(java.util.List) NodeType(org.eclipse.sirius.components.diagrams.NodeType) Optional(java.util.Optional) VariableManager(org.eclipse.sirius.components.representations.VariableManager) IIdentifierProvider(org.eclipse.sirius.components.compatibility.api.IIdentifierProvider) BasicLabelStyleDescription(org.eclipse.sirius.viewpoint.description.style.BasicLabelStyleDescription) LabelStyleDescription(org.eclipse.sirius.components.diagrams.description.LabelStyleDescription) LabelDescription(org.eclipse.sirius.components.diagrams.description.LabelDescription) NodeDescription(org.eclipse.sirius.components.diagrams.description.NodeDescription) ArrayList(java.util.ArrayList) List(java.util.List) ListNodeStyle(org.eclipse.sirius.components.diagrams.ListNodeStyle) ListItemNodeStyle(org.eclipse.sirius.components.diagrams.ListItemNodeStyle) SynchronizationPolicy(org.eclipse.sirius.components.diagrams.description.SynchronizationPolicy) ImageNodeStyle(org.eclipse.sirius.components.diagrams.ImageNodeStyle) INodeStyle(org.eclipse.sirius.components.diagrams.INodeStyle)

Example 2 with ImageNodeStyle

use of org.eclipse.sirius.components.diagrams.ImageNodeStyle 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 3 with ImageNodeStyle

use of org.eclipse.sirius.components.diagrams.ImageNodeStyle 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
}
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) ImageNodeStyle(org.eclipse.sirius.components.diagrams.ImageNodeStyle) INodeStyle(org.eclipse.sirius.components.diagrams.INodeStyle) ArrayList(java.util.ArrayList) List(java.util.List) Diagram(org.eclipse.sirius.components.diagrams.Diagram) Test(org.junit.jupiter.api.Test)

Example 4 with ImageNodeStyle

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

the class ImageNodeStyleSizeProviderTests method testImageNodeStyleScaledSize.

@Test
public void testImageNodeStyleScaledSize() {
    ImageNodeStyleSizeProvider imageNodeStyleSizeProvider = new ImageNodeStyleSizeProvider(this.imageSizeProvider);
    // @formatter:off
    ImageNodeStyle imageNodeStyle = ImageNodeStyle.newImageNodeStyle().imageURL(IMAGE_PNG).scalingFactor(2).build();
    // @formatter:on
    Size size = imageNodeStyleSizeProvider.getSize(imageNodeStyle);
    assertThat(size.getWidth()).isCloseTo(20.0, Offset.offset(0.0001));
}
Also used : ImageNodeStyleSizeProvider(org.eclipse.sirius.components.diagrams.layout.incremental.provider.ImageNodeStyleSizeProvider) ImageNodeStyle(org.eclipse.sirius.components.diagrams.ImageNodeStyle) Size(org.eclipse.sirius.components.diagrams.Size) Test(org.junit.jupiter.api.Test)

Example 5 with ImageNodeStyle

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

the class NodeSizeProvider method isAlreadySized.

private boolean isAlreadySized(NodeLayoutData node) {
    Size size = node.getSize();
    INodeStyle style = node.getStyle();
    boolean isSizeUndefined = size.getWidth() == -1 || size.getHeight() == -1;
    // If the node is an Image node Style, we recompute the size since the image scale factor may have changed.
    return node.isResizedByUser() || (!isSizeUndefined && !(style instanceof ImageNodeStyle));
}
Also used : Size(org.eclipse.sirius.components.diagrams.Size) ImageNodeStyle(org.eclipse.sirius.components.diagrams.ImageNodeStyle) INodeStyle(org.eclipse.sirius.components.diagrams.INodeStyle)

Aggregations

ImageNodeStyle (org.eclipse.sirius.components.diagrams.ImageNodeStyle)13 Size (org.eclipse.sirius.components.diagrams.Size)7 INodeStyle (org.eclipse.sirius.components.diagrams.INodeStyle)5 VariableManager (org.eclipse.sirius.components.representations.VariableManager)5 Test (org.junit.jupiter.api.Test)5 AQLInterpreter (org.eclipse.sirius.components.interpreter.AQLInterpreter)4 RectangularNodeStyle (org.eclipse.sirius.components.diagrams.RectangularNodeStyle)3 WorkspaceImageDescription (org.eclipse.sirius.diagram.description.style.WorkspaceImageDescription)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Objects (java.util.Objects)2 Optional (java.util.Optional)2 UUID (java.util.UUID)2 Function (java.util.function.Function)2 LineStyle (org.eclipse.sirius.components.diagrams.LineStyle)2 ListItemNodeStyle (org.eclipse.sirius.components.diagrams.ListItemNodeStyle)2 ListNodeStyle (org.eclipse.sirius.components.diagrams.ListNodeStyle)2 TextBounds (org.eclipse.sirius.components.diagrams.TextBounds)2 LabelDescription (org.eclipse.sirius.components.diagrams.description.LabelDescription)2 LabelStyleDescription (org.eclipse.sirius.components.diagrams.description.LabelStyleDescription)2