use of org.eclipse.sirius.components.diagrams.INodeStyle 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.INodeStyle 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.INodeStyle in project sirius-components by eclipse-sirius.
the class DiagramRendererEdgeTests method getNodeDescription.
private NodeDescription getNodeDescription(UUID nodeDescriptionId) {
// @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> targetObjectIdProvider = variableManager -> {
Object object = variableManager.getVariables().get(VariableManager.SELF);
if (object instanceof String) {
// $NON-NLS-1$
return nodeDescriptionId + "__" + object;
}
return null;
};
return NodeDescription.newNodeDescription(nodeDescriptionId).typeProvider(// $NON-NLS-1$
variableManager -> "").semanticElementsProvider(variableManager -> List.of(FIRST_OBJECT_ID, SECOND_OBJECT_ID)).targetObjectIdProvider(targetObjectIdProvider).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 DiagramRendererNodeTests method testSimpleNodeRenderingWithSizeProviderWithPreviousDiagram.
@Test
public void testSimpleNodeRenderingWithSizeProviderWithPreviousDiagram() {
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.of(10, 200), Optional.empty());
// We modified the created diagram to change the node previous size.
Node node = diagram.getNodes().get(0);
// @formatter:off
Node nodeWithNewSize = Node.newNode(node).size(Size.of(50, 100)).build();
Diagram newDiagram = Diagram.newDiagram(diagram).nodes(List.of(nodeWithNewSize)).build();
// @formatter:on
diagram = this.createDiagram(styleProvider, variableManager -> NODE_RECTANGULAR, VariableManager -> Size.of(10, 200), Optional.of(newDiagram));
// We check that the node size is still the one provided by the VSM
assertThat(diagram.getNodes()).extracting(Node::getSize).allMatch(s -> s.getHeight() == 200 && s.getWidth() == 10);
// This time, the size provider return 0,0. The NodeComponent should use the previous size in this case
diagram = this.createDiagram(styleProvider, variableManager -> NODE_RECTANGULAR, VariableManager -> Size.of(0, 0), Optional.of(newDiagram));
// We check that the node size is the new one set in new diagram
assertThat(diagram.getNodes()).extracting(Node::getSize).allMatch(s -> s.getHeight() == 100 && s.getWidth() == 50);
// @formatter:off
nodeWithNewSize = Node.newNode(node).size(Size.of(50, 100)).customizedProperties(Set.of(CustomizableProperties.Size)).build();
newDiagram = Diagram.newDiagram(diagram).nodes(List.of(nodeWithNewSize)).build();
// @formatter:on
diagram = this.createDiagram(styleProvider, variableManager -> NODE_RECTANGULAR, VariableManager -> Size.of(10, 200), Optional.of(newDiagram));
// We now check that we use the custom user size in priority over the VSM default one.
assertThat(diagram.getNodes()).extracting(Node::getSize).allMatch(s -> s.getHeight() == 100 && s.getWidth() == 50);
}
use of org.eclipse.sirius.components.diagrams.INodeStyle 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);
}
Aggregations