Exemplo n.º 1
0
  /** Loads the name of all ingredients and puts them in ingredientlist. */
  public void updateIngredients() {
    ArrayList<ArrayList<String>> dataSet;
    ObservableList<String> itemList =
        FXCollections.observableArrayList(); // Observable arraylist for the listview

    try {
      System.out.println("- Main updateIngredientsRecipList");

      dataSet = fetchData("Ingredients", "Name"); // Gives the arraylist the ingredientnames

      for (ArrayList<String> element : dataSet) {
        itemList.add(element.get(0)); // For every element in the array, get name
      }

      System.out.println("- end of Main updateIngredientsRecipList");
    } catch (SQLException e) {
      e.printStackTrace();
    }
    recipeIngredients.setItems(itemList); // Sets the Listview to show the obs arraylist

    itemList.clear();
    try {
      dataSet = fetchData("Units", "*");

      for (ArrayList<String> element : dataSet) {
        itemList.add(element.get(1));
      }
    } catch (SQLException e) {
      e.printStackTrace();
    }
    ingredientUnit.setItems(itemList);
  }
Exemplo n.º 2
0
  /** ButtonMethod for add ingredients from the ingredientList into the tableview */
  public void addIngredientButton() {

    String selectedIngredient = recipeIngredients.getSelectionModel().getSelectedItems().toString();
    selectedIngredient = selectedIngredient.replaceAll("\\[", "").replaceAll("\\]", "");

    items.add(
        new Ingredient(
            selectedIngredient,
            ingredientAmount.getText(),
            ingredientUnit.getSelectionModel().getSelectedItem().toString())); // Creates new
    addedIngredientTable.setItems(
        items); // Object of the type Ingredient and adds it to the tableView.
  }