Search in sources :

Example 21 with ProgressIndicatorBase

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

the class ApplicationImplTest method testCheckCanceledReadAction.

public void testCheckCanceledReadAction() throws Exception {
    Semaphore mayStartReadAction = new Semaphore();
    mayStartReadAction.down();
    ProgressIndicatorBase progress = new ProgressIndicatorBase();
    Future<?> future = ApplicationManager.getApplication().executeOnPooledThread(() -> ProgressManager.getInstance().runProcess(() -> {
        mayStartReadAction.waitFor();
        ReadAction.run(() -> fail("should be canceled before entering read action"));
    }, progress));
    WriteAction.run(() -> {
        mayStartReadAction.up();
        progress.cancel();
        future.get(1, TimeUnit.SECONDS);
    });
}
Also used : ProgressIndicatorBase(com.intellij.openapi.progress.util.ProgressIndicatorBase) Semaphore(com.intellij.util.concurrency.Semaphore)

Example 22 with ProgressIndicatorBase

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

the class JavadocQuarantineStatusCleaner method cleanQuarantineStatusInBackground.

private static void cleanQuarantineStatusInBackground(@NotNull String folderPath) {
    ProgressIndicatorBase progressIndicator = new ProgressIndicatorBase();
    String message = ApplicationBundle.message("quarantine.clean.progress", folderPath);
    ProgressManager.getInstance().runProcessWithProgressAsynchronously(new Task.Backgroundable(null, message) {

        @Override
        public void run(@NotNull ProgressIndicator indicator) {
            try (Stream<Path> s = Files.walk(Paths.get(folderPath))) {
                s.forEach(p -> {
                    ProgressManager.checkCanceled();
                    XAttrUtil.removeXAttr(p.toFile().getAbsolutePath(), QUARANTINE_ATTRIBUTE);
                });
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        @Override
        public void onThrowable(@NotNull Throwable error) {
            LOG.warn(error);
            new Notification(ApplicationBundle.message("quarantine.error.group"), ApplicationBundle.message("quarantine.error.title"), ApplicationBundle.message("quarantine.error.message"), NotificationType.WARNING).notify(null);
        }
    }, progressIndicator);
}
Also used : ProgressManager(com.intellij.openapi.progress.ProgressManager) ProgressIndicatorBase(com.intellij.openapi.progress.util.ProgressIndicatorBase) Application(com.intellij.openapi.application.Application) VfsUtilCore(com.intellij.openapi.vfs.VfsUtilCore) Files(java.nio.file.Files) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ModalityState(com.intellij.openapi.application.ModalityState) IOException(java.io.IOException) XAttrUtil(com.sun.jna.platform.mac.XAttrUtil) SystemInfo(com.intellij.openapi.util.SystemInfo) NotificationType(com.intellij.notification.NotificationType) Notification(com.intellij.notification.Notification) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) Task(com.intellij.openapi.progress.Task) Stream(java.util.stream.Stream) Paths(java.nio.file.Paths) ApplicationManager(com.intellij.openapi.application.ApplicationManager) Messages(com.intellij.openapi.ui.Messages) URI(java.net.URI) Logger(com.intellij.openapi.diagnostic.Logger) NotNull(org.jetbrains.annotations.NotNull) Path(java.nio.file.Path) ApplicationBundle(com.intellij.openapi.application.ApplicationBundle) Task(com.intellij.openapi.progress.Task) ProgressIndicatorBase(com.intellij.openapi.progress.util.ProgressIndicatorBase) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) Stream(java.util.stream.Stream) IOException(java.io.IOException) Notification(com.intellij.notification.Notification)

Example 23 with ProgressIndicatorBase

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

the class FindDialog method findSettingsChanged.

