Exemplo n.º 1
0
  /** Adds listeners to the UI components. */
  private void initListeners() {
    user.getDocument().addDocumentListener(this);
    pass.getDocument().addDocumentListener(this);
    login.addActionListener(this);
    user.addActionListener(this);
    pass.addActionListener(this);
    cancel.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            quit();
          }
        });
    configButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            config();
          }
        });
    encryptionListener =
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            encrypt();
          }
        };
    encryptedButton.addActionListener(encryptionListener);
    addWindowListener(
        new WindowAdapter() {
          public void windowOpened(WindowEvent e) {
            requestFocusOnField();
          }
        });
    user.addMouseListener(
        new MouseAdapter() {

          /**
           * Fires a property to move the window to the front.
           *
           * @see MouseListener#mouseClicked(MouseEvent)
           */
          public void mouseClicked(MouseEvent e) {
            firePropertyChange(TO_FRONT_PROPERTY, Boolean.valueOf(false), Boolean.valueOf(true));
            user.requestFocus();
            // if (user.getText() != null)
            //	user.selectAll();
          }
        });
    pass.addMouseListener(
        new MouseAdapter() {

          /**
           * Fires a property to move the window to the front.
           *
           * @see MouseListener#mouseClicked(MouseEvent)
           */
          public void mouseClicked(MouseEvent e) {
            firePropertyChange(TO_FRONT_PROPERTY, Boolean.valueOf(false), Boolean.valueOf(true));
            // requestFocusOnField();
          }
        });
  }
  private JPasswordField getConfirmPasswordField() {
    if (confirmPasswordField == null) {
      confirmPasswordField = new JPasswordField();
      confirmPasswordField
          .getDocument()
          .addDocumentListener(
              new DocumentListener() {

                @Override
                public void removeUpdate(DocumentEvent e) {
                  refreshState();
                }

                @Override
                public void insertUpdate(DocumentEvent e) {
                  refreshState();
                }

                @Override
                public void changedUpdate(DocumentEvent e) {
                  refreshState();
                }
              });
    }
    return confirmPasswordField;
  }
Exemplo n.º 3
0
  /**
   * @param constraints
   * @param columns
   * @param rows
   */
  public ExtPasswordField() {
    super("ins 0", "[grow,fill]", "[grow,fill]");
    renderer = new ExtTextField();
    editor = new JPasswordField();

    renderer.addFocusListener(this);
    editor.addFocusListener(this);
    this.add(renderer, "hidemode 3");
    this.add(editor, "hidemode 3");
    editor.setText("");
    // this.renderer.setBackground(Color.RED);
    renderer.setText("");
    editor.getDocument().addDocumentListener(this);
    renderer.setHelpText("");
    setRendererMode(true);
  }
  public void addActionListener(final ActionListener actionListener) {
    myProxyLoginTextField.addActionListener(actionListener);
    DocumentListener docListener =
        new DocumentListener() {
          public void insertUpdate(DocumentEvent e) {
            actionListener.actionPerformed(null);
          }

          public void removeUpdate(DocumentEvent e) {
            actionListener.actionPerformed(null);
          }

          public void changedUpdate(DocumentEvent e) {
            actionListener.actionPerformed(null);
          }
        };
    myProxyPasswordTextField.getDocument().addDocumentListener(docListener);
    myProxyAuthCheckBox.addActionListener(actionListener);
    myProxyPortTextField.getDocument().addDocumentListener(docListener);
    myProxyHostTextField.getDocument().addDocumentListener(docListener);
    myUseHTTPProxyRb.addActionListener(actionListener);
    myRememberProxyPasswordCheckBox.addActionListener(actionListener);
  }
 public GithubLoginPanel(final GithubLoginDialog dialog) {
   DocumentListener listener =
       new DocumentAdapter() {
         @Override
         protected void textChanged(DocumentEvent e) {
           dialog.clearErrors();
         }
       };
   myLoginTextField.getDocument().addDocumentListener(listener);
   myPasswordField.getDocument().addDocumentListener(listener);
   mySignupTextField.setText(
       "<html>Do not have an account at github.com? <a href=\"https://github.com\">Sign up</a>.</html>");
   mySignupTextField.setMargin(new Insets(5, 0, 0, 0));
   mySignupTextField.addHyperlinkListener(
       new HyperlinkAdapter() {
         @Override
         protected void hyperlinkActivated(final HyperlinkEvent e) {
           BrowserUtil.browse(e.getURL());
         }
       });
   mySignupTextField.setBackground(UIUtil.TRANSPARENT_COLOR);
   mySignupTextField.setCursor(new Cursor(Cursor.HAND_CURSOR));
 }
