Search in sources :

Example 1 with ReadTask

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

the class MvcModuleStructureSynchronizer method scheduleRunActions.

private void scheduleRunActions() {
    if (myProject.isDisposed())
        return;
    final Application app = ApplicationManager.getApplication();
    if (app.isUnitTestMode()) {
        if (ourGrailsTestFlag && !myProject.isInitialized()) {
            runActions(computeRawActions(takeOrderSnapshot()));
        }
        return;
    }
    final Set<Pair<Object, SyncAction>> orderSnapshot = takeOrderSnapshot();
    ReadTask task = new ReadTask() {

        @Nullable
        @Override
        public Continuation performInReadAction(@NotNull final ProgressIndicator indicator) throws ProcessCanceledException {
            final Set<Trinity<Module, SyncAction, MvcFramework>> actions = isUpToDate() ? computeRawActions(orderSnapshot) : Collections.<Trinity<Module, SyncAction, MvcFramework>>emptySet();
            return new Continuation(() -> {
                if (isUpToDate()) {
                    runActions(actions);
                } else if (!indicator.isCanceled()) {
                    scheduleRunActions();
                }
            }, ModalityState.NON_MODAL);
        }

        @Override
        public void onCanceled(@NotNull ProgressIndicator indicator) {
            scheduleRunActions();
        }

        private boolean isUpToDate() {
            return !myProject.isDisposed() && orderSnapshot.equals(takeOrderSnapshot());
        }
    };
    GuiUtils.invokeLaterIfNeeded(() -> ProgressIndicatorUtils.scheduleWithWriteActionPriority(ourExecutor, task), ModalityState.NON_MODAL);
}
Also used : Trinity(com.intellij.openapi.util.Trinity) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) Module(com.intellij.openapi.module.Module) Application(com.intellij.openapi.application.Application) NotNull(org.jetbrains.annotations.NotNull) Pair(com.intellij.openapi.util.Pair) ReadTask(com.intellij.openapi.progress.util.ReadTask)

Example 2 with ReadTask

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

the class FindPopupPanel method findSettingsChanged.

