Search in sources :

Example 1 with RenameRepresentationInput

use of org.eclipse.sirius.components.collaborative.dto.RenameRepresentationInput 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)

Example 2 with RenameRepresentationInput

use of org.eclipse.sirius.components.collaborative.dto.RenameRepresentationInput in project sirius-components by eclipse-sirius.

the class EditingContextEventProcessor method setupChangeDescriptionSinkConsumer.

@SuppressWarnings("checkstyle:IllegalCatch")
private Disposable setupChangeDescriptionSinkConsumer() {
    Consumer<ChangeDescription> consumer = changeDescription -> {
        if (ChangeKind.REPRESENTATION_TO_DELETE.equals(changeDescription.getKind())) {
            Object representationId = changeDescription.getParameters().get(REPRESENTATION_ID);
            if (representationId instanceof String) {
                DeleteRepresentationInput deleteRepresentationInput = new DeleteRepresentationInput(UUID.randomUUID(), (String) representationId);
                this.doHandle(Sinks.one(), deleteRepresentationInput);
            }
        } else if (ChangeKind.REPRESENTATION_TO_RENAME.equals(changeDescription.getKind())) {
            Object representationId = changeDescription.getParameters().get(REPRESENTATION_ID);
            Object representationLabel = changeDescription.getParameters().get(REPRESENTATION_LABEL);
            if (representationId instanceof String && representationLabel instanceof String) {
                RenameRepresentationInput renameRepresentationInput = new RenameRepresentationInput(UUID.randomUUID(), this.getEditingContextId(), (String) representationId, (String) representationLabel);
                this.doHandle(Sinks.one(), renameRepresentationInput);
            }
        }
        this.publishEvent(changeDescription);
        this.disposeRepresentationIfNeeded();
        RepresentationEventProcessorEntry representationEventProcessorEntry = this.representationEventProcessors.get(changeDescription.getSourceId());
        if (representationEventProcessorEntry != null) {
            try {
                IRepresentationEventProcessor representationEventProcessor = representationEventProcessorEntry.getRepresentationEventProcessor();
                representationEventProcessor.refresh(changeDescription);
                IRepresentation representation = representationEventProcessor.getRepresentation();
                this.applicationEventPublisher.publishEvent(new RepresentationRefreshedEvent(this.editingContext.getId(), representation));
            } catch (Exception exception) {
                this.logger.warn(exception.getMessage(), exception);
            }
        }
        this.refreshOtherRepresentations(changeDescription);
        if (this.shouldPersistTheEditingContext(changeDescription)) {
            this.editingContextPersistenceService.persist(this.editingContext);
        }
        this.danglingRepresentationDeletionService.deleteDanglingRepresentations(this.editingContext.getId());
    };
    Consumer<Throwable> errorConsumer = throwable -> this.logger.warn(throwable.getMessage(), throwable);
    return this.changeDescriptionSink.asFlux().subscribe(consumer, errorConsumer);
}
Also used : ErrorPayload(org.eclipse.sirius.components.core.api.ErrorPayload) Sinks(reactor.core.publisher.Sinks) IEditingContextEventProcessor(org.eclipse.sirius.components.collaborative.api.IEditingContextEventProcessor) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) Disposable(reactor.core.Disposable) IRepresentationConfiguration(org.eclipse.sirius.components.collaborative.api.IRepresentationConfiguration) LoggerFactory(org.slf4j.LoggerFactory) One(reactor.core.publisher.Sinks.One) IDanglingRepresentationDeletionService(org.eclipse.sirius.components.collaborative.api.IDanglingRepresentationDeletionService) IInput(org.eclipse.sirius.components.core.api.IInput) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) IEditingContextPersistenceService(org.eclipse.sirius.components.core.api.IEditingContextPersistenceService) IRepresentationEventProcessorComposedFactory(org.eclipse.sirius.components.collaborative.api.IRepresentationEventProcessorComposedFactory) Duration(java.time.Duration) Map(java.util.Map) IRepresentation(org.eclipse.sirius.components.representations.IRepresentation) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) ICollaborativeMessageService(org.eclipse.sirius.components.collaborative.messages.ICollaborativeMessageService) EmitResult(reactor.core.publisher.Sinks.EmitResult) Schedulers(reactor.core.scheduler.Schedulers) IRepresentationEventProcessor(org.eclipse.sirius.components.collaborative.api.IRepresentationEventProcessor) RepresentationRefreshedEvent(org.eclipse.sirius.components.collaborative.dto.RepresentationRefreshedEvent) ExecutorService(java.util.concurrent.ExecutorService) ChangeKind(org.eclipse.sirius.components.collaborative.api.ChangeKind) Logger(org.slf4j.Logger) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) RenameRepresentationInput(org.eclipse.sirius.components.collaborative.dto.RenameRepresentationInput) RepresentationRenamedEventPayload(org.eclipse.sirius.components.collaborative.dto.RepresentationRenamedEventPayload) Mono(reactor.core.publisher.Mono) UUID(java.util.UUID) IRepresentationInput(org.eclipse.sirius.components.core.api.IRepresentationInput) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) ExecutionException(java.util.concurrent.ExecutionException) Consumer(java.util.function.Consumer) Flux(reactor.core.publisher.Flux) List(java.util.List) IPayload(org.eclipse.sirius.components.core.api.IPayload) DelegatingRequestContextExecutorService(org.eclipse.sirius.components.collaborative.requestcontext.DelegatingRequestContextExecutorService) Entry(java.util.Map.Entry) Many(reactor.core.publisher.Sinks.Many) Optional(java.util.Optional) IEditingContextEventHandler(org.eclipse.sirius.components.collaborative.api.IEditingContextEventHandler) DeleteRepresentationInput(org.eclipse.sirius.components.collaborative.dto.DeleteRepresentationInput) RepresentationRefreshedEvent(org.eclipse.sirius.components.collaborative.dto.RepresentationRefreshedEvent) DeleteRepresentationInput(org.eclipse.sirius.components.collaborative.dto.DeleteRepresentationInput) IRepresentation(org.eclipse.sirius.components.representations.IRepresentation) ExecutionException(java.util.concurrent.ExecutionException) IRepresentationEventProcessor(org.eclipse.sirius.components.collaborative.api.IRepresentationEventProcessor) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) RenameRepresentationInput(org.eclipse.sirius.components.collaborative.dto.RenameRepresentationInput)