Exemplo n.º 6
0
  /** Initializes the components composing this display. */
  private void initComponents() {
    admin = false;
    active = false;
    groupOwner = false;

    userPicture = new UserProfileCanvas();
    userPicture.setBackground(UIUtilities.BACKGROUND_COLOR);
    userPicture.setToolTipText("Click to upload your picture.");
    IconManager icons = IconManager.getInstance();
    userPicture.setImage(icons.getImageIcon(IconManager.USER_PHOTO_32).getImage());
    loginArea = new JTextField();
    boolean a = MetadataViewerAgent.isAdministrator();
    loginArea.setEnabled(a);
    loginArea.setEditable(a);
    adminBox = new JCheckBox();
    adminBox.setVisible(false);
    adminBox.setBackground(UIUtilities.BACKGROUND_COLOR);
    ownerBox = new JCheckBox();
    ownerBox.setBackground(UIUtilities.BACKGROUND_COLOR);
    activeBox = new JCheckBox();
    activeBox.setBackground(UIUtilities.BACKGROUND_COLOR);
    activeBox.setVisible(false);
    passwordButton = new JButton("Change password");
    passwordButton.setEnabled(false);
    passwordButton.setBackground(UIUtilities.BACKGROUND_COLOR);
    passwordButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            changePassword();
          }
        });
    manageButton = new JButton("Group");
    manageButton.setEnabled(false);
    manageButton.setBackground(UIUtilities.BACKGROUND_COLOR);
    manageButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            manageGroup();
          }
        });
    passwordNew = new JPasswordField();
    passwordNew.setBackground(UIUtilities.BACKGROUND_COLOR);
    passwordConfirm = new JPasswordField();
    passwordConfirm.setBackground(UIUtilities.BACKGROUND_COLOR);
    oldPassword = new JPasswordField();
    oldPassword.setBackground(UIUtilities.BACKGROUND_COLOR);
    items = new HashMap<String, JTextField>();
    ExperimenterData user = (ExperimenterData) model.getRefObject();
    GroupData defaultGroup = user.getDefaultGroup();

    permissionsPane =
        new PermissionsPane(defaultGroup.getPermissions(), UIUtilities.BACKGROUND_COLOR);
    permissionsPane.disablePermissions();
    groupLabel = new JLabel(defaultGroup.getName());
    groupLabel.setBackground(UIUtilities.BACKGROUND_COLOR);

    long groupID = defaultGroup.getId();
    boolean owner = false;
    /*
    if (defaultGroup.getLeaders() != null)
    	owner = setGroupOwner(defaultGroup);
    else {
    	GroupData g = model.loadGroup(groupID);
    	if (g != null)
    		owner = setGroupOwner(g);
    }
    */
    Object parentRootObject = model.getParentRootObject();
    if (parentRootObject instanceof GroupData) {
      owner = setGroupOwner((GroupData) parentRootObject);
    }
    // Build the array for box.
    /*
    Iterator i = userGroups.iterator();
    GroupData g;

    List<GroupData> validGroups = new ArrayList<GroupData>();
    while (i.hasNext()) {
    	g = (GroupData) i.next();
    	if (model.isValidGroup(g))
    		validGroups.add(g);
    }
    groupData = new GroupData[validGroups.size()];
    admin = false;
    active = false;
    int selectedIndex = 0;
    int index = 0;
    i = validGroups.iterator();
    boolean owner = false;
    while (i.hasNext()) {
    	g = (GroupData) i.next();
    	groupData[index] = g;
    	if (g.getId() == groupID) {
    		if (g.getLeaders() != null) {
    			owner = setGroupOwner(g);
    			originalIndex = index;
    		}
    	}
    	index++;
    }
    selectedIndex = originalIndex;
    groups = EditorUtil.createComboBox(groupData, 0);
    groups.setEnabled(false);
    groups.setRenderer(new GroupsRenderer());
    if (groupData.length != 0)
    	groups.setSelectedIndex(selectedIndex);
    */

    if (MetadataViewerAgent.isAdministrator()) {
      // Check that the user is not the one currently logged.
      oldPassword.setVisible(false);
      owner = true;
      adminBox.setVisible(true);
      activeBox.setVisible(true);
      adminBox.addChangeListener(this);
      active = user.isActive();
      activeBox.setSelected(active);
      activeBox.setEnabled(!model.isSelf());
      activeBox.addChangeListener(this);
      // indicate if the user is an administrator.a
      admin = isUserAdministrator();
      adminBox.setSelected(admin);
      ownerBox.addChangeListener(this);
      // admin = false;
      // Now check if the user is the last administrator
    } else {
      ownerBox.setEnabled(false);
      passwordConfirm
          .getDocument()
          .addDocumentListener(
              new DocumentListener() {

                /**
                 * Allows the user to interact with the password controls depending on the value
                 * entered.
                 *
                 * @see DocumentListener#removeUpdate(DocumentEvent)
                 */
                public void removeUpdate(DocumentEvent e) {
                  handlePasswordEntered();
                }

                /**
                 * Allows the user to interact with the password controls depending on the value
                 * entered.
                 *
                 * @see DocumentListener#insertUpdate(DocumentEvent)
                 */
                public void insertUpdate(DocumentEvent e) {
                  handlePasswordEntered();
                }

                /**
                 * Required by the {@link DocumentListener} I/F but no-operation implementation in
                 * our case.
                 *
                 * @see DocumentListener#changedUpdate(DocumentEvent)
                 */
                public void changedUpdate(DocumentEvent e) {}
              });
    }
    passwordNew
        .getDocument()
        .addDocumentListener(
            new DocumentListener() {

              /**
               * Allows the user to interact with the password controls depending on the value
               * entered.
               *
               * @see DocumentListener#removeUpdate(DocumentEvent)
               */
              public void removeUpdate(DocumentEvent e) {
                handlePasswordEntered();
              }

              /**
               * Allows the user to interact with the password controls depending on the value
               * entered.
               *
               * @see DocumentListener#insertUpdate(DocumentEvent)
               */
              public void insertUpdate(DocumentEvent e) {
                handlePasswordEntered();
              }

              /**
               * Required by the {@link DocumentListener} I/F but no-operation implementation in our
               * case.
               *
               * @see DocumentListener#changedUpdate(DocumentEvent)
               */
              public void changedUpdate(DocumentEvent e) {}
            });
    ExperimenterData logUser = MetadataViewerAgent.getUserDetails();
    if (user.getId() == logUser.getId()) {
      userPicture.addMouseListener(
          new MouseAdapter() {

            /** Brings up a chooser to load the user image. */
            public void mouseReleased(MouseEvent e) {
              uploadPicture();
            }
          });
    }
  }
