Search in sources :

Example 26 with CredentialedUser

use of com.google.cloud.tools.intellij.login.CredentialedUser in project google-cloud-intellij by GoogleCloudPlatform.

the class ProjectSelectionDialog method loadAllProjects.

@VisibleForTesting
void loadAllProjects() {
    Collection<CredentialedUser> credentialedUsers = Services.getLoginService().getAllUsers().values();
    if (credentialedUsers.isEmpty()) {
        showSignInRequest();
    } else {
        hideSignInRequest();
        cachedProjectList.clear();
        accountComboBox.removeAllItems();
        for (CredentialedUser user : credentialedUsers) {
            accountComboBox.addItem(user);
            loadProjectList(user);
        }
    }
}
Also used : CredentialedUser(com.google.cloud.tools.intellij.login.CredentialedUser) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 27 with CredentialedUser

use of com.google.cloud.tools.intellij.login.CredentialedUser in project google-cloud-intellij by GoogleCloudPlatform.

the class ProjectSelectionDialog method createUIComponents.

@VisibleForTesting
void createUIComponents() {
    addAccountButton = new JButton();
    addAccountButton.addActionListener((event) -> Services.getLoginService().logIn());
    // prepare table model and rendering.
    projectListTable = new JBTable();
    projectListTableModel = new ProjectListTableModel();
    projectListTable.setModel(projectListTableModel);
    projectListTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    projectListTable.getSelectionModel().addListSelectionListener(e -> validateProjectSelection());
    FilteredTextTableCellRenderer filterRenderer = new FilteredTextTableCellRenderer();
    projectListTable.setDefaultRenderer(Object.class, filterRenderer);
    DoubleClickListener tableDoubleClickListener = new DoubleClickListener() {

        @Override
        protected boolean onDoubleClick(MouseEvent event) {
            dialogWrapper.clickDefaultButton();
            return true;
        }
    };
    tableDoubleClickListener.installOn(projectListTable);
    // filter rows based on text field content.
    filterTextField = new JBTextField();
    TableRowSorter<TableModel> sorter = new TableRowSorter<>(projectListTableModel);
    projectListTable.setRowSorter(sorter);
    GeneralFilter filter = new GeneralFilter() {

        @Override
        protected boolean include(Entry value, int index) {
            return value.getStringValue(index).toLowerCase().contains(filterTextField.getText().toLowerCase());
        }
    };
    sorter.setRowFilter(filter);
    // on filter types, update row filter and renderer.
    filterTextField.getDocument().addDocumentListener(new DocumentAdapter() {

        @Override
        protected void textChanged(DocumentEvent e) {
            sorter.allRowsChanged();
            filterRenderer.setFilterText(filterTextField.getText());
        }
    });
    refreshAction = new RefreshAction();
    // prepare account combobox model and rendering.
    accountComboBox = new ComboBox<>();
    accountComboBox.setRenderer(new AccountComboBoxRenderer());
    accountComboBox.addActionListener((event) -> refreshProjectListUi((CredentialedUser) accountComboBox.getSelectedItem()));
    progressBar = new JBProgressBar();
    progressBar.setIndeterminate(true);
    progressBar.setVisible(false);
    // wrapper for center panel that holds either project selection or sign in screen.
    centerPanelWrapper = new JPanel(new BorderLayout());
}
Also used : JPanel(javax.swing.JPanel) MouseEvent(java.awt.event.MouseEvent) DoubleClickListener(com.intellij.ui.DoubleClickListener) GeneralFilter(org.jdesktop.swingx.sort.RowFilters.GeneralFilter) JButton(javax.swing.JButton) DocumentAdapter(com.intellij.ui.DocumentAdapter) JBProgressBar(com.intellij.ui.JBProgressBar) JBTextField(com.intellij.ui.components.JBTextField) JBTable(com.intellij.ui.table.JBTable) DocumentEvent(javax.swing.event.DocumentEvent) BorderLayout(java.awt.BorderLayout) CredentialedUser(com.google.cloud.tools.intellij.login.CredentialedUser) TableModel(javax.swing.table.TableModel) TableRowSorter(javax.swing.table.TableRowSorter) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 28 with CredentialedUser

use of com.google.cloud.tools.intellij.login.CredentialedUser in project google-cloud-intellij by GoogleCloudPlatform.

the class ProjectSelectionDialogTest method addActiveAccount_withNoProjects_clearsProjectList.

