Search in sources :

Example 16 with ModalityState

use of com.intellij.openapi.application.ModalityState in project azure-tools-for-java by Microsoft.

the class IntellijAzureTaskManager method doRunLater.

@Override
protected void doRunLater(final Runnable runnable, final AzureTask<?> task) {
    final ModalityState state = toIntellijModality(task);
    ApplicationManager.getApplication().invokeLater(runnable, state);
}
Also used : ModalityState(com.intellij.openapi.application.ModalityState)

Example 17 with ModalityState

use of com.intellij.openapi.application.ModalityState in project azure-tools-for-java by Microsoft.

the class IntellijAzureTaskManager method doRunAndWait.

@Override
protected void doRunAndWait(final Runnable runnable, final AzureTask<?> task) {
    final ModalityState state = toIntellijModality(task);
    ApplicationManager.getApplication().invokeAndWait(runnable, state);
}
Also used : ModalityState(com.intellij.openapi.application.ModalityState)

Example 18 with ModalityState

use of com.intellij.openapi.application.ModalityState in project intellij-community by JetBrains.

the class MergingUpdateQueue method isModalityStateCorrect.

protected boolean isModalityStateCorrect() {
    if (!myExecuteInDispatchThread)
        return true;
    if (myModalityStateComponent == ANY_COMPONENT)
        return true;
    ModalityState current = ApplicationManager.getApplication().getCurrentModalityState();
    final ModalityState modalityState = getModalityState();
    return !current.dominates(modalityState);
}
Also used : ModalityState(com.intellij.openapi.application.ModalityState)

Example 19 with ModalityState

use of com.intellij.openapi.application.ModalityState in project intellij-community by JetBrains.

the class BackgroundTaskUtil method executeAndTryWait.

@NotNull
@CalledInAwt
public static ProgressIndicator executeAndTryWait(@NotNull Function<ProgressIndicator, /*@NotNull*/
Runnable> backgroundTask, @Nullable Runnable onSlowAction, long waitMillis, boolean forceEDT) {
    ModalityState modality = ModalityState.current();
    if (forceEDT) {
        ProgressIndicator indicator = new EmptyProgressIndicator(modality);
        try {
            Runnable callback = backgroundTask.fun(indicator);
            finish(callback, indicator);
        } catch (ProcessCanceledException ignore) {
        } catch (Throwable t) {
            LOG.error(t);
        }
        return indicator;
    } else {
        Pair<Runnable, ProgressIndicator> pair = computeInBackgroundAndTryWait(backgroundTask, (callback, indicator) -> {
            ApplicationManager.getApplication().invokeLater(() -> {
                finish(callback, indicator);
            }, modality);
        }, modality, waitMillis);
        Runnable callback = pair.first;
        ProgressIndicator indicator = pair.second;
        if (callback != null) {
            finish(callback, indicator);
        } else {
            if (onSlowAction != null)
                onSlowAction.run();
        }
        return indicator;
    }
}
Also used : EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ModalityState(com.intellij.openapi.application.ModalityState) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) CalledInAwt(org.jetbrains.annotations.CalledInAwt) NotNull(org.jetbrains.annotations.NotNull)

Example 20 with ModalityState

use of com.intellij.openapi.application.ModalityState in project intellij-community by JetBrains.

the class BackgroundTaskQueue method runTaskInCurrentThread.

private void runTaskInCurrentThread(@NotNull BackgroundableTaskData data) {
    Task.Backgroundable task = data.myTask;
    ProgressIndicator indicator = data.myIndicator;
    if (indicator == null)
        indicator = new EmptyProgressIndicator();
    ModalityState modalityState = data.myModalityState;
    if (modalityState == null)
        modalityState = ModalityState.NON_MODAL;
    ProgressManagerImpl pm = (ProgressManagerImpl) ProgressManager.getInstance();
    // prohibit simultaneous execution from different threads
    synchronized (TEST_TASK_LOCK) {
        pm.runProcessWithProgressInCurrentThread(task, indicator, modalityState);
    }
}
Also used : ProgressManagerImpl(com.intellij.openapi.progress.impl.ProgressManagerImpl) ModalityState(com.intellij.openapi.application.ModalityState)

Aggregations

ModalityState (com.intellij.openapi.application.ModalityState)40 Application (com.intellij.openapi.application.Application)6 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)6 NotNull (org.jetbrains.annotations.NotNull)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 Nullable (org.jetbrains.annotations.Nullable)5 Disposable (com.intellij.openapi.Disposable)4 ListSelectionListener (javax.swing.event.ListSelectionListener)4 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)3 Project (com.intellij.openapi.project.Project)3 List (java.util.List)3 CommonBundle (com.intellij.CommonBundle)2 com.intellij.find (com.intellij.find)2 ShowUsagesAction (com.intellij.find.actions.ShowUsagesAction)2 BaseProjectTreeBuilder (com.intellij.ide.projectView.BaseProjectTreeBuilder)2 AbstractProjectTreeStructure (com.intellij.ide.projectView.impl.AbstractProjectTreeStructure)2 ProjectAbstractTreeStructureBase (com.intellij.ide.projectView.impl.ProjectAbstractTreeStructureBase)2 ProjectTreeBuilder (com.intellij.ide.projectView.impl.ProjectTreeBuilder)2 NodeRenderer (com.intellij.ide.util.treeView.NodeRenderer)2 com.intellij.openapi.actionSystem (com.intellij.openapi.actionSystem)2