Example 3 with RenameRepresentationInput

use of org.eclipse.sirius.components.collaborative.dto.RenameRepresentationInput in project sirius-components by eclipse-sirius.

the class EditingContextEventProcessor method publishEvent.

private void publishEvent(ChangeDescription changeDescription) {
    if (this.sink.currentSubscriberCount() > 0) {
        IInput input = changeDescription.getInput();
        UUID correlationId = input.getId();
        if (input instanceof RenameRepresentationInput && ChangeKind.REPRESENTATION_RENAMING.equals(changeDescription.getKind())) {
            String representationId = ((RenameRepresentationInput) input).getRepresentationId();
            String newLabel = ((RenameRepresentationInput) input).getNewLabel();
            this.tryEmitRepresentationRenamedEvent(correlationId, representationId, newLabel);
        } else if (ChangeKind.REPRESENTATION_TO_RENAME.equals(changeDescription.getKind()) && !changeDescription.getParameters().isEmpty()) {
            Map<String, Object> parameters = changeDescription.getParameters();
            // @formatter:off
            var optionalRepresentationId = Optional.ofNullable(parameters.get(REPRESENTATION_ID)).filter(String.class::isInstance).map(String.class::cast);
            var optionalRepresentationLabel = Optional.ofNullable(parameters.get(REPRESENTATION_LABEL)).filter(String.class::isInstance).map(String.class::cast);
            // @formatter:on
            if (optionalRepresentationId.isPresent() && optionalRepresentationLabel.isPresent()) {
                this.tryEmitRepresentationRenamedEvent(correlationId, optionalRepresentationId.get(), optionalRepresentationLabel.get());
            }
        }
    }
}
Also used : IInput(org.eclipse.sirius.components.core.api.IInput) UUID(java.util.UUID) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) RenameRepresentationInput(org.eclipse.sirius.components.collaborative.dto.RenameRepresentationInput)

Aggregations

RenameRepresentationInput (org.eclipse.sirius.components.collaborative.dto.RenameRepresentationInput)3 IInput (org.eclipse.sirius.components.core.api.IInput)3 List (java.util.List)2 Map (java.util.Map)2 Objects (java.util.Objects)2 Optional (java.util.Optional)2 UUID (java.util.UUID)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ChangeDescription (org.eclipse.sirius.components.collaborative.api.ChangeDescription)2 ChangeKind (org.eclipse.sirius.components.collaborative.api.ChangeKind)2 IEditingContext (org.eclipse.sirius.components.core.api.IEditingContext)2 IPayload (org.eclipse.sirius.components.core.api.IPayload)2 IRepresentationInput (org.eclipse.sirius.components.core.api.IRepresentationInput)2 IRepresentation (org.eclipse.sirius.components.representations.IRepresentation)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Flux (reactor.core.publisher.Flux)2 Duration (java.time.Duration)1 ArrayList (java.util.ArrayList)1 Entry (java.util.Map.Entry)1