Search in sources :

Example 1 with AbstractProgressIndicatorExBase

use of com.intellij.openapi.progress.util.AbstractProgressIndicatorExBase 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 AbstractProgressIndicatorExBase

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

the class SearchCommand method startSearching.

public void startSearching() {
    final UsageViewContext context = createUsageViewContext();
    final UsageViewPresentation presentation = new UsageViewPresentation();
    presentation.setOpenInNewTab(FindSettings.getInstance().isShowResultsInSeparateView());
    context.configure(presentation);
    final FindUsagesProcessPresentation processPresentation = new FindUsagesProcessPresentation(presentation);
    processPresentation.setShowNotFoundMessage(true);
    processPresentation.setShowPanelIfOnlyOneUsage(true);
    processPresentation.setProgressIndicatorFactory(new Factory<ProgressIndicator>() {

        @Override
        public ProgressIndicator create() {
            FindProgressIndicator indicator = new FindProgressIndicator(mySearchContext.getProject(), presentation.getScopeText());
            indicator.addStateDelegate(new AbstractProgressIndicatorExBase() {

                @Override
                public void cancel() {
                    super.cancel();
                    stopAsyncSearch();
                }
            });
            return indicator;
        }
    });
    PsiDocumentManager.getInstance(mySearchContext.getProject()).commitAllDocuments();
    final ConfigurableUsageTarget target = context.getTarget();
    ((FindManagerImpl) FindManager.getInstance(mySearchContext.getProject())).getFindUsagesManager().addToHistory(target);
    UsageViewManager.getInstance(mySearchContext.getProject()).searchAndShowUsages(new UsageTarget[] { target }, () -> new UsageSearcher() {

        @Override
        public void generate(@NotNull final Processor<Usage> processor) {
            findUsages(processor);
        }
    }, processPresentation, presentation, new UsageViewManager.UsageViewStateListener() {

        @Override
        public void usageViewCreated(@NotNull UsageView usageView) {
            context.setUsageView(usageView);
            context.configureActions();
        }

        @Override
        public void findingUsagesFinished(final UsageView usageView) {
        }
    });
}
Also used : AbstractProgressIndicatorExBase(com.intellij.openapi.progress.util.AbstractProgressIndicatorExBase) FindProgressIndicator(com.intellij.find.FindProgressIndicator) FindProgressIndicator(com.intellij.find.FindProgressIndicator) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator)

Example 3 with AbstractProgressIndicatorExBase

use of com.intellij.openapi.progress.util.AbstractProgressIndicatorExBase 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 4 with AbstractProgressIndicatorExBase

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

the class CodeSmellDetectorImpl method findCodeSmells.

@NotNull
private List<CodeSmellInfo> findCodeSmells(@NotNull final VirtualFile file, @NotNull final ProgressIndicator progress) {
    final List<CodeSmellInfo> result = Collections.synchronizedList(new ArrayList<CodeSmellInfo>());
    final DaemonCodeAnalyzerImpl codeAnalyzer = (DaemonCodeAnalyzerImpl) DaemonCodeAnalyzer.getInstance(myProject);
    final ProgressIndicator daemonIndicator = new DaemonProgressIndicator();
    ((ProgressIndicatorEx) progress).addStateDelegate(new AbstractProgressIndicatorExBase() {

        @Override
        public void cancel() {
            super.cancel();
            daemonIndicator.cancel();
        }
    });
    ProgressManager.getInstance().runProcess(new Runnable() {

        @Override
        public void run() {
            DumbService.getInstance(myProject).runReadActionInSmartMode(new Runnable() {

                @Override
                public void run() {
                    final PsiFile psiFile = PsiManager.getInstance(myProject).findFile(file);
                    final Document document = FileDocumentManager.getInstance().getDocument(file);
                    if (psiFile == null || document == null) {
                        return;
                    }
                    List<HighlightInfo> infos = codeAnalyzer.runMainPasses(psiFile, document, daemonIndicator);
                    convertErrorsAndWarnings(infos, result, document);
                }
            });
        }
    }, daemonIndicator);
    return result;
}
Also used : CodeSmellInfo(com.intellij.codeInsight.CodeSmellInfo) Document(com.intellij.openapi.editor.Document) AbstractProgressIndicatorExBase(com.intellij.openapi.progress.util.AbstractProgressIndicatorExBase) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ProgressIndicatorEx(com.intellij.openapi.wm.ex.ProgressIndicatorEx) PsiFile(com.intellij.psi.PsiFile) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with AbstractProgressIndicatorExBase

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

