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());
}
}
}
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;
}
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);
}
}
}
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;
}
}
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;
}
Aggregations