/** * Loads active {@link CloudProject}, if IDE {@link Project} has been specified. This should be * called when project selector and the related UI are completely initialized. Calls listeners to * notify on new project selection. */ public void loadActiveCloudProject() { Optional<CloudProject> projectOptional = Optional.ofNullable(ideProject) .map(p -> ActiveCloudProjectManager.getInstance().getActiveCloudProject(p)); projectOptional.ifPresent( activeCloudProject -> { // do not preset and notify on active project if not signed in to avoid misleading client // code to assume project selection is made with an active account. if (Services.getLoginService().isLoggedIn()) { setSelectedProject(activeCloudProject); notifyProjectSelectionListeners(); } }); }
@VisibleForTesting void handleOpenProjectSelectionDialog() { ProjectSelectionDialog projectSelectionDialog = createProjectSelectionDialog(this); CloudProject newSelection = projectSelectionDialog.showDialog(cloudProject); // if null, it means no change or user cancelled selection dialog - no update required. if (newSelection != null) { setSelectedProject(newSelection); notifyProjectSelectionListeners(); // keep as last active project if IDE project has been specified. if (ideProject != null) { ActiveCloudProjectManager.getInstance().setActiveCloudProject(newSelection, ideProject); } } }
/** @param ideProject IDE {@link Project} to be used to update active cloud project settings. */ public ProjectSelector(@Nullable Project ideProject) { this.ideProject = ideProject; // listen to login changes to show sign in prompt when no one is signed in. googleLoginListener = () -> { if (cloudProject != null) { ApplicationManager.getApplication() .invokeLater( () -> { updateCloudProjectSelection(cloudProject); notifyProjectSelectionListeners(); }); } }; messageBusConnection = ApplicationManager.getApplication().getMessageBus().connect(); messageBusConnection.subscribe( GoogleLoginListener.GOOGLE_LOGIN_LISTENER_TOPIC, googleLoginListener); }