Search in sources :

Example 1 with ModalityState

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

the class HgRunConflictResolverDialog method onChangeRepository.

private void onChangeRepository() {
    VirtualFile repo = repositorySelector.getRepository().getRoot();
    HgResolveCommand command = new HgResolveCommand(project);
    final ModalityState modalityState = ApplicationManager.getApplication().getModalityStateForComponent(getRootPane());
    command.getListAsynchronously(repo, new Consumer<Map<HgFile, HgResolveStatusEnum>>() {

        @Override
        public void consume(Map<HgFile, HgResolveStatusEnum> status) {
            final DefaultListModel model = new DefaultListModel();
            for (Map.Entry<HgFile, HgResolveStatusEnum> entry : status.entrySet()) {
                if (entry.getValue() == HgResolveStatusEnum.UNRESOLVED) {
                    model.addElement(entry.getKey().getRelativePath());
                }
            }
            ApplicationManager.getApplication().invokeLater(new Runnable() {

                @Override
                public void run() {
                    setOKActionEnabled(!model.isEmpty());
                    if (model.isEmpty()) {
                        model.addElement("No conflicts to resolve");
                    }
                    conflictsList.setModel(model);
                }
            }, modalityState);
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) HgFile(org.zmlx.hg4idea.HgFile) HgResolveCommand(org.zmlx.hg4idea.command.HgResolveCommand) HgResolveStatusEnum(org.zmlx.hg4idea.command.HgResolveStatusEnum) ModalityState(com.intellij.openapi.application.ModalityState) Map(java.util.Map)

Example 2 with ModalityState

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

the class RepositoryLoader method startLoadTask.

private void startLoadTask(@NotNull final Pair<RepositoryTreeNode, Expander> data) {
    final ModalityState state = ModalityState.current();
    ApplicationManager.getApplication().executeOnPooledThread(() -> ProgressManager.getInstance().runProcess(new LoadTask(data), new EmptyProgressIndicator(state)));
}
Also used : EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) ModalityState(com.intellij.openapi.application.ModalityState)

Example 3 with ModalityState

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

the class CompilerTask method addMessage.

public void addMessage(final CompilerMessage message) {
    prepareMessageView();
    final CompilerMessageCategory messageCategory = message.getCategory();
    if (CompilerMessageCategory.WARNING.equals(messageCategory)) {
        myWarningCount += 1;
    } else if (CompilerMessageCategory.ERROR.equals(messageCategory)) {
        myErrorCount += 1;
        informWolf(message);
    }
    if (ApplicationManager.getApplication().isDispatchThread()) {
        openMessageView();
        doAddMessage(message);
    } else {
        final Window window = getWindow();
        final ModalityState modalityState = window != null ? ModalityState.stateForComponent(window) : ModalityState.NON_MODAL;
        ApplicationManager.getApplication().invokeLater(() -> {
            if (myProject != null && !myProject.isDisposed()) {
                openMessageView();
                doAddMessage(message);
            }
        }, modalityState);
    }
}
Also used : CompilerMessageCategory(com.intellij.openapi.compiler.CompilerMessageCategory) ToolWindow(com.intellij.openapi.wm.ToolWindow) ModalityState(com.intellij.openapi.application.ModalityState)

Example 4 with ModalityState

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

the class WaitForProgressToShow method runOrInvokeAndWaitAboveProgress.

public static void runOrInvokeAndWaitAboveProgress(final Runnable command, @Nullable final ModalityState modalityState) {
    final Application application = ApplicationManager.getApplication();
    if (application.isDispatchThread()) {
        command.run();
    } else {
        final ProgressIndicator pi = ProgressManager.getInstance().getProgressIndicator();
        if (pi != null) {
            execute(pi);
            application.invokeAndWait(command);
        } else {
            final ModalityState notNullModalityState = modalityState == null ? ModalityState.NON_MODAL : modalityState;
            application.invokeAndWait(command, notNullModalityState);
        }
    }
}
Also used : ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ModalityState(com.intellij.openapi.application.ModalityState) Application(com.intellij.openapi.application.Application)

Example 5 with ModalityState

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

the class WaitForProgressToShow method runOrInvokeLaterAboveProgress.

public static void runOrInvokeLaterAboveProgress(final Runnable command, @Nullable final ModalityState modalityState, @NotNull final Project project) {
    final Application application = ApplicationManager.getApplication();
    if (application.isDispatchThread()) {
        command.run();
    } else {
        final ProgressIndicator pi = ProgressManager.getInstance().getProgressIndicator();
        if (pi != null) {
            execute(pi);
            application.invokeLater(command, pi.getModalityState(), o -> (!project.isOpen()) || project.isDisposed());
        } else {
            final ModalityState notNullModalityState = modalityState == null ? ModalityState.NON_MODAL : modalityState;
            application.invokeLater(command, notNullModalityState, project.getDisposed());
        }
    }
}
Also used : ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ModalityState(com.intellij.openapi.application.ModalityState) Application(com.intellij.openapi.application.Application)

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