use of org.eclipse.sirius.components.collaborative.dto.RenameDocumentSuccessPayload in project sirius-web by eclipse-sirius.
the class RenameDocumentEventHandler method handle.
@Override
public void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDescriptionSink, IEditingContext editingContext, IInput input) {
this.counter.increment();
String message = this.messageService.invalidInput(input.getClass().getSimpleName(), RenameDocumentInput.class.getSimpleName());
IPayload payload = new ErrorPayload(input.getId(), message);
ChangeDescription changeDescription = new ChangeDescription(ChangeKind.NOTHING, editingContext.getId(), input);
// @formatter:off
Optional<AdapterFactoryEditingDomain> optionalEditingDomain = Optional.of(editingContext).filter(EditingContext.class::isInstance).map(EditingContext.class::cast).map(EditingContext::getDomain);
if (input instanceof RenameDocumentInput) {
RenameDocumentInput renameDocumentInput = (RenameDocumentInput) input;
UUID documentId = renameDocumentInput.getDocumentId();
String newName = renameDocumentInput.getNewName();
Optional<Document> optionalDocument = this.documentService.rename(documentId, newName);
if (optionalEditingDomain.isPresent() && optionalDocument.isPresent()) {
Document document = optionalDocument.get();
AdapterFactoryEditingDomain adapterFactoryEditingDomain = optionalEditingDomain.get();
ResourceSet resourceSet = adapterFactoryEditingDomain.getResourceSet();
// @formatter:off
resourceSet.getResources().stream().filter(resource -> document.getId().toString().equals(resource.getURI().toString())).findFirst().ifPresent(resource -> {
resource.eAdapters().stream().filter(DocumentMetadataAdapter.class::isInstance).map(DocumentMetadataAdapter.class::cast).findFirst().ifPresent(adapter -> adapter.setName(newName));
});
// @formatter:on
payload = new RenameDocumentSuccessPayload(input.getId());
changeDescription = new ChangeDescription(ChangeKind.SEMANTIC_CHANGE, editingContext.getId(), input);
}
}
payloadSink.tryEmitValue(payload);
changeDescriptionSink.tryEmitNext(changeDescription);
}
Aggregations