the class ExternalSystemUtil method refreshProject.

public static void refreshProject(@NotNull final String externalProjectPath, @NotNull final ImportSpec importSpec) {
    Project project = importSpec.getProject();
    ProjectSystemId externalSystemId = importSpec.getExternalSystemId();
    ExternalProjectRefreshCallback callback = importSpec.getCallback();
    boolean isPreviewMode = importSpec.isPreviewMode();
    ProgressExecutionMode progressExecutionMode = importSpec.getProgressExecutionMode();
    boolean reportRefreshError = importSpec.isReportRefreshError();
    String arguments = importSpec.getArguments();
    String vmOptions = importSpec.getVmOptions();
    File projectFile = new File(externalProjectPath);
    final String projectName;
    if (projectFile.isFile()) {
        projectName = projectFile.getParentFile().getName();
    } else {
        projectName = projectFile.getName();
    }
    final TaskUnderProgress refreshProjectStructureTask = new TaskUnderProgress() {

        private final ExternalSystemResolveProjectTask myTask = new ExternalSystemResolveProjectTask(externalSystemId, project, externalProjectPath, vmOptions, arguments, isPreviewMode);

        @SuppressWarnings({ "ThrowableResultOfMethodCallIgnored", "IOResourceOpenedButNotSafelyClosed" })
        @Override
        public void execute(@NotNull ProgressIndicator indicator) {
            if (project.isDisposed())
                return;
            if (indicator instanceof ProgressIndicatorEx) {
                ((ProgressIndicatorEx) indicator).addStateDelegate(new AbstractProgressIndicatorExBase() {

                    @Override
                    public void cancel() {
                        super.cancel();
                        ApplicationManager.getApplication().executeOnPooledThread((Runnable) () -> myTask.cancel(ExternalSystemTaskNotificationListener.EP_NAME.getExtensions()));
                    }
                });
            }
            ExternalSystemProcessingManager processingManager = ServiceManager.getService(ExternalSystemProcessingManager.class);
            if (processingManager.findTask(ExternalSystemTaskType.RESOLVE_PROJECT, externalSystemId, externalProjectPath) != null) {
                if (callback != null) {
                    callback.onFailure(ExternalSystemBundle.message("error.resolve.already.running", externalProjectPath), null);
                }
                return;
            }
            if (!(callback instanceof MyMultiExternalProjectRefreshCallback)) {
                ExternalSystemNotificationManager.getInstance(project).clearNotifications(null, NotificationSource.PROJECT_SYNC, externalSystemId);
            }
            final ExternalSystemTaskActivator externalSystemTaskActivator = ExternalProjectsManager.getInstance(project).getTaskActivator();
            if (!isPreviewMode && !externalSystemTaskActivator.runTasks(externalProjectPath, ExternalSystemTaskActivator.Phase.BEFORE_SYNC)) {
                return;
            }
            myTask.execute(indicator, ExternalSystemTaskNotificationListener.EP_NAME.getExtensions());
            if (project.isDisposed())
                return;
            final Throwable error = myTask.getError();
            if (error == null) {
                if (callback != null) {
                    DataNode<ProjectData> externalProject = myTask.getExternalProject();
                    if (externalProject != null && importSpec.shouldCreateDirectoriesForEmptyContentRoots()) {
                        externalProject.putUserData(ContentRootDataService.CREATE_EMPTY_DIRECTORIES, Boolean.TRUE);
                    }
                    callback.onSuccess(externalProject);
                }
                if (!isPreviewMode) {
                    externalSystemTaskActivator.runTasks(externalProjectPath, ExternalSystemTaskActivator.Phase.AFTER_SYNC);
                }
                return;
            }
            if (error instanceof ImportCanceledException) {
                // stop refresh task
                return;
            }
            String message = ExternalSystemApiUtil.buildErrorMessage(error);
            if (StringUtil.isEmpty(message)) {
                message = String.format("Can't resolve %s project at '%s'. Reason: %s", externalSystemId.getReadableName(), externalProjectPath, message);
            }
            if (callback != null) {
                callback.onFailure(message, extractDetails(error));
            }
            ExternalSystemManager<?, ?, ?, ?, ?> manager = ExternalSystemApiUtil.getManager(externalSystemId);
            if (manager == null) {
                return;
            }
            AbstractExternalSystemSettings<?, ?, ?> settings = manager.getSettingsProvider().fun(project);
            ExternalProjectSettings projectSettings = settings.getLinkedProjectSettings(externalProjectPath);
            if (projectSettings == null || !reportRefreshError) {
                return;
            }
            ExternalSystemNotificationManager.getInstance(project).processExternalProjectRefreshError(error, projectName, externalSystemId);
        }
    };
    final String title;
    switch(progressExecutionMode) {
        case NO_PROGRESS_SYNC:
        case NO_PROGRESS_ASYNC:
            throw new ExternalSystemException("Please, use progress for the project import!");
        case MODAL_SYNC:
            title = ExternalSystemBundle.message("progress.import.text", projectName, externalSystemId.getReadableName());
            new Task.Modal(project, title, true) {

                @Override
                public void run(@NotNull ProgressIndicator indicator) {
                    refreshProjectStructureTask.execute(indicator);
                }
            }.queue();
            break;
        case IN_BACKGROUND_ASYNC:
            title = ExternalSystemBundle.message("progress.refresh.text", projectName, externalSystemId.getReadableName());
            new Task.Backgroundable(project, title) {

                @Override
                public void run(@NotNull ProgressIndicator indicator) {
                    refreshProjectStructureTask.execute(indicator);
                }
            }.queue();
            break;
        case START_IN_FOREGROUND_ASYNC:
            title = ExternalSystemBundle.message("progress.refresh.text", projectName, externalSystemId.getReadableName());
            new Task.Backgroundable(project, title, true, PerformInBackgroundOption.DEAF) {

                @Override
                public void run(@NotNull ProgressIndicator indicator) {
                    refreshProjectStructureTask.execute(indicator);
                }
            }.queue();
    }
}
Also used : ExternalSystemTaskActivator(com.intellij.openapi.externalSystem.service.project.manage.ExternalSystemTaskActivator) Task(com.intellij.openapi.progress.Task) ExternalSystemResolveProjectTask(com.intellij.openapi.externalSystem.service.internal.ExternalSystemResolveProjectTask) ExternalSystemProcessingManager(com.intellij.openapi.externalSystem.service.internal.ExternalSystemProcessingManager) ImportCanceledException(com.intellij.openapi.externalSystem.service.ImportCanceledException) NotNull(org.jetbrains.annotations.NotNull) ExternalSystemResolveProjectTask(com.intellij.openapi.externalSystem.service.internal.ExternalSystemResolveProjectTask) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ExternalProjectRefreshCallback(com.intellij.openapi.externalSystem.service.project.ExternalProjectRefreshCallback) ProjectData(com.intellij.openapi.externalSystem.model.project.ProjectData) ProgressExecutionMode(com.intellij.openapi.externalSystem.service.execution.ProgressExecutionMode) ExternalProjectSettings(com.intellij.openapi.externalSystem.settings.ExternalProjectSettings) Project(com.intellij.openapi.project.Project) AbstractProgressIndicatorExBase(com.intellij.openapi.progress.util.AbstractProgressIndicatorExBase) DisposeAwareRunnable(com.intellij.util.DisposeAwareRunnable) ProgressIndicatorEx(com.intellij.openapi.wm.ex.ProgressIndicatorEx) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Aggregations

AbstractProgressIndicatorExBase (com.intellij.openapi.progress.util.AbstractProgressIndicatorExBase)6 ProgressIndicatorEx (com.intellij.openapi.wm.ex.ProgressIndicatorEx)5 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)4 EmptyProgressIndicator (com.intellij.openapi.progress.EmptyProgressIndicator)2 NotNull (org.jetbrains.annotations.NotNull)2 CodeSmellInfo (com.intellij.codeInsight.CodeSmellInfo)1 FindProgressIndicator (com.intellij.find.FindProgressIndicator)1 IdeaPluginDescriptor (com.intellij.ide.plugins.IdeaPluginDescriptor)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 Project (com.intellij.openapi.project.Project)1 VerticalFlowLayout (com.intellij.openapi.ui.VerticalFlowLayout)1