use of org.eclipse.sirius.components.collaborative.diagrams.dto.GetToolSectionsInput 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.dto.GetToolSectionsInput in project sirius-web by eclipse-sirius.
the class DiagramDescriptionToolSectionsDataFetcher method get.
@Override
public CompletableFuture<List<ToolSection>> get(DataFetchingEnvironment environment) throws Exception {
Map<String, Object> localContext = environment.getLocalContext();
String editingContextId = Optional.ofNullable(localContext.get(LocalContextConstants.EDITING_CONTEXT_ID)).map(Object::toString).orElse(null);
String representationId = Optional.ofNullable(localContext.get(LocalContextConstants.REPRESENTATION_ID)).map(Object::toString).orElse(null);
String diagramElementId = environment.getArgument(DIAGRAM_ELEMENT_ID);
if (editingContextId != null && representationId != null) {
GetToolSectionsInput input = new GetToolSectionsInput(UUID.randomUUID(), editingContextId, representationId, diagramElementId);
// @formatter:off
return this.editingContextEventProcessorRegistry.dispatchEvent(input.getEditingContextId(), input).filter(GetToolSectionSuccessPayload.class::isInstance).map(GetToolSectionSuccessPayload.class::cast).map(GetToolSectionSuccessPayload::getToolSections).toFuture();
// @formatter:on
}
return Mono.<List<ToolSection>>empty().toFuture();
}
Aggregations