Search in sources :

Example 6 with ProgressManager

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

the class TextFieldWithAutoCompletionListProvider method fillCompletionVariants.

@Override
public void fillCompletionVariants(@NotNull CompletionParameters parameters, @NotNull String prefix, @NotNull CompletionResultSet result) {
    Collection<T> items = getItems(prefix, true, parameters);
    addCompletionElements(result, this, items, -10000);
    final ProgressManager progressManager = ProgressManager.getInstance();
    ProgressIndicator mainIndicator = progressManager.getProgressIndicator();
    final ProgressIndicator indicator = mainIndicator != null ? new SensitiveProgressWrapper(mainIndicator) : new EmptyProgressIndicator();
    Future<Collection<T>> future = ApplicationManager.getApplication().executeOnPooledThread(() -> progressManager.runProcess(() -> getItems(prefix, false, parameters), indicator));
    while (true) {
        try {
            Collection<T> tasks = future.get(100, TimeUnit.MILLISECONDS);
            if (tasks != null) {
                addCompletionElements(result, this, tasks, 0);
                return;
            }
        } catch (ProcessCanceledException e) {
            throw e;
        } catch (Exception ignore) {
        }
        ProgressManager.checkCanceled();
    }
}
Also used : EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) ProgressManager(com.intellij.openapi.progress.ProgressManager) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) SensitiveProgressWrapper(com.intellij.concurrency.SensitiveProgressWrapper) Collection(java.util.Collection) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 7 with ProgressManager

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

the class Preloader method initComponent.

@Override
public void initComponent() {
    if (ApplicationManager.getApplication().isUnitTestMode() || ApplicationManager.getApplication().isHeadlessEnvironment()) {
        return;
    }
    ProgressManager progressManager = ProgressManager.getInstance();
    for (final PreloadingActivity activity : PreloadingActivity.EP_NAME.getExtensions()) {
        myExecutor.execute(() -> {
            if (myIndicator.isCanceled())
                return;
            checkHeavyProcessRunning();
            if (myIndicator.isCanceled())
                return;
            progressManager.runProcess(() -> {
                try {
                    activity.preload(myWrappingIndicator);
                } catch (ProcessCanceledException ignore) {
                }
                LOG.info("Finished preloading " + activity);
            }, myIndicator);
        });
    }
}
Also used : ProgressManager(com.intellij.openapi.progress.ProgressManager) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 8 with ProgressManager

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

the class IdeFrameFixture method waitForBackgroundTasksToFinish.

