Search in sources :

Example 1 with Notifications

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();
            }
        }
    });
}
Also used : ShowSettingsUtil(com.intellij.openapi.options.ShowSettingsUtil) Task(com.intellij.openapi.progress.Task) StatusBar(com.intellij.openapi.wm.StatusBar) PropertiesFileFlagReader(com.google.cloud.tools.intellij.flags.PropertiesFileFlagReader) Map(java.util.Map) Project(com.intellij.openapi.project.Project) GctBundle(com.google.cloud.tools.intellij.util.GctBundle) Notifications(com.intellij.notification.Notifications) ProgressManager(com.intellij.openapi.progress.ProgressManager) StatusBarEx(com.intellij.openapi.wm.ex.StatusBarEx) WindowManager(com.intellij.openapi.wm.WindowManager) AnAction(com.intellij.openapi.actionSystem.AnAction) Maps(com.google.common.collect.Maps) NotificationType(com.intellij.notification.NotificationType) Notification(com.intellij.notification.Notification) CountDownLatch(java.util.concurrent.CountDownLatch) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ServiceManager(com.intellij.openapi.components.ServiceManager) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) ApplicationManager(com.intellij.openapi.application.ApplicationManager) SdkStatus(com.google.cloud.tools.intellij.appengine.sdk.CloudSdkService.SdkStatus) VisibleForTesting(com.google.common.annotations.VisibleForTesting) NotNull(org.jetbrains.annotations.NotNull) SECONDS(java.util.concurrent.TimeUnit.SECONDS) Task(com.intellij.openapi.progress.Task) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 2 with Notifications

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;
}
Also used : Notifications(com.intellij.notification.Notifications) Application(com.intellij.openapi.application.Application) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

Notifications (com.intellij.notification.Notifications)2 NotNull (org.jetbrains.annotations.NotNull)2 SdkStatus (com.google.cloud.tools.intellij.appengine.sdk.CloudSdkService.SdkStatus)1 PropertiesFileFlagReader (com.google.cloud.tools.intellij.flags.PropertiesFileFlagReader)1 GctBundle (com.google.cloud.tools.intellij.util.GctBundle)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Maps (com.google.common.collect.Maps)1 Notification (com.intellij.notification.Notification)1 NotificationType (com.intellij.notification.NotificationType)1 AnAction (com.intellij.openapi.actionSystem.AnAction)1 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)1 Application (com.intellij.openapi.application.Application)1 ApplicationManager (com.intellij.openapi.application.ApplicationManager)1 ServiceManager (com.intellij.openapi.components.ServiceManager)1 ShowSettingsUtil (com.intellij.openapi.options.ShowSettingsUtil)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 ProgressManager (com.intellij.openapi.progress.ProgressManager)1 Task (com.intellij.openapi.progress.Task)1 Project (com.intellij.openapi.project.Project)1 StatusBar (com.intellij.openapi.wm.StatusBar)1