use of org.eclipse.sirius.components.collaborative.trees.dto.DeleteTreeItemSuccessPayload in project sirius-components by eclipse-sirius.
the class DeleteTreeItemEventHandler method handle.
@Override
public void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDescriptionSink, IEditingContext editingContext, Tree tree, ITreeInput treeInput) {
this.counter.increment();
String message = this.messageService.invalidInput(treeInput.getClass().getSimpleName(), DeleteTreeItemInput.class.getSimpleName());
IPayload payload = new ErrorPayload(treeInput.getId(), message);
ChangeDescription changeDescription = new ChangeDescription(ChangeKind.NOTHING, treeInput.getRepresentationId(), treeInput);
if (treeInput instanceof DeleteTreeItemInput) {
DeleteTreeItemInput input = (DeleteTreeItemInput) treeInput;
var optionalTreeItem = this.treeQueryService.findTreeItem(tree, input.getTreeItemId());
if (optionalTreeItem.isPresent()) {
TreeDescription treeDescription = this.explorerDescriptionProvider.getDescription();
TreeItem treeItem = optionalTreeItem.get();
VariableManager variableManager = new VariableManager();
variableManager.put(IEditingContext.EDITING_CONTEXT, editingContext);
variableManager.put(TreeItem.SELECTED_TREE_ITEM, treeItem);
var status = treeDescription.getDeleteHandler().apply(variableManager);
if (status instanceof Success) {
Success success = (Success) status;
changeDescription = new ChangeDescription(success.getChangeKind(), treeInput.getRepresentationId(), treeInput, success.getParameters());
payload = new DeleteTreeItemSuccessPayload(treeInput.getId());
} else if (status instanceof Failure) {
payload = new ErrorPayload(treeInput.getId(), ((Failure) status).getMessage());
}
}
}
changeDescriptionSink.tryEmitNext(changeDescription);
payloadSink.tryEmitValue(payload);
}
Aggregations