use of com.intellij.openapi.application.ModalityState in project intellij-community by JetBrains.
the class ThreadDumpInfo method runUnderPerformanceMonitor.
@Override
public void runUnderPerformanceMonitor(@Nullable Project project, @NotNull Runnable action) {
if (!shouldReport() || isUnderDebug() || ApplicationManager.getApplication().isUnitTestMode()) {
action.run();
return;
}
final ModalityState initial = ModalityState.current();
ALARM.cancelAllRequests();
ALARM.addRequest(() -> dumpThreads(project, initial), MAX_ALLOWED_TIME);
try {
action.run();
} finally {
ALARM.cancelAllRequests();
}
}
use of com.intellij.openapi.application.ModalityState in project intellij-community by JetBrains.
the class PlatformTestUtil method waitForAlarm.
@TestOnly
public static void waitForAlarm(final int delay) {
Application app = ApplicationManager.getApplication();
assert !app.isWriteAccessAllowed() : "It's a bad idea to wait for an alarm under the write action. Somebody creates an alarm which requires read action and you are deadlocked.";
assert app.isDispatchThread();
Disposable tempDisposable = Disposer.newDisposable();
final AtomicBoolean runnableInvoked = new AtomicBoolean();
final AtomicBoolean pooledRunnableInvoked = new AtomicBoolean();
final AtomicBoolean alarmInvoked1 = new AtomicBoolean();
final AtomicBoolean alarmInvoked2 = new AtomicBoolean();
final Alarm alarm = new Alarm(Alarm.ThreadToUse.SWING_THREAD);
final Alarm pooledAlarm = new Alarm(Alarm.ThreadToUse.POOLED_THREAD, tempDisposable);
ModalityState initialModality = ModalityState.current();
alarm.addRequest(() -> {
alarmInvoked1.set(true);
app.invokeLater(() -> {
runnableInvoked.set(true);
alarm.addRequest(() -> alarmInvoked2.set(true), delay);
});
}, delay);
pooledAlarm.addRequest(() -> pooledRunnableInvoked.set(true), delay);
UIUtil.dispatchAllInvocationEvents();
long start = System.currentTimeMillis();
boolean sleptAlready = false;
try {
while (!alarmInvoked2.get()) {
AtomicBoolean laterInvoked = new AtomicBoolean();
ApplicationManager.getApplication().invokeLater(() -> laterInvoked.set(true));
UIUtil.dispatchAllInvocationEvents();
Assert.assertTrue(laterInvoked.get());
TimeoutUtil.sleep(sleptAlready ? 10 : delay);
sleptAlready = true;
if (System.currentTimeMillis() - start > 100 * 1000) {
throw new AssertionError("Couldn't await alarm" + "; alarm passed=" + alarmInvoked1.get() + "; modality1=" + initialModality + "; modality2=" + ModalityState.current() + "; non-modal=" + (initialModality == ModalityState.NON_MODAL) + "; invokeLater passed=" + runnableInvoked.get() + "; pooled alarm passed=" + pooledRunnableInvoked.get() + "; app.disposed=" + app.isDisposed() + "; alarm.disposed=" + alarm.isDisposed() + "; alarm.requests=" + alarm.getActiveRequestCount() + "\n delayQueue=" + StringUtil.trimLog(((AppScheduledExecutorService) AppExecutorUtil.getAppScheduledExecutorService()).dumpQueue(), 1000) + "\n invocatorQueue=" + LaterInvocator.getLaterInvocatorQueue());
}
}
} finally {
Disposer.dispose(tempDisposable);
}
UIUtil.dispatchAllInvocationEvents();
}
use of com.intellij.openapi.application.ModalityState in project intellij-community by JetBrains.
the class ChangesBrowserDialog method initDialog.
private void initDialog(final Project project, final CommittedChangesTableModel changes, final Mode mode) {
myProject = project;
myChanges = changes;
myMode = mode;
setTitle(VcsBundle.message("dialog.title.changes.browser"));
setCancelButtonText(CommonBundle.getCloseButtonText());
final ModalityState currentState = ModalityState.current();
if ((mode != Mode.Choose) && (ModalityState.NON_MODAL.equals(currentState))) {
setModal(false);
}
myAppender = new AsynchConsumer<List<CommittedChangeList>>() {
public void finished() {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
if (ChangesBrowserDialog.this.isShowing()) {
myCommittedChangesBrowser.stopLoading();
}
}
});
}
public void consume(final List<CommittedChangeList> committedChangeLists) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
if (ChangesBrowserDialog.this.isShowing()) {
final boolean selectFirst = (myChanges.getRowCount() == 0) && (!committedChangeLists.isEmpty());
myChanges.addRows(committedChangeLists);
if (selectFirst) {
myCommittedChangesBrowser.selectFirstIfAny();
}
}
}
});
}
};
init();
if (myInitRunnable != null) {
new AdjustComponentWhenShown() {
@Override
protected boolean init() {
myInitRunnable.consume(ChangesBrowserDialog.this);
return true;
}
}.install(myCommittedChangesBrowser);
}
}
use of com.intellij.openapi.application.ModalityState in project intellij-community by JetBrains.
the class AbstractPopup method dispose.
@Override
public void dispose() {
if (myState == State.SHOWN) {
LOG.debug("shown popup must be cancelled");
cancel();
}
if (myState == State.DISPOSE) {
return;
}
debugState("dispose popup", State.INIT, State.CANCEL);
myState = State.DISPOSE;
if (myDisposed) {
return;
}
myDisposed = true;
if (LOG.isDebugEnabled()) {
LOG.debug("start disposing " + myContent);
}
Disposer.dispose(this, false);
ApplicationManager.getApplication().assertIsDispatchThread();
if (myPopup != null) {
cancel(myDisposeEvent);
}
if (myContent != null) {
Container parent = myContent.getParent();
if (parent != null)
parent.remove(myContent);
myContent.removeAll();
myContent.removeKeyListener(mySearchKeyListener);
}
myContent = null;
myPreferredFocusedComponent = null;
myComponent = null;
myFocusTrackback = null;
myCallBack = null;
myListeners = null;
if (myMouseOutCanceller != null) {
final Toolkit toolkit = Toolkit.getDefaultToolkit();
// http://www.jetbrains.net/jira/browse/IDEADEV-21265
if (toolkit != null) {
toolkit.removeAWTEventListener(myMouseOutCanceller);
}
}
myMouseOutCanceller = null;
if (myFinalRunnable != null) {
final ActionCallback typeAheadDone = new ActionCallback();
IdeFocusManager.getInstance(myProject).typeAheadUntil(typeAheadDone);
ModalityState modalityState = ModalityState.current();
Runnable finalRunnable = myFinalRunnable;
getFocusManager().doWhenFocusSettlesDown(() -> {
//noinspection SSBasedInspection
SwingUtilities.invokeLater(() -> {
if (ModalityState.current().equals(modalityState)) {
((TransactionGuardImpl) TransactionGuard.getInstance()).performUserActivity(finalRunnable);
}
// Otherwise the UI has changed unexpectedly and the action is likely not applicable.
// And we don't want finalRunnable to perform potentially destructive actions
// in the context of a suddenly appeared modal dialog.
});
//noinspection SSBasedInspection
SwingUtilities.invokeLater(typeAheadDone.createSetDoneRunnable());
myFinalRunnable = null;
});
}
if (LOG.isDebugEnabled()) {
LOG.debug("stop disposing content");
}
}
use of com.intellij.openapi.application.ModalityState in project intellij-community by JetBrains.
the class ModalityContextImpl method getCurrentModalityState.
private ModalityState getCurrentModalityState() {
ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator();
ModalityState modalityState = progressIndicator == null ? myDefaultModalityState : progressIndicator.getModalityState();
if (modalityState == null)
modalityState = ModalityState.defaultModalityState();
return modalityState;
}
Aggregations