/** * Runs a thread when initialized * * @param project * @param r */ public static void runWhenInitialized(final Project project, final Runnable r) { if (project.isDisposed()) return; if (isNoBackgroundMode()) { r.run(); return; } if (!project.isInitialized()) { StartupManager.getInstance(project).registerPostStartupActivity(DisposeAwareRunnable.create(r, project)); return; } runDumbAware(project, r); }
/** * Runs a runnable once the specified project has been initialized. * * @param project * The project. * @param runnable * The runnable. */ private static void runWhenInitialized(final Project project, final Runnable runnable) { if(project.isDisposed()) // Project is disposed. Nothing to do. return; final Application application = ApplicationManager.getApplication(); if(application.isHeadlessEnvironment() || application.isUnitTestMode()) { // Runnable cannot be run in background. Just run it. runnable.run(); } else if(!project.isInitialized()) { // Run runnable once project has initialized. StartupManager.getInstance(project) .registerPostStartupActivity(DisposeAwareRunnable.create(runnable, project)); } else if(DumbService.isDumbAware(runnable)) { // The runnable is dumb aware. Just run it. runnable.run(); } else { // The runnable is not dumb aware. Run it when applicable. DumbService.getInstance(project).runWhenSmart(DisposeAwareRunnable.create(runnable, project)); } }
public static void runWhenInitialized(final Project project, final Runnable r) { if (project.isDisposed()) return; if (isNoBackgroundMode()) { r.run(); return; } if (!project.isInitialized()) { StartupManager.getInstance(project).registerPostStartupActivity(DisposeAwareRunnable.create(r, project)); return; } runDumbAware(project, r); }
public static void invokeLater(final Project p, final ModalityState state, final Runnable r) { if (isNoBackgroundMode()) { r.run(); } else { ApplicationManager.getApplication().invokeLater(DisposeAwareRunnable.create(r, p), state); } }
public static void invokeAndWait(final Project p, final ModalityState state, final Runnable r) { if (isNoBackgroundMode()) { r.run(); } else { ApplicationManager.getApplication().invokeAndWait(DisposeAwareRunnable.create(r, p), state); } }
public static void runDumbAware(final Project project, final Runnable r) { if (DumbService.isDumbAware(r)) { r.run(); } else { DumbService.getInstance(project).runWhenSmart(DisposeAwareRunnable.create(r, project)); } }
public static void invokeAndWait(final Project p, final ModalityState state, final Runnable r) { if (isNoBackgroundMode()) { r.run(); } else { if (ApplicationManager.getApplication().isDispatchThread()) { r.run(); } else { ApplicationManager.getApplication().invokeAndWait(DisposeAwareRunnable.create(r, p), state); } } }
public void show(@Nullable final Runnable runnable, boolean focus) { Runnable r = null; if (runnable != null) { r = DisposeAwareRunnable.create(runnable, myProject); } myToolWindow.activate(r, focus); }
/** * Runs the DumbService * @param project * @param r */ public static void runDumbAware(final Project project, final Runnable r) { if (DumbService.isDumbAware(r)) { r.run(); } else { DumbService.getInstance(project).runWhenSmart(DisposeAwareRunnable.create(r, project)); } }