/** Load the groups of a contact. */
  public final void setupGroups() {
    for (Group g : c.getGroups()) {

      String name = g.getName();

      if (!ACTIVEDATA.contains("Arbeit") && name.equals("Arbeit")) {
        ACTIVEDATA.add("Arbeit");
      } else {
        if (!INACTIVEDATA.contains("Arbeit") && !ACTIVEDATA.contains("Arbeit")) {
          INACTIVEDATA.add("Arbeit");
        }
      }
      if (!ACTIVEDATA.contains("Familie") && name.equals("Familie")) {
        ACTIVEDATA.add("Familie");
      } else {
        if (!INACTIVEDATA.contains("Familie") && !ACTIVEDATA.contains("Familie")) {
          INACTIVEDATA.add("Familie");
        }
      }
      if (!ACTIVEDATA.contains("Freunde") && name.equals("Freunde")) {
        ACTIVEDATA.add("Freunde");
      } else {
        if (!INACTIVEDATA.contains("Freunde") && !ACTIVEDATA.contains("Freunde")) {
          INACTIVEDATA.add("Freunde");
        }
      }
    }

    enabled.setItems(ACTIVEDATA);
    disabled.setItems(INACTIVEDATA);
  }
  /**
   * @param event event of button
   * @throws GroupNotValidException not valid
   * @throws IDNotValidException not valid
   * @throws StringNotValidException not valid
   */
  public final void onBtnGroupClick(final ActionEvent event)
      throws GroupNotValidException, IDNotValidException, StringNotValidException {

    try {
      Object item = disabled.getSelectionModel().getSelectedItem();
      Button button = (Button) event.getSource();

      // add a group
      if (button.getText().equals("<<")) {

        if (item.toString().equals("Arbeit")) {
          INACTIVEDATA.remove(item);
          ACTIVEDATA.add(item);
          c.addToGroup(Main.getWorkGroup());
        }
        if (item.toString().equals("Familie")) {
          INACTIVEDATA.remove(item);
          ACTIVEDATA.add(item);
          c.addToGroup(Main.getFamilyGroup());
        }
        if (item.toString().equals("Freunde")) {
          INACTIVEDATA.remove(item);
          ACTIVEDATA.add(item);
          c.addToGroup(Main.getFriendsGroup());
        }
      }

      // remove a group
      item = enabled.getSelectionModel().getSelectedItem();
      if (button.getText().equals(">>")) {

        if (item.toString().equals("Arbeit")) {
          ACTIVEDATA.remove(item);
          INACTIVEDATA.add(item);
          c.removeFromGroup(Main.getWorkGroup());
        }
        if (item.toString().equals("Familie")) {
          ACTIVEDATA.remove(item);
          INACTIVEDATA.add(item);
          c.removeFromGroup(Main.getFamilyGroup());
        }
        if (item.toString().equals("Freunde")) {
          ACTIVEDATA.remove(item);
          INACTIVEDATA.add(item);
          c.removeFromGroup(Main.getFriendsGroup());
        }
      }

    } catch (Exception e) {

      Alert alert = new Alert(AlertType.ERROR);
      alert.setTitle("Keine gültige Gruppe erkannt.");
      alert.setHeaderText("");
      alert.setContentText("Es wurde keine gültige Gruppe erkannt. Klicke auf gültige Gruppe.");
      alert.showAndWait();

      logger.log(Level.SEVERE, "Error: " + e.getMessage());
    }
  }
  /** @throws StringNotValidException a */
  public final void onBtnSaveClick() throws StringNotValidException {

    String firstName;
    String lastName;
    TableMain tm;

    try {
      firstName = StringUtils.defaultIfBlank(txtFirstName.getText(), "MusterName");
      lastName = StringUtils.defaultIfBlank(txtLastName.getText(), "MusterName");
      c.setFirstName(firstName);
      c.setLastName(lastName);

      // update table view with name only
      tm =
          MainPresenter.getData()
              .get(
                  MainPresenter.getMainPresenterInstance()
                      .getMainTable()
                      .getSelectionModel()
                      .getSelectedIndex());
      tm.setFirstName(firstName);
      tm.setLastName(lastName);

      // set rest of contact information
      c.setEmail(StringUtils.defaultIfBlank(txtEmail.getText(), "MusterEmail"));
      c.setPhoneNumber(StringUtils.defaultIfBlank(txtPhoneNumber.getText(), "MusterNummer"));
      if (contactImage != null) {
        c.setPhoto(contactImage);
      }
      c.getAddress().setZipCode(StringUtils.defaultString(txtZipCode.getText(), "12345"));
      c.getAddress().setStreet(StringUtils.defaultIfBlank(txtStreet.getText(), "MusterStraße"));
      c.getAddress().setCity(StringUtils.defaultIfBlank(txtCity.getText(), "MusterStadt"));
      c.getAddress().setCountry(StringUtils.defaultIfBlank(txtCountry.getText(), "MusterLand"));

      int housenumber = 0;

      if (!StringUtils.isNumeric(txtHouseNumber.getText()) || (txtHouseNumber.equals("0"))) {
        throw new HouseNumberNotValidException("Diese Hausnummer ist nicht erlaubt");
      }
      housenumber = Integer.parseInt(txtHouseNumber.getText());
      if (housenumber > 300) {
        throw new HouseNumberNotValidException(
            "Hausnummer zu groß: Maximal erlaubte Hausnummer '300'");
      }
      c.getAddress().setHouseNumber(housenumber);

      txtFirstName.clear();
      txtLastName.clear();
      txtBorn.clear();
      txtCity.clear();
      txtEmail.clear();
      txtHouseNumber.clear();
      txtZipCode.clear();
      txtPhoneNumber.clear();

      onBtnBackClick();
      logger.log(Level.INFO, "New Information saved:");

    } catch (Exception e) {
      logger.log(Level.SEVERE, e.getMessage());
    }
  }
  /**
   * Get contact information and display them.
   *
   * @throws IOException error
   */
  public final void setupTextFields() throws IOException {

    String firstName;
    String lastName;
    String email;
    String phoneNumber;
    String city;
    String born;
    String zipCode;
    String street;
    String country;
    int houseNumber;

    firstName = c.getFirstName();
    lastName = c.getLastName();
    email = c.getEmail();
    phoneNumber = c.getPhoneNumber();
    born = c.getBirthday().toGMTString();
    Image temp = SwingFXUtils.toFXImage(c.getPhoto().get(), null);
    image.setImage(temp);
    zipCode = c.getAddress().getZipCode();
    city = c.getAddress().getCity();
    houseNumber = c.getAddress().getHouseNumber();
    street = c.getAddress().getStreet();
    country = c.getAddress().getCountry();

    this.txtFirstName.setText(firstName);
    this.txtLastName.setText(lastName);
    this.txtEmail.setText(email);
    this.txtPhoneNumber.setText(phoneNumber);
    this.txtCity.setText(city);
    this.txtHouseNumber.setText(String.valueOf(houseNumber));
    this.txtBorn.setText(born);
    this.txtZipCode.setText(zipCode);
    this.txtStreet.setText(street);
    this.txtCountry.setText(country);
  }