Search in sources :

Example 1 with ProgressIndicatorEx

use of com.intellij.openapi.wm.ex.ProgressIndicatorEx in project intellij-community by JetBrains.

the class CompilerTask method addIndicatorDelegate.

private void addIndicatorDelegate() {
    ProgressIndicator indicator = myIndicator;
    if (!(indicator instanceof ProgressIndicatorEx)) {
        return;
    }
    ((ProgressIndicatorEx) indicator).addStateDelegate(new AbstractProgressIndicatorExBase() {

        @Override
        public void cancel() {
            super.cancel();
            selectFirstMessage();
            stopAppIconProgress();
        }

        @Override
        public void stop() {
            super.stop();
            if (!isCanceled()) {
                selectFirstMessage();
            }
            stopAppIconProgress();
        }

        private void selectFirstMessage() {
            if (!isHeadlessMode()) {
                SwingUtilities.invokeLater(() -> {
                    if (myProject != null && myProject.isDisposed()) {
                        return;
                    }
                    synchronized (myMessageViewLock) {
                        if (myErrorTreeView != null) {
                            myErrorTreeView.selectFirstMessage();
                        }
                    }
                });
            }
        }

        private void stopAppIconProgress() {
            UIUtil.invokeLaterIfNeeded(() -> {
                if (myProject != null && myProject.isDisposed()) {
                    return;
                }
                final AppIcon appIcon = AppIcon.getInstance();
                if (appIcon.hideProgress(myProject, APP_ICON_ID)) {
                    if (myErrorCount > 0) {
                        appIcon.setErrorBadge(myProject, String.valueOf(myErrorCount));
                        appIcon.requestAttention(myProject, true);
                    } else if (!myCompilationStartedAutomatically) {
                        appIcon.setOkBadge(myProject, true);
                        appIcon.requestAttention(myProject, false);
                    }
                }
            });
        }

        @Override
        public void setText(final String text) {
            super.setText(text);
            updateProgressText();
        }

        @Override
        public void setText2(final String text) {
            super.setText2(text);
            updateProgressText();
        }

        @Override
        public void setFraction(final double fraction) {
            super.setFraction(fraction);
            updateProgressText();
            GuiUtils.invokeLaterIfNeeded(() -> AppIcon.getInstance().setProgress(myProject, APP_ICON_ID, AppIconScheme.Progress.BUILD, fraction, true), ModalityState.any());
        }

        @Override
        protected void onProgressChange() {
            prepareMessageView();
        }
    });
}
Also used : AbstractProgressIndicatorExBase(com.intellij.openapi.progress.util.AbstractProgressIndicatorExBase) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ProgressIndicatorEx(com.intellij.openapi.wm.ex.ProgressIndicatorEx) AppIcon(com.intellij.ui.AppIcon)

Example 2 with ProgressIndicatorEx

use of com.intellij.openapi.wm.ex.ProgressIndicatorEx in project intellij-community by JetBrains.

the class DumbServiceImpl method runBackgroundProcess.

private void runBackgroundProcess(@NotNull final ProgressIndicator visibleIndicator) {
    if (!myState.compareAndSet(State.SCHEDULED_TASKS, State.RUNNING_DUMB_TASKS))
        return;
    final ShutDownTracker shutdownTracker = ShutDownTracker.getInstance();
    final Thread self = Thread.currentThread();
    try {
        shutdownTracker.registerStopperThread(self);
        if (visibleIndicator instanceof ProgressIndicatorEx) {
            ((ProgressIndicatorEx) visibleIndicator).addStateDelegate(new AppIconProgress());
        }
        DumbModeTask task = null;
        while (true) {
            Pair<DumbModeTask, ProgressIndicatorEx> pair = getNextTask(task, visibleIndicator);
            if (pair == null)
                break;
            task = pair.first;
            ProgressIndicatorEx taskIndicator = pair.second;
            if (visibleIndicator instanceof ProgressIndicatorEx) {
                taskIndicator.addStateDelegate(new AbstractProgressIndicatorExBase() {

                    @Override
                    protected void delegateProgressChange(@NotNull IndicatorAction action) {
                        super.delegateProgressChange(action);
                        action.execute((ProgressIndicatorEx) visibleIndicator);
                    }
                });
            }
            try (AccessToken ignored = HeavyProcessLatch.INSTANCE.processStarted("Performing indexing tasks")) {
                runSingleTask(task, taskIndicator);
            }
        }
    } catch (Throwable unexpected) {
        LOG.error(unexpected);
    } finally {
        shutdownTracker.unregisterStopperThread(self);
    }
}
Also used : ShutDownTracker(com.intellij.openapi.util.ShutDownTracker) AbstractProgressIndicatorExBase(com.intellij.openapi.progress.util.AbstractProgressIndicatorExBase) ProgressIndicatorEx(com.intellij.openapi.wm.ex.ProgressIndicatorEx)