private void findSettingsChanged() {
    if (isShowing()) {
        ScrollingUtil.ensureSelectionExists(myResultsPreviewTable);
    }
    final ModalityState state = ModalityState.current();
    finishPreviousPreviewSearch();
    mySearchRescheduleOnCancellationsAlarm.cancelAllRequests();
    applyTo(myHelper.getModel(), false);
    myHelper.updateFindSettings();
    FindModel findInProjectModel = FindManager.getInstance(myProject).getFindInProjectModel();
    FindModel copy = new FindModel();
    copy.copyFrom(findInProjectModel);
    findInProjectModel.copyFrom(myHelper.getModel());
    //todo check if we really need to do it now
    ((FindManagerImpl) FindManager.getInstance(myProject)).changeGlobalSettings(myHelper.getModel());
    FindSettings findSettings = FindSettings.getInstance();
    myScopeUI.applyTo(findSettings, mySelectedScope);
    findSettings.setFileMask(myHelper.getModel().getFileFilter());
    ValidationInfo result = getValidationInfo(myHelper.getModel());
    final ProgressIndicatorBase progressIndicatorWhenSearchStarted = new ProgressIndicatorBase();
    myResultsPreviewSearchProgress = progressIndicatorWhenSearchStarted;
    final DefaultTableModel model = new DefaultTableModel() {

        @Override
        public boolean isCellEditable(int row, int column) {
            return false;
        }
    };
    model.addColumn("Usages");
    // 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() < myHelper.getModel().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 = myHelper.getModel().clone();
    myCodePreviewComponent.setVisible(false);
    mySearchTextArea.setInfoText(null);
    myResultsPreviewTable.setModel(model);
    if (result != null) {
        myResultsPreviewTable.getEmptyText().setText(UIBundle.message("message.nothingToShow") + " (" + result.message + ")");
        return;
    }
    myResultsPreviewTable.getColumnModel().getColumn(0).setCellRenderer(new FindDialog.UsageTableCellRenderer(myCbFileFilter.isSelected(), false));
    myResultsPreviewTable.getEmptyText().setText("Searching...");
    final AtomicInteger resultsCount = new AtomicInteger();
    final AtomicInteger resultsFilesCount = new AtomicInteger();
    ProgressIndicatorUtils.scheduleWithWriteActionPriority(myResultsPreviewSearchProgress, new ReadTask() {

        @Override
        public void computeInReadAction(@NotNull ProgressIndicator indicator) {
            final UsageViewPresentation presentation = FindInProjectUtil.setupViewPresentation(findSettings.isShowResultsInSeparateView(), /*findModel*/
            myHelper.getModel().clone());
            final boolean showPanelIfOnlyOneUsage = !findSettings.isSkipResultsWithOneUsage();
            final FindUsagesProcessPresentation processPresentation = FindInProjectUtil.setupProcessPresentation(myProject, showPanelIfOnlyOneUsage, presentation);
            Ref<VirtualFile> lastUsageFileRef = new Ref<>();
            FindInProjectUtil.findUsages(myHelper.getModel().clone(), 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 });
                    myCodePreviewComponent.setVisible(true);
                    if (model.getRowCount() == 1 && myResultsPreviewTable.getModel() == model) {
                        myResultsPreviewTable.setRowSelectionInterval(0, 0);
                    }
                }, state);
                return resultsCount.incrementAndGet() < ShowUsagesAction.USAGES_PAGE_SIZE;
            }, processPresentation, filesToScanInitially);
            boolean succeeded = !progressIndicatorWhenSearchStarted.isCanceled();
            if (succeeded) {
                ApplicationManager.getApplication().invokeLater(() -> {
                    if (progressIndicatorWhenSearchStarted == myResultsPreviewSearchProgress && !myResultsPreviewSearchProgress.isCanceled()) {
                        int occurrences = resultsCount.get();
                        int filesWithOccurrences = resultsFilesCount.get();
                        if (occurrences == 0)
                            myResultsPreviewTable.getEmptyText().setText(UIBundle.message("message.nothingToShow"));
                        myCodePreviewComponent.setVisible(occurrences > 0);
                        StringBuilder info = new StringBuilder();
                        if (occurrences > 0) {
                            info.append(Math.min(ShowUsagesAction.USAGES_PAGE_SIZE, occurrences));
                            boolean foundAllUsages = occurrences < ShowUsagesAction.USAGES_PAGE_SIZE;
                            if (!foundAllUsages) {
                                info.append("+");
                            }
                            info.append(UIBundle.message("message.matches", occurrences));
                            info.append(" in ");
                            info.append(filesWithOccurrences);
                            if (!foundAllUsages) {
                                info.append("+");
                            }
                            info.append(UIBundle.message("message.files", filesWithOccurrences));
                        }
                        mySearchTextArea.setInfoText(info.toString());
                    }
                }, state);
            }
        }

        @Override
        public void onCanceled(@NotNull ProgressIndicator indicator) {
            if (isShowing() && progressIndicatorWhenSearchStarted == myResultsPreviewSearchProgress) {
                scheduleResultsUpdate();
            }
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) UsageViewPresentation(com.intellij.usages.UsageViewPresentation) com.intellij.openapi.util(com.intellij.openapi.util) JBInsets(com.intellij.util.ui.JBInsets) UIUtil(com.intellij.util.ui.UIUtil) AllIcons(com.intellij.icons.AllIcons) ReadTask(com.intellij.openapi.progress.util.ReadTask) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ModalityState(com.intellij.openapi.application.ModalityState) JBLabel(com.intellij.ui.components.JBLabel) SmartList(com.intellij.util.SmartList) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) JBUI(com.intellij.util.ui.JBUI) Messages(com.intellij.openapi.ui.Messages) Logger(com.intellij.openapi.diagnostic.Logger) ListSelectionEvent(javax.swing.event.ListSelectionEvent) JBFont(com.intellij.util.ui.JBFont) ValidationInfo(com.intellij.openapi.ui.ValidationInfo) CustomComponentAction(com.intellij.openapi.actionSystem.ex.CustomComponentAction) ComponentPopupBuilder(com.intellij.openapi.ui.popup.ComponentPopupBuilder) PatternSyntaxException(java.util.regex.PatternSyntaxException) DefaultTableModel(javax.swing.table.DefaultTableModel) ActionButton(com.intellij.openapi.actionSystem.impl.ActionButton) WindowManager(com.intellij.openapi.wm.WindowManager) UsageViewPresentation(com.intellij.usages.UsageViewPresentation) KeymapUtil(com.intellij.openapi.keymap.KeymapUtil) com.intellij.ui(com.intellij.ui) JBScrollPane(com.intellij.ui.components.JBScrollPane) HelpManager(com.intellij.openapi.help.HelpManager) ListPopup(com.intellij.openapi.ui.popup.ListPopup) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) List(java.util.List) IdeFocusManager(com.intellij.openapi.wm.IdeFocusManager) JBPanel(com.intellij.ui.components.JBPanel) 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) RelativePoint(com.intellij.ui.awt.RelativePoint) ProgressIndicatorBase(com.intellij.openapi.progress.util.ProgressIndicatorBase) java.util(java.util) ArrayUtil(com.intellij.util.ArrayUtil) ActionToolbarImpl(com.intellij.openapi.actionSystem.impl.ActionToolbarImpl) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) UsageInfo(com.intellij.usageView.UsageInfo) ProgressIndicatorUtils(com.intellij.openapi.progress.util.ProgressIndicatorUtils) ContainerUtil(com.intellij.util.containers.ContainerUtil) UsageInfo2UsageAdapter(com.intellij.usages.UsageInfo2UsageAdapter) ActionButtonWithText(com.intellij.openapi.actionSystem.impl.ActionButtonWithText) CommonBundle(com.intellij.CommonBundle) IdeFrameImpl(com.intellij.openapi.wm.impl.IdeFrameImpl) FindUsagesProcessPresentation(com.intellij.usages.FindUsagesProcessPresentation) UsagePreviewPanel(com.intellij.usages.impl.UsagePreviewPanel) Project(com.intellij.openapi.project.Project) DocumentEvent(javax.swing.event.DocumentEvent) VfsUtilCore(com.intellij.openapi.vfs.VfsUtilCore) Usage(com.intellij.usages.Usage) StringUtil(com.intellij.openapi.util.text.StringUtil) MigLayout(net.miginfocom.swing.MigLayout) com.intellij.find(com.intellij.find) UISettings(com.intellij.ide.ui.UISettings) OnePixelDivider(com.intellij.openapi.ui.OnePixelDivider) Disposable(com.intellij.openapi.Disposable) JBPopup(com.intellij.openapi.ui.popup.JBPopup) java.awt(java.awt) com.intellij.openapi.actionSystem(com.intellij.openapi.actionSystem) JBTable(com.intellij.ui.table.JBTable) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) JBPopupFactory(com.intellij.openapi.ui.popup.JBPopupFactory) ShowUsagesAction(com.intellij.find.actions.ShowUsagesAction) MnemonicHelper(com.intellij.openapi.MnemonicHelper) ListSelectionListener(javax.swing.event.ListSelectionListener) Alarm(com.intellij.util.Alarm) javax.swing(javax.swing) DefaultTableModel(javax.swing.table.DefaultTableModel) ProgressIndicatorBase(com.intellij.openapi.progress.util.ProgressIndicatorBase) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) Usage(com.intellij.usages.Usage) FindUsagesProcessPresentation(com.intellij.usages.FindUsagesProcessPresentation) RelativePoint(com.intellij.ui.awt.RelativePoint) ValidationInfo(com.intellij.openapi.ui.ValidationInfo) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) UsageInfo2UsageAdapter(com.intellij.usages.UsageInfo2UsageAdapter) ModalityState(com.intellij.openapi.application.ModalityState) ReadTask(com.intellij.openapi.progress.util.ReadTask)

