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);
}
}
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);
}
}
}
Aggregations