Search in sources :

Example 1 with Progressive

use of com.intellij.openapi.progress.Progressive in project intellij-community by JetBrains.

the class AssociationsEditor method expandTree.

private void expandTree(DefaultTreeModel newModel) {
    final TreePath rootPath = new TreePath(newModel.getRoot());
    final Object element = myBuilder.getTreeStructure().getRootElement();
    myBuilder.batch(new Progressive() {

        @Override
        public void run(@NotNull ProgressIndicator indicator) {
            myBuilder.expand(element, null);
            myBuilder.expand(myBuilder.getTreeStructure().getChildElements(element), null);
        }
    });
    myTree.setSelectionPath(rootPath);
    myTree.scrollRectToVisible(new Rectangle(new Point(0, 0)));
}
Also used : Progressive(com.intellij.openapi.progress.Progressive) TreePath(javax.swing.tree.TreePath) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator)

Example 2 with Progressive

use of com.intellij.openapi.progress.Progressive in project intellij-community by JetBrains.

the class TreeUiTest method testBatchUpdate.

public void testBatchUpdate() throws Exception {
    buildStructure(myRoot);
    myElementUpdate.clear();
    final NodeElement[] toExpand = new NodeElement[] { new NodeElement("com"), new NodeElement("jetbrains"), new NodeElement("org"), new NodeElement("xUnit") };
    final ActionCallback done = new ActionCallback();
    final Ref<ProgressIndicator> indicatorRef = new Ref<>();
    final Ref<ActionCallback> ready = new Ref<>();
    myElementUpdateHook = new ElementUpdateHook() {

        @Override
        public void onElementAction(String action, Object element) {
            if (new NodeElement("jetbrains").equals(element) && ready.get() == null) {
                ActionCallback readyCallback = new ActionCallback();
                assertFalse(getBuilder().getUi().isReady());
                getBuilder().getReady(this).notify(readyCallback);
                ready.set(readyCallback);
            }
        }
    };
    invokeLaterIfNeeded(() -> getBuilder().batch(new Progressive() {

        @Override
        public void run(@NotNull ProgressIndicator indicator) {
            indicatorRef.set(indicator);
            expandNext(toExpand, 0, indicator, done);
        }
    }).notify(done));
    waitBuilderToCome(o -> done.isProcessed());
    assertTrue(done.isDone());
    assertNotNull(ready.get());
    assertTrue(ready.get().isDone());
    assertTree("-/\n" + " -com\n" + "  +intellij\n" + " -jetbrains\n" + "  +fabrique\n" + " -org\n" + "  +eclipse\n" + " -xUnit\n" + "  runner\n");
    assertFalse(indicatorRef.get().isCanceled());
}
Also used : Progressive(com.intellij.openapi.progress.Progressive) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator)

Example 3 with Progressive

use of com.intellij.openapi.progress.Progressive in project intellij-community by JetBrains.

the class CloudRuntimeTask method perform.

private T perform(boolean modal, final Disposable disposable) {
    final Semaphore semaphore = new Semaphore();
    semaphore.down();
    final AtomicReference<T> result = new AtomicReference<>();
    final Progressive progressive = new Progressive() {

        @Override
        public void run(@NotNull ProgressIndicator indicator) {
            indicator.setIndeterminate(true);
            while (!indicator.isCanceled()) {
                if (semaphore.waitFor(500)) {
                    if (mySuccess.get()) {
                        UIUtil.invokeLaterIfNeeded(() -> {
                            if (disposable == null || !Disposer.isDisposed(disposable)) {
                                postPerform(result.get());
                            }
                        });
                    }
                    break;
                }
            }
        }
    };
    Task task;
    boolean cancellable = isCancellable(modal);
    if (modal) {
        task = new Task.Modal(myProject, myTitle, cancellable) {

            @Override
            public void run(@NotNull ProgressIndicator indicator) {
                progressive.run(indicator);
            }
        };
    } else {
        task = new Task.Backgroundable(myProject, myTitle, cancellable) {

            @Override
            public void run(@NotNull ProgressIndicator indicator) {
                progressive.run(indicator);
            }

            @Override
            public boolean shouldStartInBackground() {
                return CloudRuntimeTask.this.shouldStartInBackground();
            }
        };
    }
    mySuccess.set(false);
    myErrorMessage.set(null);
    run(semaphore, result);
    task.queue();
    return result.get();
}
Also used : Progressive(com.intellij.openapi.progress.Progressive) Task(com.intellij.openapi.progress.Task) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) AtomicReference(java.util.concurrent.atomic.AtomicReference) Semaphore(com.intellij.util.concurrency.Semaphore) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with Progressive