Example 3 with ReadTask

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

the class EditorNotificationsImpl method updateNotifications.

@Override
public void updateNotifications(@NotNull final VirtualFile file) {
    UIUtil.invokeLaterIfNeeded(() -> {
        ProgressIndicator indicator = getCurrentProgress(file);
        if (indicator != null) {
            indicator.cancel();
        }
        file.putUserData(CURRENT_UPDATES, null);
        if (myProject.isDisposed() || !file.isValid()) {
            return;
        }
        indicator = new ProgressIndicatorBase();
        final ReadTask task = createTask(indicator, file);
        if (task == null)
            return;
        file.putUserData(CURRENT_UPDATES, new WeakReference<>(indicator));
        if (ApplicationManager.getApplication().isUnitTestMode()) {
            ReadTask.Continuation continuation = task.performInReadAction(indicator);
            if (continuation != null) {
                continuation.getAction().run();
            }
        } else {
            ProgressIndicatorUtils.scheduleWithWriteActionPriority(indicator, ourExecutor, task);
        }
    });
}
Also used : ProgressIndicatorBase(com.intellij.openapi.progress.util.ProgressIndicatorBase) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ReadTask(com.intellij.openapi.progress.util.ReadTask)

Example 4 with ReadTask

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

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

the class ProgressIndicatorTest method testProgressIndicatorUtilsScheduleWithWriteActionPriority.

