use of org.eclipse.sirius.components.diagrams.description.EdgeDescription.Builder in project sirius-components by eclipse-sirius.
the class EdgeMappingConverter method convert.
public EdgeDescription convert(EdgeMapping edgeMapping, AQLInterpreter interpreter, Map<UUID, NodeDescription> id2NodeDescriptions) {
Function<VariableManager, String> targetIdProvider = variableManager -> {
return variableManager.get(VariableManager.SELF, Object.class).map(this.objectService::getId).orElse(null);
};
Function<VariableManager, String> targetKindProvider = variableManager -> {
return variableManager.get(VariableManager.SELF, Object.class).map(this.objectService::getKind).orElse(null);
};
Function<VariableManager, String> targetLabelProvider = variableManager -> {
return variableManager.get(VariableManager.SELF, Object.class).map(this.objectService::getLabel).orElse(null);
};
List<NodeDescription> sourceNodeDescriptions = this.getNodeDescriptions(edgeMapping.getSourceMapping(), id2NodeDescriptions);
List<NodeDescription> targetNodeDescriptions = this.getNodeDescriptions(edgeMapping.getTargetMapping(), id2NodeDescriptions);
Function<VariableManager, List<?>> semanticElementsProvider = this.getSemanticElementsProvider(interpreter, edgeMapping, sourceNodeDescriptions);
Function<VariableManager, List<Element>> sourceNodesProvider = null;
if (edgeMapping.isUseDomainElement()) {
sourceNodesProvider = new DomainBasedSourceNodesProvider(edgeMapping, interpreter, this.identifierProvider);
} else {
sourceNodesProvider = new RelationBasedSourceNodesProvider(edgeMapping, this.identifierProvider);
}
Function<VariableManager, List<Element>> targetNodesProvider = new TargetNodesProvider(edgeMapping, interpreter, this.identifierProvider);
Function<VariableManager, EdgeStyle> styleProvider = new EdgeMappingStyleProvider(interpreter, edgeMapping);
LabelStyleDescriptionConverter labelStyleDescriptionConverter = new LabelStyleDescriptionConverter(interpreter, this.objectService);
// @formatter:off
EdgeStyleDescription style = edgeMapping.getStyle();
Optional<LabelDescription> optionalBeginLabelDescription = Optional.ofNullable(style).map(EdgeStyleDescription::getBeginLabelStyleDescription).map(// $NON-NLS-1$
labelDescription -> this.createLabelDescription(interpreter, labelStyleDescriptionConverter, labelDescription, "_beginlabel", edgeMapping));
Optional<LabelDescription> optionalCenterLabelDescription = Optional.ofNullable(style).map(EdgeStyleDescription::getCenterLabelStyleDescription).map(// $NON-NLS-1$
labelDescription -> this.createLabelDescription(interpreter, labelStyleDescriptionConverter, labelDescription, "_centerlabel", edgeMapping));
Optional<LabelDescription> optionalEndLabelDescription = Optional.ofNullable(style).map(EdgeStyleDescription::getEndLabelStyleDescription).map(// $NON-NLS-1$
labelDescription -> this.createLabelDescription(interpreter, labelStyleDescriptionConverter, labelDescription, "_endlabel", edgeMapping));
ToolConverter toolConverter = new ToolConverter(interpreter, this.editService, this.modelOperationHandlerSwitchProvider);
var deleteHandler = toolConverter.createDeleteToolHandler(edgeMapping.getDeletionDescription());
var labelEditHandler = toolConverter.createDirectEditToolHandler(edgeMapping.getLabelDirectEdit());
Builder builder = EdgeDescription.newEdgeDescription(UUID.fromString(this.identifierProvider.getIdentifier(edgeMapping))).targetObjectIdProvider(targetIdProvider).targetObjectKindProvider(targetKindProvider).targetObjectLabelProvider(targetLabelProvider).semanticElementsProvider(semanticElementsProvider).sourceNodeDescriptions(sourceNodeDescriptions).targetNodeDescriptions(targetNodeDescriptions).sourceNodesProvider(sourceNodesProvider).targetNodesProvider(targetNodesProvider).styleProvider(styleProvider).labelEditHandler(labelEditHandler).deleteHandler(deleteHandler);
optionalBeginLabelDescription.ifPresent(builder::beginLabelDescription);
optionalCenterLabelDescription.ifPresent(builder::centerLabelDescription);
optionalEndLabelDescription.ifPresent(builder::endLabelDescription);
return builder.build();
// @formatter:on
}
Aggregations