@FXML
 private void handleAddButton() {
   hideLabels();
   successLabel.setVisible(false);
   if (ver.verify(fieldArray) == true) {
     ingredientStorage.storeIngredientType(
         new IngredientType(nameField.getText(), measurementField.getText()));
     successLabel.setText(String.format("Ingredienttype %s added.", nameField.getText()));
     successLabel.setVisible(true);
     nameField.setText("");
     measurementField.setText("");
   } else {
     errorLabel.setVisible(true);
     for (TextField tf : ver.getErrorList()) {
       if (tf.equals(nameField)) {
         nameFieldErrorLabel.setVisible(true);
       } else if (tf.equals(measurementField)) {
         measurementFieldErrorLabel.setVisible(true);
       }
     }
   }
 }
コード例 #2
0
  /** @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());
    }
  }