/**
   * Sets the person to be edited in the dialog.
   *
   * @param person
   */
  public void setPerson(Person person) {
    this.person = person;

    firstNameField.setText(person.getFirstName());
    lastNameField.setText(person.getLastName());
    streetField.setText(person.getStreet());
    postalCodeField.setText(Integer.toString(person.getPostalCode()));
    cityField.setText(person.getCity());
    birthdayField.setText(DateUtil.format(person.getBirthday()));
    birthdayField.setPromptText("dd.mm.yyyy");
  }
  /**
   * Validates the user input in the text fields.
   *
   * @return true if the input is valid
   */
  private boolean isInputValid() {
    String errorMessage = "";

    if (firstNameField.getText() == null || firstNameField.getText().length() == 0) {
      errorMessage += "No valid first name!\n";
    }
    if (lastNameField.getText() == null || lastNameField.getText().length() == 0) {
      errorMessage += "No valid last name!\n";
    }
    if (streetField.getText() == null || streetField.getText().length() == 0) {
      errorMessage += "No valid street!\n";
    }

    if (postalCodeField.getText() == null || postalCodeField.getText().length() == 0) {
      errorMessage += "No valid postal code!\n";
    } else {
      // try to parse the postal code into an int.
      try {
        Integer.parseInt(postalCodeField.getText());
      } catch (NumberFormatException e) {
        errorMessage += "No valid postal code (must be an integer)!\n";
      }
    }

    if (cityField.getText() == null || cityField.getText().length() == 0) {
      errorMessage += "No valid city!\n";
    }

    if (birthdayField.getText() == null || birthdayField.getText().length() == 0) {
      errorMessage += "No valid birthday!\n";
    } else {
      if (!DateUtil.validDate(birthdayField.getText())) {
        errorMessage += "No valid birthday. Use the format dd.mm.yyyy!\n";
      }
    }

    if (errorMessage.length() == 0) {
      return true;
    } else {
      // Show the error message.
      Alert alert = new Alert(AlertType.ERROR);
      alert.initOwner(dialogStage);
      alert.setTitle("Invalid Fields");
      alert.setHeaderText("Please correct invalid fields");
      alert.setContentText(errorMessage);

      alert.showAndWait();

      return false;
    }
  }
  /** Called when the user clicks ok. */
  @FXML
  private void handleOk() {
    if (isInputValid()) {
      person.setFirstName(firstNameField.getText());
      person.setLastName(lastNameField.getText());
      person.setStreet(streetField.getText());
      person.setPostalCode(Integer.parseInt(postalCodeField.getText()));
      person.setCity(cityField.getText());
      person.setBirthday(DateUtil.parse(birthdayField.getText()));

      okClicked = true;
      dialogStage.close();
    }
  }
 /**
  * Método llamado cada vez que se selecciona un objeto de la tabla. Actualiza el form de
  * PersonOverview
  *
  * @param person el objeto de la lista seleccionado en la tabla
  */
 public void showPersonDetails(Person person) {
   if (person != null) {
     firstNameLabel.setText(person.getFirstName());
     lastNameLabel.setText(person.getLastName());
     streetLabel.setText(person.getStreet());
     postalCodeLabel.setText(String.valueOf(person.getPostalCode()));
     cityLabel.setText(person.getCity());
     birthdayLabel.setText(DateUtil.format(person.getBirthday()));
   } else {
     // Person is null, remove all the text.
     firstNameLabel.setText("");
     lastNameLabel.setText("");
     streetLabel.setText("");
     postalCodeLabel.setText("");
     cityLabel.setText("");
     birthdayLabel.setText("");
   }
 }
  /**
   * Fills all text fields to show details about the person. If the specified person is null, all
   * text fields are cleared.
   *
   * @param person the person or null
   */
  private void showPersonDetails(Person person) {
    if (person != null) {
      // Fill the labels with info from the person object.
      firstNameLabel.setText(person.getFirstName());
      lastNameLabel.setText(person.getLastName());
      streetLabel.setText(person.getStreet());
      postalCodeLabel.setText(Integer.toString(person.getPostalCode()));
      cityLabel.setText(person.getCity());

      birthdayLabel.setText(DateUtil.format(person.getBirthday()));
      // birthdayLabel.setText(...);
    } else {
      // Person is null, remove all the text.
      firstNameLabel.setText("");
      lastNameLabel.setText("");
      streetLabel.setText("");
      postalCodeLabel.setText("");
      cityLabel.setText("");
      birthdayLabel.setText("");
    }
  }