Search in sources :

Example 1 with Tree

use of org.eclipse.sirius.components.trees.Tree 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 Tree

use of org.eclipse.sirius.components.trees.Tree in project sirius-components by eclipse-sirius.

the class TreeEventProcessor method refreshTree.

private Tree refreshTree() {
    Tree tree = this.treeService.create(this.treeCreationParameters);
    // $NON-NLS-1$
    this.logger.trace("Tree refreshed: {}", this.treeCreationParameters.getEditingContext().getId());
    return tree;
}
Also used : Tree(org.eclipse.sirius.components.trees.Tree)

Example 3 with Tree

use of org.eclipse.sirius.components.trees.Tree in project sirius-components by eclipse-sirius.

the class TreeEventProcessor method refresh.

@Override
public void refresh(ChangeDescription changeDescription) {
    if (this.shouldRefresh(changeDescription)) {
        long start = System.currentTimeMillis();
        Tree tree = this.refreshTree();
        this.currentTree.set(tree);
        if (this.sink.currentSubscriberCount() > 0) {
            EmitResult emitResult = this.sink.tryEmitNext(new TreeRefreshedEventPayload(changeDescription.getInput().getId(), tree));
            if (emitResult.isFailure()) {
                // $NON-NLS-1$
                String pattern = "An error has occurred while emitting a TreeRefreshedEventPayload: {}";
                this.logger.warn(pattern, emitResult);
            }
        }
        long end = System.currentTimeMillis();
        this.timer.record(end - start, TimeUnit.MILLISECONDS);
    }
}
Also used : TreeRefreshedEventPayload(org.eclipse.sirius.components.collaborative.trees.dto.TreeRefreshedEventPayload) Tree(org.eclipse.sirius.components.trees.Tree) EmitResult(reactor.core.publisher.Sinks.EmitResult)

Aggregations

Tree (org.eclipse.sirius.components.trees.Tree)3 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 TreePathInput (org.eclipse.sirius.components.collaborative.trees.dto.TreePathInput)1 TreePathSuccessPayload (org.eclipse.sirius.components.collaborative.trees.dto.TreePathSuccessPayload)1 TreeRefreshedEventPayload (org.eclipse.sirius.components.collaborative.trees.dto.TreeRefreshedEventPayload)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 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 Service (org.springframework.stereotype.Service)1 EmitResult (reactor.core.publisher.Sinks.EmitResult)1