private void handleBirthDateChange() {
   String bdateStr = view.bDateFld.getText();
   if (bdateStr == null || bdateStr.trim().equals("")) {
     model.setBirthDate(null);
     view.syncBirthDate();
   } else {
     try {
       DateTimeFormatter formatter = DateTimeFormatter.ofPattern(view.dateFormat);
       LocalDate bdate = LocalDate.parse(bdateStr, formatter);
       List<String> errorList = new ArrayList<>();
       if (model.isValidBirthDate(bdate, errorList)) {
         model.setBirthDate(bdate);
         view.syncAgeCategory();
       } else {
         this.showError(errorList);
         view.syncBirthDate();
       }
     } catch (DateTimeParseException e) {
       // Birth date is not in the specified date format
       List<String> errorList = new ArrayList<>();
       errorList.add("Birth date must be in the " + view.dateFormat.toLowerCase() + " format.");
       this.showError(errorList);
       // Refresh the view
       view.syncBirthDate();
     }
   }
 }
  private void showError(List<String> errorList) {
    String msg = "";
    if (errorList.isEmpty()) {
      msg = "No message to display.";
    } else {
      for (String s : errorList) {
        msg = msg + s + "\n";
      }
    }
    Label msgLbl = new Label(msg);
    Button okBtn = new Button("OK");
    VBox root = new VBox(new StackPane(msgLbl), new StackPane(okBtn));
    root.setSpacing(10);

    Scene scene = new Scene(root);
    Stage stage = new Stage(StageStyle.UTILITY);
    stage.initModality(Modality.WINDOW_MODAL);
    stage.setScene(scene);
    stage.initOwner(view.getScene().getWindow());

    // Set the Action listener for the OK button
    okBtn.setOnAction(e -> stage.close());

    stage.setTitle("Error");
    stage.sizeToScene();
    stage.showAndWait();
  }
  /**
   * Gets contact from view.
   *
   * @return a Contact
   */
  public Contact getContact() {
    Contact c = new Contact(personView.get());
    c.setAddress(getAddress());
    c.setTele(getTele());
    c.setEmail(getEmail());
    c.setWebSites(getSites());

    return c;
  }
  private PersonView addPersonRow() {
    final View view = getLayoutInflater().inflate(R.layout.person_list_entry, personList, false);
    personList.addView(view);

    final PersonView personView = new PersonView();
    personView.view = view;
    personView.nameField = (EditText) view.findViewById(R.id.person_name);
    personView.deleteButton = (ImageView) view.findViewById(R.id.delete_button);
    personViews.add(personView);

    personView.nameField.setId(-1); // do not restore in onRestoreInstanceState()
    personView.nameField.addTextChangedListener(
        new TextWatcher() {
          @Override
          public void onTextChanged(CharSequence s, int start, int before, int count) {}

          @Override
          public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

          @Override
          public void afterTextChanged(Editable s) {
            createOrDeletePersonRows();
          }
        });

    personView.nameField.setOnFocusChangeListener(
        new View.OnFocusChangeListener() {
          @Override
          public void onFocusChange(View v, boolean hasFocus) {
            if (!hasFocus) createOrDeletePersonRows();
          }
        });

    personView.deleteButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            deletePersonRow(personView);
            createOrDeletePersonRows();
          }
        });
    return personView;
  }
  private void attachEvents() {

    // We need to detect the birth date change when the bDate field loses
    // focus or the user presses the Enter key while it still has focus
    view.bDateFld.setOnAction(e -> handleBirthDateChange());
    view.bDateFld.getScene().focusOwnerProperty().addListener(this::focusChanged);

    view.saveBtn.setOnAction(e -> saveData());

    view.closeBtn.setOnAction(e -> view.getScene().getWindow().hide());
  }
  public void clear() {
    contact = null;
    personView.clear();
    teleView.clear();
    emailView.clear();
    websiteView.clear();
    addressView.clear();

    if (cbTelAddress != null) {
      cbTelAddress.removeItemListener(this);
      remove(cbTelAddress);
      revalidate();
      cbTelAddress = null;
    }
    linkTelAddress = false;
    note.setText("");
  }
 /**
  * Filtering contact view.
  *
  * @param f int person type
  */
 public void filter(int f) {
   personView.filter(f);
 }
 public Person getPerson() {
   return personView.get();
 }
 public void setPerson(Person p) {
   if (p != null) {
     String configDir = ConfigUtil.getConf(ConfigKey.PHOTOS_PATH.getKey());
     personView.set(p, configDir);
   }
 }
 public void setSubscriptionRest(PersonSubscriptionCard card) {
   personView.showSubscriptionRest(card);
 }
 public void setID(int i) {
   personView.setId(i);
 }
 public int getId() {
   return personView.getId();
 }