コード例 #1
0
  @Override
  protected void buttonPressed(int buttonId) {
    /* User pressed SAVE Button */
    if (buttonId == IDialogConstants.OK_ID) {
      final String username = usernameField.getText();
      final String password = passwordField.getText();
      if (!username.equals("") && !password.equals("")) { // $NON-NLS-1$//$NON-NLS-2$
        GmailCredentials credentials = new GmailCredentials(username, password);
        try {
          if (gCredProvider != null) {
            gCredProvider.setAuthCredentials(credentials, gLink, null);
          }
        } catch (CredentialsException e) {
          Activator.getDefault().getLog().log(e.getStatus());
        }
        GmailAuthenticationAction gAuthAction = new GmailAuthenticationAction();
        gAuthAction.addGmailFolder();
      } else {
        MessageDialog.openError(
            this.getParentShell(),
            "You must enter valid credentials",
            "Empty strings are not allowed"); //$NON-NLS-1$ //$NON-NLS-2$
      }
    }

    super.buttonPressed(buttonId);
  }
コード例 #2
0
  private void preload() {
    ICredentials authCredentials = null;
    try {
      if (gCredProvider != null) authCredentials = gCredProvider.getAuthCredentials(gLink, null);
    } catch (CredentialsException e) {
      Activator.getDefault().getLog().log(e.getStatus());
    }

    if (authCredentials != null) {
      String username = authCredentials.getUsername();
      String password = authCredentials.getPassword();

      if (StringUtils.isSet(username)) {
        usernameField.setText(username);
        usernameField.selectAll();
      }

      if (StringUtils.isSet(password)) passwordField.setText(password);
    }
  }