/** Called when user click on the "new" button */
  @FXML
  private void handleNewPerson() {
    Person person = new Person();
    boolean okClicked = mainApp.showPersonEditDialog(person);

    if (okClicked) {
      mainApp.getPersonData().add(person);
    }
  }
  /**
   * Called when user clicked on the "edit" button. Opens a dialog to edit details for the selected
   * person
   */
  @FXML
  private void handleEditPerson() {
    Person person = personTable.getSelectionModel().getSelectedItem();

    if (person != null) {
      boolean okClicked = mainApp.showPersonEditDialog(person);
      if (okClicked) {
        showPersonDetails(person);
      }
    } else {
      // nothing selected
      Alert alert = new Alert(Alert.AlertType.ERROR);

      alert.setTitle("No selection");
      alert.setHeaderText("No person selected");
      alert.setContentText("Please select a person in the table");

      alert.showAndWait();
    }
  }
  /**
   * Is called by the main application to give a reference back to itself.
   *
   * @param mainApp
   */
  public void setMainApp(MainApp mainApp) {
    this.mainApp = mainApp;

    // Add observable list data to the table
    personTable.setItems(mainApp.getPersonData());
  }