public void testProgressIndicatorUtilsScheduleWithWriteActionPriority() throws Throwable {
    final AtomicBoolean insideReadAction = new AtomicBoolean();
    final ProgressIndicatorBase indicator = new ProgressIndicatorBase();
    ProgressIndicatorUtils.scheduleWithWriteActionPriority(indicator, new ReadTask() {

        @Override
        public void computeInReadAction(@NotNull ProgressIndicator indicator) {
            insideReadAction.set(true);
            while (true) {
                ProgressManager.checkCanceled();
            }
        }

        @Override
        public void onCanceled(@NotNull ProgressIndicator indicator) {
        }
    });
    UIUtil.dispatchAllInvocationEvents();
    while (!insideReadAction.get()) {
    }
    ApplicationManager.getApplication().runWriteAction(() -> assertTrue(indicator.isCanceled()));
    assertTrue(indicator.isCanceled());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) 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) ReadTask(com.intellij.openapi.progress.util.ReadTask)

Aggregations

ReadTask (com.intellij.openapi.progress.util.ReadTask)7 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)5 ProgressIndicatorBase (com.intellij.openapi.progress.util.ProgressIndicatorBase)5 NotNull (org.jetbrains.annotations.NotNull)4 Nullable (org.jetbrains.annotations.Nullable)3 CommonBundle (com.intellij.CommonBundle)2 DaemonProgressIndicator (com.intellij.codeInsight.daemon.impl.DaemonProgressIndicator)2 com.intellij.find (com.intellij.find)2 ShowUsagesAction (com.intellij.find.actions.ShowUsagesAction)2 DelegatingProgressIndicator (com.intellij.ide.util.DelegatingProgressIndicator)2 Disposable (com.intellij.openapi.Disposable)2 com.intellij.openapi.actionSystem (com.intellij.openapi.actionSystem)2 ApplicationManager (com.intellij.openapi.application.ApplicationManager)2 ModalityState (com.intellij.openapi.application.ModalityState)2 Logger (com.intellij.openapi.diagnostic.Logger)2 HelpManager (com.intellij.openapi.help.HelpManager)2 Module (com.intellij.openapi.module.Module)2 ProgressIndicatorUtils (com.intellij.openapi.progress.util.ProgressIndicatorUtils)2 DumbAwareAction (com.intellij.openapi.project.DumbAwareAction)2 BombedProgressIndicator (com.intellij.testFramework.BombedProgressIndicator)2