Search in sources :

Example 1 with TreePathInput

use of org.eclipse.sirius.components.collaborative.trees.dto.TreePathInput 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);
}
Also used : ErrorPayload(org.eclipse.sirius.components.core.api.ErrorPayload) ChangeKind(org.eclipse.sirius.components.collaborative.api.ChangeKind) TreePathSuccessPayload(org.eclipse.sirius.components.collaborative.trees.dto.TreePathSuccessPayload) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) Logger(org.slf4j.Logger) TreePath(org.eclipse.sirius.components.collaborative.trees.dto.TreePath) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) LoggerFactory(org.slf4j.LoggerFactory) One(reactor.core.publisher.Sinks.One) ITreeEventHandler(org.eclipse.sirius.components.collaborative.trees.api.ITreeEventHandler) ITreeInput(org.eclipse.sirius.components.collaborative.trees.api.ITreeInput) Objects(java.util.Objects) List(java.util.List) IPayload(org.eclipse.sirius.components.core.api.IPayload) Service(org.springframework.stereotype.Service) Many(reactor.core.publisher.Sinks.Many) Optional(java.util.Optional) ITreePathProvider(org.eclipse.sirius.components.collaborative.trees.api.ITreePathProvider) TreePathInput(org.eclipse.sirius.components.collaborative.trees.dto.TreePathInput) Tree(org.eclipse.sirius.components.trees.Tree) TreePathInput(org.eclipse.sirius.components.collaborative.trees.dto.TreePathInput) ErrorPayload(org.eclipse.sirius.components.core.api.ErrorPayload) TreePath(org.eclipse.sirius.components.collaborative.trees.dto.TreePath) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) IPayload(org.eclipse.sirius.components.core.api.IPayload) TreePathSuccessPayload(org.eclipse.sirius.components.collaborative.trees.dto.TreePathSuccessPayload) ITreePathProvider(org.eclipse.sirius.components.collaborative.trees.api.ITreePathProvider)

Example 2 with TreePathInput

use of org.eclipse.sirius.components.collaborative.trees.dto.TreePathInput 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
}
Also used : TreePathInput(org.eclipse.sirius.components.collaborative.trees.dto.TreePathInput) TreePathSuccessPayload(org.eclipse.sirius.components.collaborative.trees.dto.TreePathSuccessPayload)

Aggregations

TreePathInput (org.eclipse.sirius.components.collaborative.trees.dto.TreePathInput)2 TreePathSuccessPayload (org.eclipse.sirius.components.collaborative.trees.dto.TreePathSuccessPayload)2 List (java.util.List)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 ChangeDescription (org.eclipse.sirius.components.collaborative.api.ChangeDescription)1 ChangeKind (org.eclipse.sirius.components.collaborative.api.ChangeKind)1 ITreeEventHandler (org.eclipse.sirius.components.collaborative.trees.api.ITreeEventHandler)1 ITreeInput (org.eclipse.sirius.components.collaborative.trees.api.ITreeInput)1 ITreePathProvider (org.eclipse.sirius.components.collaborative.trees.api.ITreePathProvider)1 TreePath (org.eclipse.sirius.components.collaborative.trees.dto.TreePath)1 ErrorPayload (org.eclipse.sirius.components.core.api.ErrorPayload)1 IEditingContext (org.eclipse.sirius.components.core.api.IEditingContext)1 IPayload (org.eclipse.sirius.components.core.api.IPayload)1 Tree (org.eclipse.sirius.components.trees.Tree)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 Service (org.springframework.stereotype.Service)1 Many (reactor.core.publisher.Sinks.Many)1 One (reactor.core.publisher.Sinks.One)1