Search in sources :

Example 1 with ResourceErrorModelItem

use of com.google.cloud.tools.intellij.resources.ResourceErrorModelItem in project google-cloud-intellij by GoogleCloudPlatform.

the class ProjectRepositoriesModelItem method loadRepositories.

@SuppressWarnings("FutureReturnValueIgnored")
public void loadRepositories(@NotNull String cloudProject, @NotNull CredentialedUser user, @Nullable Runnable onComplete) {
    setUserObject(cloudProject);
    cloudRepositoryService.listAsync(user, cloudProject).thenAccept(response -> {
        removeAllChildren();
        List<Repo> repositories = response.getRepos();
        if (!response.isEmpty() && repositories != null) {
            repositories.forEach(repo -> {
                Object name = repo.get("name");
                if (name != null) {
                    add(new RepositoryModelItem(name.toString()));
                }
            });
        } else {
            add(new ResourceEmptyModelItem(GctBundle.message("cloud.repository.list.empty")));
        }
        if (onComplete != null) {
            onComplete.run();
        }
    }).exceptionally(response -> {
        removeAllChildren();
        add(new ResourceErrorModelItem(GctBundle.message("cloud.repository.list.error")));
        if (onComplete != null) {
            onComplete.run();
        }
        return null;
    });
}
Also used : Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) ServiceManager(com.intellij.openapi.components.ServiceManager) ResourceErrorModelItem(com.google.cloud.tools.intellij.resources.ResourceErrorModelItem) CredentialedUser(com.google.cloud.tools.intellij.login.CredentialedUser) Repo(com.google.api.services.source.model.Repo) GctBundle(com.google.cloud.tools.intellij.util.GctBundle) ResourceEmptyModelItem(com.google.cloud.tools.intellij.resources.ResourceEmptyModelItem) NotNull(org.jetbrains.annotations.NotNull) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) List(java.util.List) ResourceEmptyModelItem(com.google.cloud.tools.intellij.resources.ResourceEmptyModelItem) ResourceErrorModelItem(com.google.cloud.tools.intellij.resources.ResourceErrorModelItem)

Aggregations

Repo (com.google.api.services.source.model.Repo)1 CredentialedUser (com.google.cloud.tools.intellij.login.CredentialedUser)1 ResourceEmptyModelItem (com.google.cloud.tools.intellij.resources.ResourceEmptyModelItem)1 ResourceErrorModelItem (com.google.cloud.tools.intellij.resources.ResourceErrorModelItem)1 GctBundle (com.google.cloud.tools.intellij.util.GctBundle)1 ServiceManager (com.intellij.openapi.components.ServiceManager)1 List (java.util.List)1 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1