//@NotNull
//public IdeFrameFixture waitForGradleProjectSyncToFail() {
//  try {
//    waitForGradleProjectSyncToFinish(true);
//    fail("Expecting project sync to fail");
//  }
//  catch (RuntimeException expected) {
//    // expected failure.
//  }
//  return waitForBackgroundTasksToFinish();
//}
//@NotNull
//public IdeFrameFixture waitForGradleProjectSyncToStart() {
//  Project project = getProject();
//  final GradleSyncState syncState = GradleSyncState.getInstance(project);
//  if (!syncState.isSyncInProgress()) {
//    pause(new Condition("Syncing project " + quote(project.getName()) + " to finish") {
//      @Override
//      public boolean test() {
//        return myGradleProjectEventListener.isSyncStarted();
//      }
//    }, SHORT_TIMEOUT);
//  }
//  return this;
//}
//@NotNull
//public IdeFrameFixture waitForGradleProjectSyncToFinish() {
//  waitForGradleProjectSyncToFinish(false);
//  return this;
//}
//private void waitForGradleProjectSyncToFinish(final boolean expectSyncFailure) {
//  final Project project = getProject();
//
//  // ensure GradleInvoker (in-process build) is always enabled.
//  AndroidGradleBuildConfiguration buildConfiguration = AndroidGradleBuildConfiguration.getInstance(project);
//  buildConfiguration.USE_EXPERIMENTAL_FASTER_BUILD = true;
//
//  pause(new Condition("Syncing project " + quote(project.getName()) + " to finish") {
//    @Override
//    public boolean test() {
//      GradleSyncState syncState = GradleSyncState.getInstance(project);
//      boolean syncFinished =
//        (myGradleProjectEventListener.isSyncFinished() || syncState.isSyncNeeded() != ThreeState.YES) && !syncState.isSyncInProgress();
//      if (expectSyncFailure) {
//        syncFinished = syncFinished && myGradleProjectEventListener.hasSyncError();
//      }
//      return syncFinished;
//    }
//  }, LONG_TIMEOUT);
//
//  findGradleSyncAction().waitUntilEnabledAndShowing();
//
//  if (myGradleProjectEventListener.hasSyncError()) {
//    RuntimeException syncError = myGradleProjectEventListener.getSyncError();
//    myGradleProjectEventListener.reset();
//    throw syncError;
//  }
//
//  if (!myGradleProjectEventListener.isSyncSkipped()) {
//    waitForBuildToFinish(SOURCE_GEN);
//  }
//
//  waitForBackgroundTasksToFinish();
//}
@NotNull
public IdeFrameFixture waitForBackgroundTasksToFinish() {
    Pause.pause(new Condition("Background tasks to finish") {

        @Override
        public boolean test() {
            ProgressManager progressManager = ProgressManager.getInstance();
            return !progressManager.hasModalProgressIndicator() && !progressManager.hasProgressIndicator() && !progressManager.hasUnsafeProgressIndicator();
        }
    }, GuiTestUtil.LONG_TIMEOUT);
    robot().waitForIdle();
    return this;
}
Also used : Condition(org.fest.swing.timing.Condition) ProgressManager(com.intellij.openapi.progress.ProgressManager) Assert.assertNotNull(junit.framework.Assert.assertNotNull) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with ProgressManager

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

the class RollbackAction method rollbackModifiedWithoutEditing.

private static void rollbackModifiedWithoutEditing(final Project project, final LinkedHashSet<VirtualFile> modifiedWithoutEditing) {
    final String operationName = StringUtil.decapitalize(UIUtil.removeMnemonic(RollbackUtil.getRollbackOperationName(project)));
    String message = (modifiedWithoutEditing.size() == 1) ? VcsBundle.message("rollback.modified.without.editing.confirm.single", operationName, modifiedWithoutEditing.iterator().next().getPresentableUrl()) : VcsBundle.message("rollback.modified.without.editing.confirm.multiple", operationName, modifiedWithoutEditing.size());
    int rc = showYesNoDialog(project, message, VcsBundle.message("changes.action.rollback.title", operationName), getQuestionIcon());
    if (rc != Messages.YES) {
        return;
    }
    final List<VcsException> exceptions = new ArrayList<>();
    final ProgressManager progressManager = ProgressManager.getInstance();
    final Runnable action = new Runnable() {

        public void run() {
            final ProgressIndicator indicator = progressManager.getProgressIndicator();
            try {
                ChangesUtil.processVirtualFilesByVcs(project, modifiedWithoutEditing, (vcs, items) -> {
                    final RollbackEnvironment rollbackEnvironment = vcs.getRollbackEnvironment();
                    if (rollbackEnvironment != null) {
                        if (indicator != null) {
                            indicator.setText(vcs.getDisplayName() + ": performing " + UIUtil.removeMnemonic(rollbackEnvironment.getRollbackOperationName()).toLowerCase() + "...");
                            indicator.setIndeterminate(false);
                        }
                        rollbackEnvironment.rollbackModifiedWithoutCheckout(items, exceptions, new RollbackProgressModifier(items.size(), indicator));
                        if (indicator != null) {
                            indicator.setText2("");
                        }
                    }
                });
            } catch (ProcessCanceledException e) {
            // for files refresh  
            }
            if (!exceptions.isEmpty()) {
                AbstractVcsHelper.getInstance(project).showErrors(exceptions, VcsBundle.message("rollback.modified.without.checkout.error.tab", operationName));
            }
            VfsUtil.markDirty(true, false, VfsUtilCore.toVirtualFileArray(modifiedWithoutEditing));
            VirtualFileManager.getInstance().asyncRefresh(new Runnable() {

                public void run() {
                    for (VirtualFile virtualFile : modifiedWithoutEditing) {
                        VcsDirtyScopeManager.getInstance(project).fileDirty(virtualFile);
                    }
                }
            });
        }
    };
    progressManager.runProcessWithProgressSynchronously(action, operationName, true, project);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) RollbackProgressModifier(com.intellij.openapi.vcs.changes.ui.RollbackProgressModifier) ProgressManager(com.intellij.openapi.progress.ProgressManager) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) RollbackEnvironment(com.intellij.openapi.vcs.rollback.RollbackEnvironment) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 10 with ProgressManager

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

