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);
}
}
}
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());
}
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);
}
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);
}
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);
}
Aggregations