Search in sources :

Example 1 with Builder

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
}
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) EdgeMapping(org.eclipse.sirius.diagram.description.EdgeMapping) AbstractNodeMapping(org.eclipse.sirius.diagram.description.AbstractNodeMapping) EdgeStyleDescription(org.eclipse.sirius.diagram.description.style.EdgeStyleDescription) Function(java.util.function.Function) NodeDescription(org.eclipse.sirius.components.diagrams.description.NodeDescription) 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) Builder(org.eclipse.sirius.components.diagrams.description.EdgeDescription.Builder) BasicLabelStyleDescription(org.eclipse.sirius.viewpoint.description.style.BasicLabelStyleDescription) IEditService(org.eclipse.sirius.components.core.api.IEditService) EdgeStyle(org.eclipse.sirius.components.diagrams.EdgeStyle) IModelOperationHandlerSwitchProvider(org.eclipse.sirius.components.compatibility.api.IModelOperationHandlerSwitchProvider) LabelStyleDescription(org.eclipse.sirius.components.diagrams.description.LabelStyleDescription) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) AQLInterpreter(org.eclipse.sirius.components.interpreter.AQLInterpreter) Element(org.eclipse.sirius.components.representations.Element) Objects(java.util.Objects) List(java.util.List) EdgeDescription(org.eclipse.sirius.components.diagrams.description.EdgeDescription) DiagramElementMapping(org.eclipse.sirius.diagram.description.DiagramElementMapping) Optional(java.util.Optional) VariableManager(org.eclipse.sirius.components.representations.VariableManager) IIdentifierProvider(org.eclipse.sirius.components.compatibility.api.IIdentifierProvider) EdgeStyleDescription(org.eclipse.sirius.diagram.description.style.EdgeStyleDescription) Builder(org.eclipse.sirius.components.diagrams.description.EdgeDescription.Builder) NodeDescription(org.eclipse.sirius.components.diagrams.description.NodeDescription) LabelDescription(org.eclipse.sirius.components.diagrams.description.LabelDescription) List(java.util.List) EdgeStyle(org.eclipse.sirius.components.diagrams.EdgeStyle)

Aggregations

List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 UUID (java.util.UUID)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 IIdentifierProvider (org.eclipse.sirius.components.compatibility.api.IIdentifierProvider)1 IModelOperationHandlerSwitchProvider (org.eclipse.sirius.components.compatibility.api.IModelOperationHandlerSwitchProvider)1 ISemanticCandidatesProviderFactory (org.eclipse.sirius.components.compatibility.api.ISemanticCandidatesProviderFactory)1 StringValueProvider (org.eclipse.sirius.components.compatibility.utils.StringValueProvider)1 IEditService (org.eclipse.sirius.components.core.api.IEditService)1 IObjectService (org.eclipse.sirius.components.core.api.IObjectService)1 EdgeStyle (org.eclipse.sirius.components.diagrams.EdgeStyle)1 EdgeDescription (org.eclipse.sirius.components.diagrams.description.EdgeDescription)1 Builder (org.eclipse.sirius.components.diagrams.description.EdgeDescription.Builder)1 LabelDescription (org.eclipse.sirius.components.diagrams.description.LabelDescription)1 LabelStyleDescription (org.eclipse.sirius.components.diagrams.description.LabelStyleDescription)1 NodeDescription (org.eclipse.sirius.components.diagrams.description.NodeDescription)1 AQLInterpreter (org.eclipse.sirius.components.interpreter.AQLInterpreter)1