Search in sources :

Example 26 with Application

use of com.intellij.openapi.application.Application 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)

Example 27 with Application

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

the class QueueProcessor method startProcessing.

private boolean startProcessing() {
    LOG.assertTrue(Thread.holdsLock(myQueue));
    if (isProcessing || !myStarted) {
        return false;
    }
    isProcessing = true;
    final T item = myQueue.removeFirst();
    final Runnable runnable = () -> {
        if (myDeathCondition.value(null))
            return;
        runSafely(() -> myProcessor.consume(item, myContinuationContext));
    };
    final Application application = ApplicationManager.getApplication();
    if (myThreadToUse == ThreadToUse.AWT) {
        final ModalityState state = myModalityState.remove(item);
        if (state != null) {
            application.invokeLater(runnable, state);
        } else {
            application.invokeLater(runnable);
        }
    } else {
        application.executeOnPooledThread(runnable);
    }
    return true;
}
Also used : ModalityState(com.intellij.openapi.application.ModalityState) Application(com.intellij.openapi.application.Application)

Example 28 with Application

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

the class UiNotifyConnector method hierarchyChanged.

public void hierarchyChanged(@NotNull HierarchyEvent e) {
    if (isDisposed())
        return;
    if ((e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) > 0) {
        final Runnable runnable = new DumbAwareRunnable() {

            public void run() {
                final Component c = myComponent.get();
                if (isDisposed() || c == null)
                    return;
                if (c.isShowing()) {
                    showNotify();
                } else {
                    hideNotify();
                }
            }
        };
        final Application app = ApplicationManager.getApplication();
        if (app != null && app.isDispatchThread()) {
            app.invokeLater(runnable, ModalityState.current());
        } else {
            //noinspection SSBasedInspection
            SwingUtilities.invokeLater(runnable);
        }
    }
}
Also used : DumbAwareRunnable(com.intellij.openapi.project.DumbAwareRunnable) Application(com.intellij.openapi.application.Application) DumbAwareRunnable(com.intellij.openapi.project.DumbAwareRunnable)

Example 29 with Application

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

the class _LastInSuiteTest method testProjectLeak.

public void testProjectLeak() throws Exception {
    boolean guiTestMode = Boolean.getBoolean("idea.test.guimode");
    if (guiTestMode) {
        final Application application = ApplicationManager.getApplication();
        TransactionGuard.getInstance().submitTransactionAndWait(() -> {
            IdeEventQueue.getInstance().flushQueue();
            ((ApplicationImpl) application).exit(true, true, false);
        });
        ShutDownTracker.getInstance().waitFor(100, TimeUnit.SECONDS);
        return;
    }
    UIUtil.invokeAndWaitIfNeeded((Runnable) () -> {
        try {
            LightPlatformTestCase.initApplication();
        } catch (RuntimeException e) {
            throw e;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        PlatformTestUtil.cleanupAllProjects();
        ApplicationImpl application = (ApplicationImpl) ApplicationManager.getApplication();
        System.out.println(application.writeActionStatistics());
        System.out.println(ActionUtil.ActionPauses.STAT.statistics());
        System.out.println(((AppScheduledExecutorService) AppExecutorUtil.getAppScheduledExecutorService()).statistics());
        System.out.println("ProcessIOExecutorService threads created: " + ((ProcessIOExecutorService) ProcessIOExecutorService.INSTANCE).getThreadCounter());
        application.setDisposeInProgress(true);
        LightPlatformTestCase.disposeApplication();
        UIUtil.dispatchAllInvocationEvents();
    });
    try {
        LeakHunter.checkProjectLeak();
        Disposer.assertIsEmpty(true);
    } catch (AssertionError | Exception e) {
        captureMemorySnapshot();
        throw e;
    }
    try {
        Disposer.assertIsEmpty(true);
    } catch (AssertionError | Exception e) {
        captureMemorySnapshot();
        throw e;
    }
}
Also used : AppScheduledExecutorService(com.intellij.util.concurrency.AppScheduledExecutorService) ApplicationImpl(com.intellij.openapi.application.impl.ApplicationImpl) Application(com.intellij.openapi.application.Application)

Example 30 with Application

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

the class IdeTestApplication method disposeInstance.

public static synchronized void disposeInstance() {
    if (!isLoaded()) {
        return;
    }
    IdeEventQueue.getInstance().flushQueue();
    final Application application = ApplicationManager.getApplication();
    ((ApplicationImpl) application).exit(true, true, false, false);
    ourInstance = null;
}
Also used : ApplicationImpl(com.intellij.openapi.application.impl.ApplicationImpl) Application(com.intellij.openapi.application.Application)

Aggregations

Application (com.intellij.openapi.application.Application)188 NotNull (org.jetbrains.annotations.NotNull)23 VirtualFile (com.intellij.openapi.vfs.VirtualFile)21 IOException (java.io.IOException)14 Project (com.intellij.openapi.project.Project)13 Nullable (org.jetbrains.annotations.Nullable)12 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)9 ModalityState (com.intellij.openapi.application.ModalityState)8 Ref (com.intellij.openapi.util.Ref)7 ArrayList (java.util.ArrayList)7 List (java.util.List)6 ApplicationImpl (com.intellij.openapi.application.impl.ApplicationImpl)5 ApplicationManager (com.intellij.openapi.application.ApplicationManager)4 ApplicationEx (com.intellij.openapi.application.ex.ApplicationEx)4 Document (com.intellij.openapi.editor.Document)4 Module (com.intellij.openapi.module.Module)4 Computable (com.intellij.openapi.util.Computable)4 PsiFile (com.intellij.psi.PsiFile)4 File (java.io.File)4 Editor (com.intellij.openapi.editor.Editor)3