Search in sources :

Example 1 with IToolSectionsProvider

use of org.eclipse.sirius.components.collaborative.diagrams.api.IToolSectionsProvider in project sirius-components by eclipse-sirius.

the class GetToolSectionsEventHandler method handle.

@Override
public void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDescriptionSink, IEditingContext editingContext, IDiagramContext diagramContext, IDiagramInput diagramInput) {
    this.counter.increment();
    ChangeDescription changeDescription = new ChangeDescription(ChangeKind.NOTHING, editingContext.getId(), diagramInput);
    IPayload payload = null;
    if (diagramInput instanceof GetToolSectionsInput) {
        GetToolSectionsInput toolSectionsInput = (GetToolSectionsInput) diagramInput;
        String diagramElementId = toolSectionsInput.getDiagramElementId();
        Diagram diagram = diagramContext.getDiagram();
        // @formatter:off
        var optionalDiagramDescription = this.representationDescriptionSearchService.findById(editingContext, diagram.getDescriptionId()).filter(DiagramDescription.class::isInstance).map(DiagramDescription.class::cast);
        // @formatter:on
        if (optionalDiagramDescription.isPresent()) {
            DiagramDescription diagramDescription = optionalDiagramDescription.get();
            var optionalToolSectionsProvider = this.toolSectionsProviders.stream().filter(toolSectionProvider -> toolSectionProvider.canHandle(diagramDescription)).findFirst();
            var optionalTargetElement = this.findTargetElement(diagram, diagramElementId, editingContext);
            var optionalDiagramElement = this.findDiagramElement(diagram, diagramElementId);
            var optionalDiagramElementDescription = this.findDiagramElementDescription(diagram, diagramElementId, diagramDescription, optionalDiagramElement.orElse(null));
            if (optionalToolSectionsProvider.isPresent() && optionalTargetElement.isPresent() && optionalDiagramElementDescription.isPresent()) {
                IToolSectionsProvider toolSectionsProvider = optionalToolSectionsProvider.get();
                List<ToolSection> toolSections = toolSectionsProvider.handle(optionalTargetElement.get(), optionalDiagramElement.orElse(null), optionalDiagramElementDescription.get(), diagramDescription);
                payload = new GetToolSectionSuccessPayload(diagramInput.getId(), toolSections);
            }
        } else {
            String message = this.messageService.invalidInput(diagramInput.getClass().getSimpleName(), GetToolSectionsInput.class.getSimpleName());
            payload = new ErrorPayload(diagramInput.getId(), message);
        }
        payloadSink.tryEmitValue(payload);
        changeDescriptionSink.tryEmitNext(changeDescription);
    }
}
Also used : ErrorPayload(org.eclipse.sirius.components.core.api.ErrorPayload) Edge(org.eclipse.sirius.components.diagrams.Edge) Node(org.eclipse.sirius.components.diagrams.Node) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) IDiagramInput(org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramInput) IObjectService(org.eclipse.sirius.components.core.api.IObjectService) One(reactor.core.publisher.Sinks.One) DiagramDescription(org.eclipse.sirius.components.diagrams.description.DiagramDescription) IToolSectionsProvider(org.eclipse.sirius.components.collaborative.diagrams.api.IToolSectionsProvider) IDiagramDescriptionService(org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramDescriptionService) ToolSection(org.eclipse.sirius.components.diagrams.tools.ToolSection) Diagram(org.eclipse.sirius.components.diagrams.Diagram) Monitoring(org.eclipse.sirius.components.collaborative.api.Monitoring) Service(org.springframework.stereotype.Service) ICollaborativeMessageService(org.eclipse.sirius.components.collaborative.messages.ICollaborativeMessageService) IDiagramQueryService(org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramQueryService) Counter(io.micrometer.core.instrument.Counter) GetToolSectionsInput(org.eclipse.sirius.components.collaborative.diagrams.dto.GetToolSectionsInput) ChangeKind(org.eclipse.sirius.components.collaborative.api.ChangeKind) IDiagramContext(org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramContext) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) IRepresentationDescriptionSearchService(org.eclipse.sirius.components.core.api.IRepresentationDescriptionSearchService) UUID(java.util.UUID) Objects(java.util.Objects) List(java.util.List) IPayload(org.eclipse.sirius.components.core.api.IPayload) IDiagramEventHandler(org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramEventHandler) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) GetToolSectionSuccessPayload(org.eclipse.sirius.components.collaborative.diagrams.dto.GetToolSectionSuccessPayload) Many(reactor.core.publisher.Sinks.Many) Optional(java.util.Optional) GetToolSectionSuccessPayload(org.eclipse.sirius.components.collaborative.diagrams.dto.GetToolSectionSuccessPayload) GetToolSectionsInput(org.eclipse.sirius.components.collaborative.diagrams.dto.GetToolSectionsInput) DiagramDescription(org.eclipse.sirius.components.diagrams.description.DiagramDescription) IPayload(org.eclipse.sirius.components.core.api.IPayload) Diagram(org.eclipse.sirius.components.diagrams.Diagram) ErrorPayload(org.eclipse.sirius.components.core.api.ErrorPayload) IToolSectionsProvider(org.eclipse.sirius.components.collaborative.diagrams.api.IToolSectionsProvider) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) ToolSection(org.eclipse.sirius.components.diagrams.tools.ToolSection)

Aggregations

Counter (io.micrometer.core.instrument.Counter)1 MeterRegistry (io.micrometer.core.instrument.MeterRegistry)1 List (java.util.List)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 UUID (java.util.UUID)1 ChangeDescription (org.eclipse.sirius.components.collaborative.api.ChangeDescription)1 ChangeKind (org.eclipse.sirius.components.collaborative.api.ChangeKind)1 Monitoring (org.eclipse.sirius.components.collaborative.api.Monitoring)1 IDiagramContext (org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramContext)1 IDiagramDescriptionService (org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramDescriptionService)1 IDiagramEventHandler (org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramEventHandler)1 IDiagramInput (org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramInput)1 IDiagramQueryService (org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramQueryService)1 IToolSectionsProvider (org.eclipse.sirius.components.collaborative.diagrams.api.IToolSectionsProvider)1 GetToolSectionSuccessPayload (org.eclipse.sirius.components.collaborative.diagrams.dto.GetToolSectionSuccessPayload)1 GetToolSectionsInput (org.eclipse.sirius.components.collaborative.diagrams.dto.GetToolSectionsInput)1 ICollaborativeMessageService (org.eclipse.sirius.components.collaborative.messages.ICollaborativeMessageService)1 ErrorPayload (org.eclipse.sirius.components.core.api.ErrorPayload)1 IEditingContext (org.eclipse.sirius.components.core.api.IEditingContext)1