Example 3 with ProgressIndicatorEx

use of com.intellij.openapi.wm.ex.ProgressIndicatorEx in project intellij-community by JetBrains.

the class InfoAndProgressPanel method removeProgress.

private void removeProgress(@NotNull InlineProgressIndicator progress) {
    synchronized (myOriginals) {
        // already disposed
        if (!myInline2Original.containsKey(progress))
            return;
        final boolean last = myOriginals.size() == 1;
        final boolean beforeLast = myOriginals.size() == 2;
        myPopup.removeIndicator(progress);
        final ProgressIndicatorEx original = removeFromMaps(progress);
        if (myOriginals.contains(original)) {
            Disposer.dispose(progress);
            return;
        }
        if (last) {
            restoreEmptyStatus();
            if (myShouldClosePopupAndOnProcessFinish) {
                hideProcessPopup();
            }
        } else {
            if (myPopup.isShowing() || myOriginals.size() > 1) {
                buildInProcessCount();
            } else if (beforeLast) {
                buildInInlineIndicator(createInlineDelegate(myInfos.get(0), myOriginals.get(0), true));
            } else {
                restoreEmptyStatus();
            }
        }
        runQuery();
    }
    Disposer.dispose(progress);
}
Also used : ProgressIndicatorEx(com.intellij.openapi.wm.ex.ProgressIndicatorEx)

Example 4 with ProgressIndicatorEx

use of com.intellij.openapi.wm.ex.ProgressIndicatorEx in project intellij-community by JetBrains.

the class ProgressIndicatorTest method testNestedIndicatorsAreCanceledRight.

public void testNestedIndicatorsAreCanceledRight() {
    checkCanceledCalled = false;
    ProgressManager.getInstance().executeProcessUnderProgress(() -> {
        assertFalse(CoreProgressManager.threadsUnderCanceledIndicator.contains(Thread.currentThread()));
        ProgressIndicator indicator = ProgressIndicatorProvider.getGlobalProgressIndicator();
        assertTrue(indicator != null && !indicator.isCanceled());
        indicator.cancel();
        assertTrue(CoreProgressManager.threadsUnderCanceledIndicator.contains(Thread.currentThread()));
        assertTrue(indicator.isCanceled());
        final ProgressIndicatorEx nested = new ProgressIndicatorBase();
        nested.addStateDelegate(new ProgressIndicatorStub() {

            @Override
            public void checkCanceled() throws ProcessCanceledException {
                checkCanceledCalled = true;
                throw new RuntimeException("must not call checkCanceled()");
            }
        });
        ProgressManager.getInstance().executeProcessUnderProgress(() -> {
            assertFalse(CoreProgressManager.threadsUnderCanceledIndicator.contains(Thread.currentThread()));
            ProgressIndicator indicator2 = ProgressIndicatorProvider.getGlobalProgressIndicator();
            assertTrue(indicator2 != null && !indicator2.isCanceled());
            assertSame(indicator2, nested);
            ProgressManager.checkCanceled();
        }, nested);
        ProgressIndicator indicator3 = ProgressIndicatorProvider.getGlobalProgressIndicator();
        assertSame(indicator, indicator3);
        assertTrue(CoreProgressManager.threadsUnderCanceledIndicator.contains(Thread.currentThread()));
    }, new EmptyProgressIndicator());
    assertFalse(checkCanceledCalled);
}
Also used : ProgressIndicatorBase(com.intellij.openapi.progress.util.ProgressIndicatorBase) DelegatingProgressIndicator(com.intellij.ide.util.DelegatingProgressIndicator) BombedProgressIndicator(com.intellij.testFramework.BombedProgressIndicator) DaemonProgressIndicator(com.intellij.codeInsight.daemon.impl.DaemonProgressIndicator) ProgressIndicatorEx(com.intellij.openapi.wm.ex.ProgressIndicatorEx)