use of com.intellij.openapi.progress.Progressive in project intellij-community by JetBrains.

the class BaseProjectTreeBuilder method revalidateElement.

@NotNull
@Override
public AsyncResult<Object> revalidateElement(Object element) {
    final AsyncResult<Object> result = new AsyncResult<>();
    if (element instanceof AbstractTreeNode) {
        AbstractTreeNode node = (AbstractTreeNode) element;
        final Object value = node.getValue();
        final ActionCallback callback = new ActionCallback();
        final VirtualFile virtualFile = PsiUtilCore.getVirtualFile(ObjectUtils.tryCast(value, PsiElement.class));
        final FocusRequestor focusRequestor = IdeFocusManager.getInstance(myProject).getFurtherRequestor();
        batch(new Progressive() {

            @Override
            public void run(@NotNull ProgressIndicator indicator) {
                final Ref<Object> target = new Ref<>();
                _select(value, virtualFile, false, Conditions.<AbstractTreeNode>alwaysTrue(), callback, indicator, target, focusRequestor, false);
                callback.doWhenDone(() -> result.setDone(target.get())).doWhenRejected(() -> result.setRejected());
            }
        });
    } else {
        result.setRejected();
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FocusRequestor(com.intellij.openapi.wm.FocusRequestor) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) Progressive(com.intellij.openapi.progress.Progressive) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with Progressive

use of com.intellij.openapi.progress.Progressive in project intellij-community by JetBrains.

the class TreeUiTest method testCancelUpdateBatch.

public void testCancelUpdateBatch() throws Exception {
    buildStructure(myRoot);
    myAlwaysShowPlus.add(new NodeElement("com"));
    myAlwaysShowPlus.add(new NodeElement("jetbrains"));
    myAlwaysShowPlus.add(new NodeElement("org"));
    myAlwaysShowPlus.add(new NodeElement("xUnit"));
    final Ref<Boolean> cancelled = new Ref<>(false);
    myElementUpdateHook = new ElementUpdateHook() {

        @Override
        public void onElementAction(String action, Object element) {
            NodeElement stopElement = new NodeElement("com");
            if (cancelled.get()) {
                myCancelRequest = new AssertionError("Not supposed to update after element=" + stopElement);
                return;
            }
            if (element.equals(stopElement) && action.equals("getChildren")) {
                cancelled.set(true);
                getBuilder().cancelUpdate();
            }
        }
    };
    final NodeElement[] toExpand = new NodeElement[] { new NodeElement("com"), new NodeElement("jetbrains"), new NodeElement("org"), new NodeElement("xUnit") };
    final ActionCallback done = new ActionCallback();
    final Ref<ProgressIndicator> indicatorRef = new Ref<>();
    invokeLaterIfNeeded(() -> getBuilder().batch(new Progressive() {

        @Override
        public void run(@NotNull ProgressIndicator indicator) {
            indicatorRef.set(indicator);
            expandNext(toExpand, 0, indicator, done);
        }
    }).notify(done));
    waitBuilderToCome(o -> done.isProcessed() || myCancelRequest != null);
    assertNull(myCancelRequest);
    assertTrue(done.isRejected());
    assertTrue(indicatorRef.get().isCanceled());
    assertFalse(getBuilder().getUi().isCancelProcessed());
}
Also used : Progressive(com.intellij.openapi.progress.Progressive) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator)

Aggregations

ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)5 Progressive (com.intellij.openapi.progress.Progressive)5 NotNull (org.jetbrains.annotations.NotNull)2 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)1 Task (com.intellij.openapi.progress.Task)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 FocusRequestor (com.intellij.openapi.wm.FocusRequestor)1 PsiElement (com.intellij.psi.PsiElement)1 Semaphore (com.intellij.util.concurrency.Semaphore)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 TreePath (javax.swing.tree.TreePath)1