private void findSettingsChanged() {
    if (haveResultsPreview()) {
        final ModalityState state = ModalityState.current();
        // skip initial changes
        if (state == ModalityState.NON_MODAL)
            return;
        finishPreviousPreviewSearch();
        mySearchRescheduleOnCancellationsAlarm.cancelAllRequests();
        final FindModel findModel = myHelper.getModel().clone();
        applyTo(findModel, false);
        ValidationInfo result = getValidationInfo(findModel);
        final ProgressIndicatorBase progressIndicatorWhenSearchStarted = new ProgressIndicatorBase();
        myResultsPreviewSearchProgress = progressIndicatorWhenSearchStarted;
        final DefaultTableModel model = new DefaultTableModel() {

            @Override
            public boolean isCellEditable(int row, int column) {
                return false;
            }
        };
        // Use previously shown usage files as hint for faster search and better usage preview performance if pattern length increased
        final LinkedHashSet<VirtualFile> filesToScanInitially = new LinkedHashSet<>();
        if (myHelper.myPreviousModel != null && myHelper.myPreviousModel.getStringToFind().length() < findModel.getStringToFind().length()) {
            final DefaultTableModel previousModel = (DefaultTableModel) myResultsPreviewTable.getModel();
            for (int i = 0, len = previousModel.getRowCount(); i < len; ++i) {
                final UsageInfo2UsageAdapter usage = (UsageInfo2UsageAdapter) previousModel.getValueAt(i, 0);
                final VirtualFile file = usage.getFile();
                if (file != null)
                    filesToScanInitially.add(file);
            }
        }
        myHelper.myPreviousModel = findModel;
        model.addColumn("Usages");
        myResultsPreviewTable.setModel(model);
        if (result != null) {
            myResultsPreviewTable.getEmptyText().setText(UIBundle.message("message.nothingToShow"));
            myContent.setTitleAt(RESULTS_PREVIEW_TAB_INDEX, PREVIEW_TITLE);
            return;
        }
        myResultsPreviewTable.getColumnModel().getColumn(0).setCellRenderer(new UsageTableCellRenderer(false, true));
        myResultsPreviewTable.getEmptyText().setText("Searching...");
        myContent.setTitleAt(RESULTS_PREVIEW_TAB_INDEX, PREVIEW_TITLE);
        final Component component = myInputComboBox.getEditor().getEditorComponent();
        // (UsagePreviewPanel.highlight)
        if (component instanceof EditorTextField) {
            final Document document = ((EditorTextField) component).getDocument();
            if (document != null) {
                PsiDocumentManager.getInstance(myProject).commitDocument(document);
            }
        }
        final AtomicInteger resultsCount = new AtomicInteger();
        final AtomicInteger resultsFilesCount = new AtomicInteger();
        ProgressIndicatorUtils.scheduleWithWriteActionPriority(myResultsPreviewSearchProgress, new ReadTask() {

            @Nullable
            @Override
            public Continuation performInReadAction(@NotNull ProgressIndicator indicator) throws ProcessCanceledException {
                final UsageViewPresentation presentation = FindInProjectUtil.setupViewPresentation(FindSettings.getInstance().isShowResultsInSeparateView(), findModel);
                final boolean showPanelIfOnlyOneUsage = !FindSettings.getInstance().isSkipResultsWithOneUsage();
                final FindUsagesProcessPresentation processPresentation = FindInProjectUtil.setupProcessPresentation(myProject, showPanelIfOnlyOneUsage, presentation);
                Ref<VirtualFile> lastUsageFileRef = new Ref<>();
                FindInProjectUtil.findUsages(findModel, myProject, info -> {
                    final Usage usage = UsageInfo2UsageAdapter.CONVERTER.fun(info);
                    usage.getPresentation().getIcon();
                    VirtualFile file = lastUsageFileRef.get();
                    VirtualFile usageFile = info.getVirtualFile();
                    if (file == null || !file.equals(usageFile)) {
                        resultsFilesCount.incrementAndGet();
                        lastUsageFileRef.set(usageFile);
                    }
                    ApplicationManager.getApplication().invokeLater(() -> {
                        model.addRow(new Object[] { usage });
                    }, state);
                    return resultsCount.incrementAndGet() < ShowUsagesAction.USAGES_PAGE_SIZE;
                }, processPresentation, filesToScanInitially);
                boolean succeeded = !progressIndicatorWhenSearchStarted.isCanceled();
                if (succeeded) {
                    return new Continuation(() -> {
                        if (progressIndicatorWhenSearchStarted == myResultsPreviewSearchProgress && !myResultsPreviewSearchProgress.isCanceled()) {
                            int occurrences = resultsCount.get();
                            int filesWithOccurrences = resultsFilesCount.get();
                            if (occurrences == 0)
                                myResultsPreviewTable.getEmptyText().setText(UIBundle.message("message.nothingToShow"));
                            boolean foundAllUsages = occurrences < ShowUsagesAction.USAGES_PAGE_SIZE;
                            myContent.setTitleAt(RESULTS_PREVIEW_TAB_INDEX, PREVIEW_TITLE + " (" + (foundAllUsages ? Integer.valueOf(occurrences) : occurrences + "+") + UIBundle.message("message.matches", occurrences) + " in " + (foundAllUsages ? Integer.valueOf(filesWithOccurrences) : filesWithOccurrences + "+") + UIBundle.message("message.files", filesWithOccurrences) + ")");
                        }
                    }, state);
                }
                return null;
            }

            @Override
            public void onCanceled(@NotNull ProgressIndicator indicator) {
                if (isShowing() && progressIndicatorWhenSearchStarted == myResultsPreviewSearchProgress) {
                    scheduleResultsUpdate();
                }
            }
        });
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Language(com.intellij.lang.Language) FileUtilRt(com.intellij.openapi.util.io.FileUtilRt) UIUtil(com.intellij.util.ui.UIUtil) ReadTask(com.intellij.openapi.progress.util.ReadTask) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ModalityState(com.intellij.openapi.application.ModalityState) Document(com.intellij.openapi.editor.Document) UniqueVFilePathBuilder(com.intellij.openapi.fileEditor.UniqueVFilePathBuilder) ScopeDescriptor(com.intellij.ide.util.scopeChooser.ScopeDescriptor) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) TableCellRenderer(javax.swing.table.TableCellRenderer) SmartList(com.intellij.util.SmartList) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) JBUI(com.intellij.util.ui.JBUI) Disposer(com.intellij.openapi.util.Disposer) DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) Logger(com.intellij.openapi.diagnostic.Logger) Module(com.intellij.openapi.module.Module) ListSelectionEvent(javax.swing.event.ListSelectionEvent) PatternSyntaxException(java.util.regex.PatternSyntaxException) ModuleUtilCore(com.intellij.openapi.module.ModuleUtilCore) DefaultTableModel(javax.swing.table.DefaultTableModel) PlainTextFileType(com.intellij.openapi.fileTypes.PlainTextFileType) com.intellij.ui(com.intellij.ui) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) JBScrollPane(com.intellij.ui.components.JBScrollPane) HelpManager(com.intellij.openapi.help.HelpManager) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) List(java.util.List) java.awt.event(java.awt.event) ApplicationManager(com.intellij.openapi.application.ApplicationManager) Registry(com.intellij.openapi.util.registry.Registry) Pattern(java.util.regex.Pattern) NotNull(org.jetbrains.annotations.NotNull) Ref(com.intellij.openapi.util.Ref) PsiBundle(com.intellij.psi.PsiBundle) FileChooserDescriptorFactory(com.intellij.openapi.fileChooser.FileChooserDescriptorFactory) ProgressIndicatorBase(com.intellij.openapi.progress.util.ProgressIndicatorBase) java.util(java.util) PsiFileFactory(com.intellij.psi.PsiFileFactory) ArrayUtil(com.intellij.util.ArrayUtil) ModuleManager(com.intellij.openapi.module.ModuleManager) UsageInfo(com.intellij.usageView.UsageInfo) ProgressIndicatorUtils(com.intellij.openapi.progress.util.ProgressIndicatorUtils) SearchScope(com.intellij.psi.search.SearchScope) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) Comparing(com.intellij.openapi.util.Comparing) STYLE_PLAIN(com.intellij.ui.SimpleTextAttributes.STYLE_PLAIN) CommonBundle(com.intellij.CommonBundle) UsagePreviewPanel(com.intellij.usages.impl.UsagePreviewPanel) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) PropertyKey(org.jetbrains.annotations.PropertyKey) PsiDocumentManager(com.intellij.psi.PsiDocumentManager) StringUtil(com.intellij.openapi.util.text.StringUtil) com.intellij.usages(com.intellij.usages) Convertor(com.intellij.util.containers.Convertor) com.intellij.find(com.intellij.find) FileType(com.intellij.openapi.fileTypes.FileType) ProjectAttachProcessor(com.intellij.projectImport.ProjectAttachProcessor) JTextComponent(javax.swing.text.JTextComponent) Disposable(com.intellij.openapi.Disposable) java.awt(java.awt) com.intellij.openapi.actionSystem(com.intellij.openapi.actionSystem) JBTable(com.intellij.ui.table.JBTable) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) ScopeChooserCombo(com.intellij.ide.util.scopeChooser.ScopeChooserCombo) com.intellij.openapi.ui(com.intellij.openapi.ui) ShowUsagesAction(com.intellij.find.actions.ShowUsagesAction) UsageViewBundle(com.intellij.usageView.UsageViewBundle) ListSelectionListener(javax.swing.event.ListSelectionListener) FileChooser(com.intellij.openapi.fileChooser.FileChooser) TransactionGuard(com.intellij.openapi.application.TransactionGuard) Condition(com.intellij.openapi.util.Condition) Alarm(com.intellij.util.Alarm) javax.swing(javax.swing) DefaultTableModel(javax.swing.table.DefaultTableModel) Document(com.intellij.openapi.editor.Document) ProgressIndicatorBase(com.intellij.openapi.progress.util.ProgressIndicatorBase) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) JTextComponent(javax.swing.text.JTextComponent) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) Ref(com.intellij.openapi.util.Ref) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ModalityState(com.intellij.openapi.application.ModalityState) Nullable(org.jetbrains.annotations.Nullable) ReadTask(com.intellij.openapi.progress.util.ReadTask)

