Search in sources :

Example 1 with IDiagramInput

use of org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramInput 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)

Example 2 with IDiagramInput

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

the class DiagramEventProcessor method handle.

@Override
public void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDescriptionSink, IRepresentationInput representationInput) {
    IRepresentationInput effectiveInput = representationInput;
    if (representationInput instanceof RenameRepresentationInput) {
        RenameRepresentationInput renameRepresentationInput = (RenameRepresentationInput) representationInput;
        effectiveInput = new RenameDiagramInput(renameRepresentationInput.getId(), renameRepresentationInput.getEditingContextId(), renameRepresentationInput.getRepresentationId(), renameRepresentationInput.getNewLabel());
    }
    if (effectiveInput instanceof IDiagramInput) {
        IDiagramInput diagramInput = (IDiagramInput) effectiveInput;
        Optional<IDiagramEventHandler> optionalDiagramEventHandler = this.diagramEventHandlers.stream().filter(handler -> handler.canHandle(diagramInput)).findFirst();
        if (optionalDiagramEventHandler.isPresent()) {
            IDiagramEventHandler diagramEventHandler = optionalDiagramEventHandler.get();
            diagramEventHandler.handle(payloadSink, changeDescriptionSink, this.editingContext, this.diagramContext, diagramInput);
        } else {
            // $NON-NLS-1$
            this.logger.warn("No handler found for event: {}", diagramInput);
        }
    }
}
Also used : IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) IDiagramInput(org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramInput) LoggerFactory(org.slf4j.LoggerFactory) One(reactor.core.publisher.Sinks.One) DiagramDescription(org.eclipse.sirius.components.diagrams.description.DiagramDescription) IInput(org.eclipse.sirius.components.core.api.IInput) Diagram(org.eclipse.sirius.components.diagrams.Diagram) IRepresentation(org.eclipse.sirius.components.representations.IRepresentation) IRepresentationRefreshPolicyRegistry(org.eclipse.sirius.components.collaborative.api.IRepresentationRefreshPolicyRegistry) IDiagramEventProcessor(org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramEventProcessor) ChangeKind(org.eclipse.sirius.components.collaborative.api.ChangeKind) ISubscriptionManager(org.eclipse.sirius.components.collaborative.api.ISubscriptionManager) Logger(org.slf4j.Logger) IDiagramContext(org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramContext) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) RenameRepresentationInput(org.eclipse.sirius.components.collaborative.dto.RenameRepresentationInput) IRepresentationDescriptionSearchService(org.eclipse.sirius.components.core.api.IRepresentationDescriptionSearchService) IRepresentationInput(org.eclipse.sirius.components.core.api.IRepresentationInput) IRepresentationRefreshPolicy(org.eclipse.sirius.components.collaborative.api.IRepresentationRefreshPolicy) IDiagramCreationService(org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramCreationService) Objects(java.util.Objects) RenameDiagramInput(org.eclipse.sirius.components.collaborative.diagrams.dto.RenameDiagramInput) Flux(reactor.core.publisher.Flux) List(java.util.List) IPayload(org.eclipse.sirius.components.core.api.IPayload) IDiagramEventHandler(org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramEventHandler) Many(reactor.core.publisher.Sinks.Many) Optional(java.util.Optional) RenameDiagramInput(org.eclipse.sirius.components.collaborative.diagrams.dto.RenameDiagramInput) IDiagramInput(org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramInput) IDiagramEventHandler(org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramEventHandler) IRepresentationInput(org.eclipse.sirius.components.core.api.IRepresentationInput) RenameRepresentationInput(org.eclipse.sirius.components.collaborative.dto.RenameRepresentationInput)

Aggregations

List (java.util.List)2 Objects (java.util.Objects)2 Optional (java.util.Optional)2 ChangeDescription (org.eclipse.sirius.components.collaborative.api.ChangeDescription)2 ChangeKind (org.eclipse.sirius.components.collaborative.api.ChangeKind)2 IDiagramContext (org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramContext)2 IDiagramEventHandler (org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramEventHandler)2 IDiagramInput (org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramInput)2 IEditingContext (org.eclipse.sirius.components.core.api.IEditingContext)2 IPayload (org.eclipse.sirius.components.core.api.IPayload)2 IRepresentationDescriptionSearchService (org.eclipse.sirius.components.core.api.IRepresentationDescriptionSearchService)2 Diagram (org.eclipse.sirius.components.diagrams.Diagram)2 DiagramDescription (org.eclipse.sirius.components.diagrams.description.DiagramDescription)2 Many (reactor.core.publisher.Sinks.Many)2 One (reactor.core.publisher.Sinks.One)2 Counter (io.micrometer.core.instrument.Counter)1 MeterRegistry (io.micrometer.core.instrument.MeterRegistry)1 UUID (java.util.UUID)1 IRepresentationRefreshPolicy (org.eclipse.sirius.components.collaborative.api.IRepresentationRefreshPolicy)1 IRepresentationRefreshPolicyRegistry (org.eclipse.sirius.components.collaborative.api.IRepresentationRefreshPolicyRegistry)1