Exemplo n.º 7
0
 public javax.swing.text.Document getDocument() {
   return editor.getDocument();
 }
  public ConfigurationPanel(final Project project) {

    serverUrl.setName("serverUrl");
    buildDelay.setName("buildDelay");
    jobRefreshPeriod.setName("jobRefreshPeriod");
    rssRefreshPeriod.setName("rssRefreshPeriod");
    username.setName("_username_");

    passwordField.setName("passwordFile");
    crumbDataField.setName("crumbDataFile");

    testConnexionButton.setName("testConnexionButton");
    connectionStatusLabel.setName("connectionStatusLabel");

    successOrStableCheckBox.setName("successOrStableCheckBox");
    unstableOrFailCheckBox.setName("unstableOrFailCheckBox");
    abortedCheckBox.setName("abortedCheckBox");

    rssStatusFilterPanel.setBorder(IdeBorderFactory.createTitledBorder("Event Log Settings", true));

    debugPanel.setVisible(false);

    initDebugTextPane();

    buildDelay.setDocument(new NumberDocument());
    jobRefreshPeriod.setDocument(new NumberDocument());
    rssRefreshPeriod.setDocument(new NumberDocument());

    uploadPatchSettingsPanel.setBorder(
        IdeBorderFactory.createTitledBorder("Upload a Patch Settings", true));

    passwordField
        .getDocument()
        .addDocumentListener(
            new DocumentListener() {
              @Override
              public void insertUpdate(DocumentEvent e) {
                myPasswordModified = true;
              }

              @Override
              public void removeUpdate(DocumentEvent e) {
                myPasswordModified = true;
              }

              @Override
              public void changedUpdate(DocumentEvent e) {
                myPasswordModified = true;
              }
            });

    testConnexionButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            try {
              debugPanel.setVisible(false);

              new NotNullValidator().validate(serverUrl);
              new UrlValidator().validate(serverUrl);

              JenkinsSettings jenkinsSettings = JenkinsSettings.getSafeInstance(project);

              String password =
                  isPasswordModified() ? getPassword() : jenkinsSettings.getPassword();

              RequestManager.getInstance(project)
                  .authenticate(
                      serverUrl.getText(), username.getText(), password, crumbDataField.getText());
              setConnectionFeedbackLabel(CONNECTION_TEST_SUCCESSFUL_COLOR, "Successful");
              setPassword(password);
            } catch (Exception ex) {
              setConnectionFeedbackLabel(CONNECTION_TEST_FAILED_COLOR, "[Fail] " + ex.getMessage());
              if (ex instanceof AuthenticationException) {
                AuthenticationException authenticationException = (AuthenticationException) ex;
                String responseBody = authenticationException.getResponseBody();
                if (StringUtils.isNotBlank(responseBody)) {
                  debugPanel.setVisible(true);
                  debugTextPane.setText(responseBody);
                }
              }
            }
          }
        });

    formValidator =
        FormValidator.init(this)
            .addValidator(
                username,
                new UIValidator<JTextField>() {
                  public void validate(JTextField component) throws ConfigurationException {
                    if (StringUtils.isNotBlank(component.getText())) {
                      String password = getPassword();
                      if (StringUtils.isBlank(password)) {
                        throw new ConfigurationException(
                            String.format("'%s' must be set", passwordField.getName()));
                      }
                    }
                  }
                });
  }