Example 5 with ProgressIndicatorEx

use of com.intellij.openapi.wm.ex.ProgressIndicatorEx in project intellij-community by JetBrains.

the class ProgressIndicatorTest method testCheckCanceledGranularity.

public void testCheckCanceledGranularity() throws InterruptedException {
    prevTime = now = 0;
    final long warmupEnd = System.currentTimeMillis() + 1000;
    final TLongArrayList times = new TLongArrayList();
    final long end = warmupEnd + 1000;
    ApplicationManagerEx.getApplicationEx().runProcessWithProgressSynchronously(() -> {
        final Alarm alarm = new Alarm(Alarm.ThreadToUse.POOLED_THREAD, getTestRootDisposable());
        ProgressIndicatorEx indicator = (ProgressIndicatorEx) ProgressIndicatorProvider.getGlobalProgressIndicator();
        prevTime = System.currentTimeMillis();
        assert indicator != null;
        indicator.addStateDelegate(new ProgressIndicatorStub() {

            @Override
            public void checkCanceled() throws ProcessCanceledException {
                now = System.currentTimeMillis();
                if (now > warmupEnd) {
                    int delta = (int) (now - prevTime);
                    times.add(delta);
                }
                prevTime = now;
            }
        });
        while (System.currentTimeMillis() < end) {
            ProgressManager.checkCanceled();
        }
        alarm.cancelAllRequests();
    }, "", false, getProject(), null, "");
    long averageDelay = ArrayUtil.averageAmongMedians(times.toNativeArray(), 5);
    System.out.println("averageDelay = " + averageDelay);
    assertTrue(averageDelay < CoreProgressManager.CHECK_CANCELED_DELAY_MILLIS * 3);
}
Also used : TLongArrayList(gnu.trove.TLongArrayList) Alarm(com.intellij.util.Alarm) ProgressIndicatorEx(com.intellij.openapi.wm.ex.ProgressIndicatorEx)

Aggregations

ProgressIndicatorEx (com.intellij.openapi.wm.ex.ProgressIndicatorEx)10 AbstractProgressIndicatorExBase (com.intellij.openapi.progress.util.AbstractProgressIndicatorExBase)5 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)3 EmptyProgressIndicator (com.intellij.openapi.progress.EmptyProgressIndicator)2 NotNull (org.jetbrains.annotations.NotNull)2 CodeSmellInfo (com.intellij.codeInsight.CodeSmellInfo)1 DaemonProgressIndicator (com.intellij.codeInsight.daemon.impl.DaemonProgressIndicator)1 IdeaPluginDescriptor (com.intellij.ide.plugins.IdeaPluginDescriptor)1 DelegatingProgressIndicator (com.intellij.ide.util.DelegatingProgressIndicator)1 Document (com.intellij.openapi.editor.Document)1 ProjectData (com.intellij.openapi.externalSystem.model.project.ProjectData)1 ImportCanceledException (com.intellij.openapi.externalSystem.service.ImportCanceledException)1 ProgressExecutionMode (com.intellij.openapi.externalSystem.service.execution.ProgressExecutionMode)1 ExternalSystemProcessingManager (com.intellij.openapi.externalSystem.service.internal.ExternalSystemProcessingManager)1 ExternalSystemResolveProjectTask (com.intellij.openapi.externalSystem.service.internal.ExternalSystemResolveProjectTask)1 ExternalProjectRefreshCallback (com.intellij.openapi.externalSystem.service.project.ExternalProjectRefreshCallback)1 ExternalSystemTaskActivator (com.intellij.openapi.externalSystem.service.project.manage.ExternalSystemTaskActivator)1 ExternalProjectSettings (com.intellij.openapi.externalSystem.settings.ExternalProjectSettings)1 Task (com.intellij.openapi.progress.Task)1 ProgressIndicatorBase (com.intellij.openapi.progress.util.ProgressIndicatorBase)1