@Test
public void addActiveAccount_withNoProjects_clearsProjectList() {
    prepareOneTestUserOneTestProjectDialog(testUiProject);
    String activeUserEmail = "active-test@google.com";
    CredentialedUser mockAnotherUser = mock(CredentialedUser.class);
    when(mockAnotherUser.getEmail()).thenReturn(activeUserEmail);
    mockUserList(Arrays.asList(mockAnotherUser, /* active */
    mockTestUser));
    mockUserProjects(mockAnotherUser, Collections.emptyList());
    cleanLoadUsersAndProjects();
    assertThat(projectSelectionDialog.getAccountComboBox().getSelectedItem()).isEqualTo(mockAnotherUser);
    assertThat(projectSelectionDialog.getProjectListTableModel().getRowCount()).isEqualTo(0);
    assertThat(projectSelectionDialog.getProjectListTable().getSelectedRow()).isEqualTo(-1);
}
Also used : CredentialedUser(com.google.cloud.tools.intellij.login.CredentialedUser) Test(org.junit.Test)

Example 29 with CredentialedUser

use of com.google.cloud.tools.intellij.login.CredentialedUser in project google-cloud-intellij by GoogleCloudPlatform.

the class ProjectSelectorTest method mockUserLoggedIn.

private void mockUserLoggedIn(String username) {
    when(mockLoginService.isLoggedIn()).thenReturn(true);
    CredentialedUser mockUser = mock(CredentialedUser.class);
    when(mockLoginService.getLoggedInUser(TEST_PROJECT.googleUsername())).thenReturn(Optional.of(mockUser));
    when(mockUser.getEmail()).thenReturn(username);
}
Also used : CredentialedUser(com.google.cloud.tools.intellij.login.CredentialedUser)

Example 30 with CredentialedUser

use of com.google.cloud.tools.intellij.login.CredentialedUser in project google-cloud-intellij by GoogleCloudPlatform.

the class CloudDebugProcessStateTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    fixture = IdeaTestFixtureFactory.getFixtureFactory().createFixtureBuilder(getTestName(true)).getFixture();
    fixture.setUp();
    project = new MockProjectEx(getTestRootDisposable());
    PsiManager psiManager = Mockito.mock(PsiManager.class);
    project.registerService(PsiManager.class, psiManager);
    IntegratedGoogleLoginService mockLoginService = TestUtils.installMockService(IntegratedGoogleLoginService.class);
    GoogleLoginState googleLoginState = Mockito.mock(GoogleLoginState.class);
    CredentialedUser user = Mockito.mock(CredentialedUser.class);
    LinkedHashMap<String, CredentialedUser> allusers = new LinkedHashMap<String, CredentialedUser>();
    when(user.getEmail()).thenReturn(USER);
    when(user.getGoogleLoginState()).thenReturn(googleLoginState);
    when(googleLoginState.fetchAccessToken()).thenReturn(PASSWORD);
    when(mockLoginService.getAllUsers()).thenReturn(allusers);
    allusers.put(USER, user);
}
Also used : IntegratedGoogleLoginService(com.google.cloud.tools.intellij.login.IntegratedGoogleLoginService) GoogleLoginState(com.google.gdt.eclipse.login.common.GoogleLoginState) PsiManager(com.intellij.psi.PsiManager) CredentialedUser(com.google.cloud.tools.intellij.login.CredentialedUser) MockProjectEx(com.intellij.mock.MockProjectEx) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

CredentialedUser (com.google.cloud.tools.intellij.login.CredentialedUser)31 IOException (java.io.IOException)9 GoogleLoginState (com.google.gdt.eclipse.login.common.GoogleLoginState)6 Nullable (org.jetbrains.annotations.Nullable)6 IntegratedGoogleLoginService (com.google.cloud.tools.intellij.login.IntegratedGoogleLoginService)5 CloudProject (com.google.cloud.tools.intellij.project.CloudProject)5 LinkedHashMap (java.util.LinkedHashMap)5 Credential (com.google.api.client.auth.oauth2.Credential)4 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)4 ArrayList (java.util.ArrayList)3 GoogleNetHttpTransport (com.google.api.client.googleapis.javanet.GoogleNetHttpTransport)2 HttpHeaders (com.google.api.client.http.HttpHeaders)2 HttpRequestInitializer (com.google.api.client.http.HttpRequestInitializer)2 HttpTransport (com.google.api.client.http.HttpTransport)2 CloudResourceManager (com.google.api.services.cloudresourcemanager.CloudResourceManager)2 Iam (com.google.api.services.iam.v1.Iam)2 ServiceAccount (com.google.api.services.iam.v1.model.ServiceAccount)2 ServiceAccountKey (com.google.api.services.iam.v1.model.ServiceAccountKey)2 GoogleApiClientFactory (com.google.cloud.tools.intellij.resources.GoogleApiClientFactory)2 PluginInfoService (com.google.cloud.tools.intellij.service.PluginInfoService)2