Example 24 with ProgressIndicatorBase

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

the class FindUsagesManager method startProcessUsages.

@NotNull
public static ProgressIndicator startProcessUsages(@NotNull final FindUsagesHandler handler, @NotNull final PsiElement[] primaryElements, @NotNull final PsiElement[] secondaryElements, @NotNull final Processor<Usage> processor, @NotNull final FindUsagesOptions findUsagesOptions, @NotNull final Runnable onComplete) {
    ApplicationManager.getApplication().assertIsDispatchThread();
    final ProgressIndicatorBase indicator = new ProgressIndicatorBase();
    Task.Backgroundable task = new Task.Backgroundable(handler.getProject(), "Finding Usages") {

        @Override
        public void run(@NotNull ProgressIndicator indicator) {
            UsageSearcher usageSearcher = ReadAction.compute(() -> {
                PsiElement2UsageTargetAdapter[] primaryTargets = PsiElement2UsageTargetAdapter.convert(primaryElements);
                PsiElement2UsageTargetAdapter[] secondaryTargets = PsiElement2UsageTargetAdapter.convert(secondaryElements);
                return createUsageSearcher(primaryTargets, secondaryTargets, handler, findUsagesOptions, null);
            });
            usageSearcher.generate(processor);
        }
    };
    ((ProgressManagerImpl) ProgressManager.getInstance()).runProcessWithProgressAsynchronously(task, indicator, onComplete);
    return indicator;
}
Also used : Task(com.intellij.openapi.progress.Task) ProgressIndicatorBase(com.intellij.openapi.progress.util.ProgressIndicatorBase) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ProgressManagerImpl(com.intellij.openapi.progress.impl.ProgressManagerImpl) NotNull(org.jetbrains.annotations.NotNull) NotNull(org.jetbrains.annotations.NotNull)

