/**
  * Listener method.
  *
  * @param event The property change event.
  */
 @Override
 public void propertyChange(PropertyChangeEvent event) {
   if (CreateDatabaseWorker.COMPLETE.equals(event.getPropertyName())) {
     CreateDatabaseWorker worker = (CreateDatabaseWorker) event.getSource();
     try {
       Boolean databasesCreated = worker.get();
       if (databasesCreated) {
         JOptionPane.showMessageDialog(
             CreateDatabaseDialog.this,
             Messages.getMessage("database.created.message"),
             Messages.getMessage("database.created.title"),
             JOptionPane.INFORMATION_MESSAGE);
       } else {
         showExceptionDialog(
             worker.getCreationException(),
             "database.create.fail.title",
             "database.create.fail.message");
       }
     } catch (CancellationException e) {
       // Do nothing - the user knows they cancelled it.
     } catch (ExecutionException e) {
       logger.warn("ExecutionException getting result from create database worker:", e);
     } catch (InterruptedException e) {
       // Just leave.
     }
   }
 }
  /**
   * Helper to <code>init</code>, this adds JLabels for each of the five database fields in each
   * block.
   *
   * @param cons The GridBagConstraints to work from.
   */
  private void addDatabaseLabels(GridBagConstraints cons) {
    Container cp = getContentPane();

    cons.gridwidth = 1;
    cons.weightx = 0;

    cons.gridy++;
    cp.add(new JLabel(Messages.getMessage("database.server")), cons);

    cons.gridy++;
    cp.add(new JLabel(Messages.getMessage("database.name")), cons);

    cons.gridy++;
    cp.add(new JLabel(Messages.getMessage("database.username")), cons);

    cons.gridy++;
    cp.add(new JLabel(Messages.getMessage("database.password")), cons);

    cons.gridy++;
    cp.add(new JLabel(Messages.getMessage("database.encoding")), cons);
  }
    /**
     * Called to check if the databases can be accessed, and if so, move on to the mine properties
     * dialog.
     *
     * @param event The action event.
     */
    @Override
    public void actionPerformed(ActionEvent event) {
      Cursor current = getCursor();
      setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

      try {
        String[] servers = {
          productionServerField.getText(), itemsServerField.getText(), profileServerField.getText()
        };
        String[] dbNames = {
          productionNameField.getText(), itemsNameField.getText(), profileNameField.getText()
        };
        String[] userNames = {
          productionUserNameField.getText(),
          itemsUserNameField.getText(),
          profileUserNameField.getText()
        };
        String[] passwords = {
          productionPasswordField.getText(),
          itemsPasswordField.getText(),
          profilePasswordField.getText()
        };

        Object[] missingDbs = new String[dbNames.length];
        int missingCount = 0;
        try {
          for (int i = 0; i < 3; i++) {
            boolean ok =
                DatabaseUtil.checkDatabaseExists(
                    servers[i], dbNames[i], userNames[i], passwords[i]);
            if (!ok) {
              missingDbs[missingCount++] = dbNames[i];
            }
          }

          if (missingCount == 0) {
            setProperties(previousProperties);
            createPropertiesDialog.open(previousProperties, getLocation());
            setVisible(false);
            createPropertiesDialog.setVisible(true);

          } else {
            String key = "database.missing." + missingCount;
            StringBuilder message = new StringBuilder();
            message.append("<html>");
            message.append(Messages.getMessage(key, missingDbs));
            message.append("<br/>");
            message.append(Messages.getMessage("database.missing.summary"));
            message.append("</html>");

            JOptionPane.showMessageDialog(
                CreateDatabaseDialog.this,
                message,
                Messages.getMessage("database.missing.title"),
                JOptionPane.ERROR_MESSAGE);
          }
        } catch (DatabaseConnectionException e) {
          showExceptionDialog(e, "database.test.fail.title", "database.test.fail.message");
        }
      } finally {
        setCursor(current);
      }
    }
 /** Constructor. */
 public NextAction() {
   super(Messages.getMessage("next"));
 }
 /** Constructor. */
 public CreateDatabaseAction() {
   super(Messages.getMessage("createdatabase"));
 }
  /**
   * Common initialisation: lays out the child components and wires up the necessary event
   * listeners.
   */
  private void init() {
    setName("Create Database Dialog");
    setTitle(Messages.getMessage("createdatabase.title"));
    setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);

    final String acceptableCharacters = RestrictedInputDocument.WORD_CHARACTERS + "-";
    String[] encodingOptions = {"SQL_ASCII", "UTF8"};

    productionServerField =
        new JTextField(new RestrictedInputDocument(acceptableCharacters), "", 20);
    productionNameField = new JTextField(new RestrictedInputDocument(acceptableCharacters), "", 20);
    productionUserNameField =
        new JTextField(new RestrictedInputDocument(acceptableCharacters), "", 20);
    productionPasswordField = new JTextField(20);
    productionEncodingCombo = new JComboBox(encodingOptions);

    itemsServerField = new JTextField(new RestrictedInputDocument(acceptableCharacters), "", 20);
    itemsNameField = new JTextField(new RestrictedInputDocument(acceptableCharacters), "", 20);
    itemsUserNameField = new JTextField(new RestrictedInputDocument(acceptableCharacters), "", 20);
    itemsPasswordField = new JTextField(20);
    itemsEncodingCombo = new JComboBox(encodingOptions);

    profileServerField = new JTextField(new RestrictedInputDocument(acceptableCharacters), "", 20);
    profileNameField = new JTextField(new RestrictedInputDocument(acceptableCharacters), "", 20);
    profileUserNameField =
        new JTextField(new RestrictedInputDocument(acceptableCharacters), "", 20);
    profilePasswordField = new JTextField(20);
    profileEncodingCombo = new JComboBox(encodingOptions);

    Container cp = getContentPane();
    GridBagConstraints cons = GridBagHelper.setup(cp);

    cons.gridwidth = GridBagConstraints.REMAINDER;
    cons.weightx = 1;
    cp.add(new JLabel(Messages.getMessage("createdatabase.header")), cons);

    cons.gridy++;
    cp.add(new JLabel(Messages.getMessage("database.production")), cons);

    addDatabaseLabels(cons);

    cons.gridy++;
    cons.gridwidth = GridBagConstraints.REMAINDER;
    cons.weightx = 1;
    cp.add(new JLabel(Messages.getMessage("database.commontargetitems")), cons);

    addDatabaseLabels(cons);

    cons.gridy++;
    cons.gridwidth = GridBagConstraints.REMAINDER;
    cons.weightx = 1;
    cp.add(new JLabel(Messages.getMessage("database.userprofile")), cons);

    addDatabaseLabels(cons);

    cons.gridx++;
    cons.gridy = 2;
    cons.weightx = 1;
    cp.add(productionServerField, cons);

    cons.gridy++;
    cp.add(productionNameField, cons);

    cons.gridy++;
    cp.add(productionUserNameField, cons);

    cons.gridy++;
    cp.add(productionPasswordField, cons);

    cons.gridy++;
    cp.add(productionEncodingCombo, cons);

    cons.gridy += 2;
    cp.add(itemsServerField, cons);

    cons.gridy++;
    cp.add(itemsNameField, cons);

    cons.gridy++;
    cp.add(itemsUserNameField, cons);

    cons.gridy++;
    cp.add(itemsPasswordField, cons);

    cons.gridy++;
    cp.add(itemsEncodingCombo, cons);

    cons.gridy += 2;
    cp.add(profileServerField, cons);

    cons.gridy++;
    cp.add(profileNameField, cons);

    cons.gridy++;
    cp.add(profileUserNameField, cons);

    cons.gridy++;
    cp.add(profilePasswordField, cons);

    cons.gridy++;
    cp.add(profileEncodingCombo, cons);

    cons.gridy++;
    cons.gridx = 0;
    cons.gridwidth = GridBagConstraints.REMAINDER;
    cons.weightx = 1.0;
    cp.add(
        new ButtonPanel(getRootPane(), 1, createDatabaseAction, nextAction, new CancelAction()),
        cons);

    DocumentListener fieldListener = new FieldListener();
    productionServerField.getDocument().addDocumentListener(fieldListener);
    productionNameField.getDocument().addDocumentListener(fieldListener);
    productionUserNameField.getDocument().addDocumentListener(fieldListener);
    productionPasswordField.getDocument().addDocumentListener(fieldListener);
    itemsServerField.getDocument().addDocumentListener(fieldListener);
    itemsNameField.getDocument().addDocumentListener(fieldListener);
    itemsUserNameField.getDocument().addDocumentListener(fieldListener);
    itemsPasswordField.getDocument().addDocumentListener(fieldListener);
    profileServerField.getDocument().addDocumentListener(fieldListener);
    profileNameField.getDocument().addDocumentListener(fieldListener);
    profileUserNameField.getDocument().addDocumentListener(fieldListener);
    profilePasswordField.getDocument().addDocumentListener(fieldListener);

    pack();
  }