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