Example 25 with ProgressIndicatorBase

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

the class HighlightSuppressedWarningsHandler method computeUsages.

@Override
public void computeUsages(List<PsiLiteralExpression> targets) {
    final Project project = myTarget.getProject();
    final PsiElement parent = myTarget.getParent().getParent();
    final LocalInspectionsPass pass = new LocalInspectionsPass(myFile, myFile.getViewProvider().getDocument(), parent.getTextRange().getStartOffset(), parent.getTextRange().getEndOffset(), myPriorityRange, false, HighlightInfoProcessor.getEmpty());
    InspectionProfileImpl inspectionProfile = InspectionProjectProfileManager.getInstance(project).getCurrentProfile();
    for (PsiLiteralExpression target : targets) {
        final Object value = target.getValue();
        if (!(value instanceof String)) {
            continue;
        }
        List<InspectionToolWrapper> tools = inspectionProfile.findToolsById((String) value, target);
        if (tools == null) {
            continue;
        }
        final List<LocalInspectionToolWrapper> toolsCopy = new ArrayList<>(tools.size());
        for (InspectionToolWrapper tool : tools) {
            if (tool instanceof LocalInspectionToolWrapper) {
                toolsCopy.add((LocalInspectionToolWrapper) tool.createCopy());
            }
        }
        if (toolsCopy.isEmpty()) {
            continue;
        }
        final InspectionManagerEx managerEx = (InspectionManagerEx) InspectionManager.getInstance(project);
        final GlobalInspectionContextImpl context = managerEx.createNewGlobalContext(false);
        for (InspectionToolWrapper toolWrapper : toolsCopy) {
            toolWrapper.initialize(context);
        }
        ((RefManagerImpl) context.getRefManager()).inspectionReadActionStarted();
        ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
        Runnable inspect = () -> pass.doInspectInBatch(context, managerEx, toolsCopy);
        if (indicator == null) {
            ProgressManager.getInstance().executeProcessUnderProgress(inspect, new ProgressIndicatorBase());
        } else {
            inspect.run();
        }
        for (HighlightInfo info : pass.getInfos()) {
            final PsiElement element = CollectHighlightsUtil.findCommonParent(myFile, info.startOffset, info.endOffset);
            if (element != null) {
                addOccurrence(element);
            }
        }
    }
}
Also used : RefManagerImpl(com.intellij.codeInspection.reference.RefManagerImpl) ArrayList(java.util.ArrayList) Project(com.intellij.openapi.project.Project) ProgressIndicatorBase(com.intellij.openapi.progress.util.ProgressIndicatorBase) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator)

Aggregations

ProgressIndicatorBase (com.intellij.openapi.progress.util.ProgressIndicatorBase)25 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)8 DaemonProgressIndicator (com.intellij.codeInsight.daemon.impl.DaemonProgressIndicator)6 DelegatingProgressIndicator (com.intellij.ide.util.DelegatingProgressIndicator)6 ReadTask (com.intellij.openapi.progress.util.ReadTask)6 BombedProgressIndicator (com.intellij.testFramework.BombedProgressIndicator)6 NotNull (org.jetbrains.annotations.NotNull)5 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 ApplicationManager (com.intellij.openapi.application.ApplicationManager)3 ModalityState (com.intellij.openapi.application.ModalityState)3 Logger (com.intellij.openapi.diagnostic.Logger)3 Project (com.intellij.openapi.project.Project)3 Ref (com.intellij.openapi.util.Ref)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 CommonBundle (com.intellij.CommonBundle)2 com.intellij.find (com.intellij.find)2 ShowUsagesAction (com.intellij.find.actions.ShowUsagesAction)2 Disposable (com.intellij.openapi.Disposable)2 com.intellij.openapi.actionSystem (com.intellij.openapi.actionSystem)2