the class JobUtilTest method testProcessorReturningFalseDoesNotCrashTheOtherThread.

public void testProcessorReturningFalseDoesNotCrashTheOtherThread() {
    final AtomicInteger delay = new AtomicInteger(0);
    final Runnable checkCanceled = ProgressManager::checkCanceled;
    Processor<String> processor = s -> {
        busySleep(delay.incrementAndGet() % 10 + 10, checkCanceled);
        return delay.get() % 100 != 0;
    };
    for (int i = 0; i < 100; i++) {
        ProgressIndicator indicator = new EmptyProgressIndicator();
        boolean result = JobLauncher.getInstance().invokeConcurrentlyUnderProgress(Collections.nCopies(10000, ""), indicator, false, false, processor);
        assertFalse(indicator.isCanceled());
        assertFalse(result);
    }
}
Also used : ProgressManager(com.intellij.openapi.progress.ProgressManager) UIUtil(com.intellij.util.ui.UIUtil) ProgressIndicatorBase(com.intellij.openapi.progress.util.ProgressIndicatorBase) java.util(java.util) PlatformTestUtil(com.intellij.testFramework.PlatformTestUtil) PlatformTestCase(com.intellij.testFramework.PlatformTestCase) java.util.concurrent(java.util.concurrent) AbstractProgressIndicatorBase(com.intellij.openapi.progress.util.AbstractProgressIndicatorBase) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicReference(java.util.concurrent.atomic.AtomicReference) ThreadDumper(com.intellij.diagnostic.ThreadDumper) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) BigDecimal(java.math.BigDecimal) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TimeoutUtil(com.intellij.util.TimeoutUtil) Processor(com.intellij.util.Processor) ApplicationManager(com.intellij.openapi.application.ApplicationManager) DaemonProgressIndicator(com.intellij.codeInsight.daemon.impl.DaemonProgressIndicator) javax.swing(javax.swing) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) DaemonProgressIndicator(com.intellij.codeInsight.daemon.impl.DaemonProgressIndicator)

Aggregations

ProgressManager (com.intellij.openapi.progress.ProgressManager)24 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)13 Task (com.intellij.openapi.progress.Task)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 Project (com.intellij.openapi.project.Project)4 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)3 VcsException (com.intellij.openapi.vcs.VcsException)3 EmptyProgressIndicator (com.intellij.openapi.progress.EmptyProgressIndicator)2 IdeFrame (com.intellij.openapi.wm.IdeFrame)2 IdeFrameImpl (com.intellij.openapi.wm.impl.IdeFrameImpl)2 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)2 PsiSearchHelper (com.intellij.psi.search.PsiSearchHelper)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Robot (org.fest.swing.core.Robot)2 WindowFinder.findFrame (org.fest.swing.finder.WindowFinder.findFrame)2 Condition (org.fest.swing.timing.Condition)2 DaemonProgressIndicator (com.intellij.codeInsight.daemon.impl.DaemonProgressIndicator)1 SensitiveProgressWrapper (com.intellij.concurrency.SensitiveProgressWrapper)1 ThreadDumper (com.intellij.diagnostic.ThreadDumper)1