use of com.intellij.notification.Notifications in project google-cloud-intellij by GoogleCloudPlatform.
the class CloudSdkServiceManager method doWait.
/**
* Performs generic wait in a separate thread for SDK to become ready, returns immediately. Must
* be called from UI thread.
*/
private void doWait(@Nullable Project project, Runnable afterWaitComplete, String progressMessage, CloudSdkStatusHandler sdkLogging) {
CloudSdkService cloudSdkService = CloudSdkService.getInstance();
// even if status is READY, this will double-check the current state from the last install.
if (cloudSdkService.isInstallSupported()) {
cloudSdkService.install();
}
// no need to wait for install if unsupported or completed.
CountDownLatch installationCompletionLatch = new CountDownLatch(isInstallInProgress() ? 1 : 0);
// listener for SDK updates, waits until install / update is done. uses latch to notify UI
// blocking thread.
final CloudSdkService.SdkStatusUpdateListener sdkStatusUpdateListener = (sdkService, status) -> {
switch(status) {
case READY:
case INVALID:
case NOT_AVAILABLE:
installationCompletionLatch.countDown();
break;
default:
}
};
if (isInstallInProgress()) {
cloudSdkService.addStatusUpdateListener(sdkStatusUpdateListener);
sdkLogging.log(GctBundle.getString("managedsdk.waiting.for.sdk.ready") + "\n");
openBackgroundProcessWindow(project);
}
// wait for SDK to be ready and trigger the actual deployment if it properly installs.
ProgressManager.getInstance().run(new Task.Backgroundable(project, progressMessage, true) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
try {
while (installationCompletionLatch.getCount() > 0) {
// wait interruptibility to check for user cancel each second.
installationCompletionLatch.await(1, SECONDS);
if (checkIfCancelled()) {
sdkLogging.onUserCancel();
break;
}
}
} catch (InterruptedException e) {
/* valid cancellation exception, no handling needed. */
} finally {
// remove the notification listener regardless of waiting outcome.
cloudSdkService.removeStatusUpdateListener(sdkStatusUpdateListener);
// process logging and error notifications.
ApplicationManager.getApplication().invokeLater(() -> handleErrors(sdkLogging));
// run the activity after wait is over, regardless of outcome.
afterWaitComplete.run();
}
}
});
}
use of com.intellij.notification.Notifications in project google-cloud-intellij by GoogleCloudPlatform.
the class CloudDebugGlobalPollerTest method setupNotificationHandlerForVerification.
@NotNull
private Notifications setupNotificationHandlerForVerification() {
Notifications handler = mock(Notifications.class);
// sending out notificationsHandler relies on several static method calls in
// com.intellij.notification.Notifications, let's subscribe to them and do verification this way
Application application = ApplicationManager.getApplication();
getProject().getMessageBus().connect(application).subscribe(Notifications.TOPIC, handler);
return handler;
}
Aggregations