Compare commits

..

2 commits

View file

@ -64,18 +64,21 @@ public class IngredientListCell extends OrderedEditableListCell<RecipeIngredient
Optional<Double> templateAmount = Optional.empty();
Optional<Unit> unit = Optional.empty();
TextField amountInput;
// Initialize the input fields with some initial data if we get a formal ingredient
if (ingredient.getClass().equals(FormalIngredient.class)) {
FormalIngredient formal = (FormalIngredient) ingredient;
templateAmount = Optional.of(formal.getAmount());
unit = Optional.of(Unit.fromString(formal.getUnitSuffix()).orElseThrow(
() -> new RuntimeException("FormalIngredient whereas invalid unit")));
amountInput = new TextField(templateAmount.map(Object::toString).orElse(null));
} else {
assert ingredient instanceof VagueIngredient;
amountInput = new TextField(((VagueIngredient) ingredient).getDescription());
}
// TODO initialize some other data in the case of vague ingredient
// Initialize the input boxes
TextField amountInput = new TextField(templateAmount.map(Object::toString).orElse(null));
ChoiceBox<Unit> unitChoice = new ChoiceBox<>();
// initialize the current unit if it is present
@ -115,7 +118,6 @@ public class IngredientListCell extends OrderedEditableListCell<RecipeIngredient
menu.setText(getLocaleString("app.prompt.new-ingredient")); // otherwise the text label on menu refuses to update
selectedIngredient.setValue(null); // indicate null to signal a new ingredient creation
logger.info("Making new ingredient");
// TODO printError() integration
TextField newIngredientNameInput = makeNewIngredientNameField(selectedIngredient::set);
container.getChildren().add(newIngredientNameInput);
});
@ -135,7 +137,9 @@ public class IngredientListCell extends OrderedEditableListCell<RecipeIngredient
}
}
private HBox makeInputLine(RecipeIngredient ingredient, TextField amountInput, ChoiceBox<Unit> unitChoice) {
MenuButton ingredientSelect = new MenuButton(getLocaleString("app.prompt.select-ingredient"));
selectedIngredient.setValue(ingredient.getIngredient());
MenuButton ingredientSelect = new MenuButton(selectedIngredient.get() == null ?
getLocaleString("app.prompt.select-ingredient") : selectedIngredient.get().getName());
HBox container = new HBox(amountInput, unitChoice, ingredientSelect);
try {
makeMenuItems(ingredientSelect, server.getIngredients(), Ingredient::getName, i -> {