use of org.eclipse.sirius.components.collaborative.trees.dto.TreePathSuccessPayload in project sirius-components by eclipse-sirius.
the class TreePathEventHandler method handle.
@Override
public void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDescriptionSink, IEditingContext editingContext, Tree tree, ITreeInput treeInput) {
IPayload payload = new TreePathSuccessPayload(treeInput.getId(), new TreePath(List.of(), 0));
ChangeDescription changeDescription = new ChangeDescription(ChangeKind.NOTHING, treeInput.getRepresentationId(), treeInput);
if (treeInput instanceof TreePathInput) {
TreePathInput input = (TreePathInput) treeInput;
Optional<ITreePathProvider> optionalPathProvider = this.treePathProviders.stream().filter(treePathProvider -> treePathProvider.canHandle(tree)).findFirst();
if (optionalPathProvider.isPresent()) {
IPayload resultPayload = optionalPathProvider.get().handle(editingContext, tree, input);
if (resultPayload instanceof TreePathSuccessPayload) {
payload = resultPayload;
} else if (resultPayload instanceof ErrorPayload) {
ErrorPayload errorPayload = (ErrorPayload) resultPayload;
this.logger.warn(errorPayload.getMessage());
}
}
}
changeDescriptionSink.tryEmitNext(changeDescription);
payloadSink.tryEmitValue(payload);
}
use of org.eclipse.sirius.components.collaborative.trees.dto.TreePathSuccessPayload in project sirius-web by eclipse-sirius.
the class EditingContextTreePathDataFetcher method get.
@Override
public CompletableFuture<TreePath> get(DataFetchingEnvironment environment) throws Exception {
String editingContextId = environment.getSource();
String treeId = environment.getArgument(TREE_ID);
List<String> selectionEntryIds = environment.getArgument(SELECTION_ENTRY_IDS);
TreePathInput input = new TreePathInput(UUID.randomUUID(), editingContextId, treeId, selectionEntryIds);
// @formatter:off
return this.editingContextEventProcessorRegistry.dispatchEvent(editingContextId, input).filter(TreePathSuccessPayload.class::isInstance).map(TreePathSuccessPayload.class::cast).map(TreePathSuccessPayload::getTreePath).toFuture();
// @formatter:on
}
use of org.eclipse.sirius.components.collaborative.trees.dto.TreePathSuccessPayload in project sirius-web by eclipse-sirius.
the class ExplorerTreePathProvider method handle.
@Override
public IPayload handle(IEditingContext editingContext, Tree tree, TreePathInput input) {
int maxDepth = 0;
Set<String> allAncestors = new HashSet<>();
for (String selectionEntryId : input.getSelectionEntryIds()) {
List<String> itemAncestors = this.getAncestors(editingContext, selectionEntryId);
allAncestors.addAll(itemAncestors);
maxDepth = Math.max(maxDepth, itemAncestors.size());
}
return new TreePathSuccessPayload(input.getId(), new TreePath(allAncestors.stream().collect(Collectors.toList()), maxDepth));
}
Aggregations