Exemple #1
0
  private boolean validateAdminParams() {

    if (addressAdminField.getText().isEmpty()) {
      MedSavantFrame.getInstance().notificationMessage("Server address required");
      addressAdminField.requestFocus();
      return false;
    }

    if (portAdminField.getText().isEmpty()) {
      MedSavantFrame.getInstance().notificationMessage("Server port required");
      portAdminField.requestFocus();
      return false;
    }

    try {
      Integer.parseInt(portAdminField.getText());
    } catch (Exception e) {
      MedSavantFrame.getInstance().notificationMessage("Invalid port number");
      portAdminField.requestFocus();
      return false;
    }

    if (dbnameAdminField.getText().isEmpty()) {
      MedSavantFrame.getInstance().notificationMessage("Database name required");
      dbnameAdminField.requestFocus();
      return false;
    }

    if (userAdminField.getText().isEmpty()) {
      MedSavantFrame.getInstance().notificationMessage("Username required");
      userAdminField.requestFocus();
      return false;
    }

    if (passwordAdminField.getText().isEmpty()) {
      MedSavantFrame.getInstance().notificationMessage("Password required");
      passwordAdminField.requestFocus();
      return false;
    }

    return true;
  }
Exemple #2
0
  private JPanel getAdminPanel() {
    MigLayout ml = new MigLayout();
    final JPanel p = new JPanel(ml);
    p.setBackground(Color.white);

    SettingsController sc = SettingsController.getInstance();

    addressAdminField = new PlaceHolderTextField();
    addressAdminField.setPlaceholder("server address");
    addressAdminField.setText(sc.getServerAddress());
    addressAdminField.setColumns(textFieldAdminColumns);
    portAdminField = new PlaceHolderTextField();
    portAdminField.setPlaceholder("server port number");
    portAdminField.setText(sc.getServerPort());
    portAdminField.setColumns(textFieldAdminColumns);
    dbnameAdminField = new PlaceHolderTextField();
    dbnameAdminField.setPlaceholder("database");
    dbnameAdminField.setColumns(textFieldAdminColumns);
    userAdminField = new PlaceHolderTextField();
    userAdminField.setPlaceholder("admin username");
    userAdminField.setColumns(textFieldAdminColumns);
    passwordAdminField = new PlaceHolderPasswordField();
    passwordAdminField.setPlaceholder("password");
    passwordAdminField.setColumns(textFieldAdminColumns);

    JButton addDB = new JButton("Create");
    JButton removeDB = new JButton("Delete");

    JLabel adminOnly = new JLabel("Administrators only");
    adminOnly.setForeground(Color.red);
    p.add(ViewUtil.makeSmall(adminOnly), "wrap");
    p.add(addressAdminField, "wrap");
    p.add(portAdminField, "wrap");
    p.add(dbnameAdminField, "wrap");
    p.add(userAdminField, "wrap");
    p.add(passwordAdminField, "wrap");
    p.add(addDB, "split 2");
    p.add(removeDB, "wrap");

    addDB.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent ae) {
            if (validateAdminParams()) {
              closeDialogContainingPanel(p);
              int port = Integer.parseInt(portAdminField.getText());
              createDatabase(
                  addressAdminField.getText(),
                  port,
                  dbnameAdminField.getText(),
                  userAdminField.getText(),
                  passwordAdminField.getPassword());
            }
          }
        });

    removeDB.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent ae) {
            if (validateAdminParams()) {
              closeDialogContainingPanel(p);
              int port = Integer.parseInt(portAdminField.getText());
              removeDatabase(
                  addressAdminField.getText(),
                  port,
                  dbnameAdminField.getText(),
                  userAdminField.getText(),
                  passwordAdminField.getPassword());
            }
          }
        });

    return p;
  }