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