Compare commits
3 commits
a32f4cd781
...
bb77c83289
| Author | SHA1 | Date | |
|---|---|---|---|
| bb77c83289 | |||
|
aec8a6bc17 |
|||
|
0da9490a60 |
1 changed files with 9 additions and 5 deletions
|
|
@ -64,18 +64,21 @@ public class IngredientListCell extends OrderedEditableListCell<RecipeIngredient
|
||||||
|
|
||||||
Optional<Double> templateAmount = Optional.empty();
|
Optional<Double> templateAmount = Optional.empty();
|
||||||
Optional<Unit> unit = Optional.empty();
|
Optional<Unit> unit = Optional.empty();
|
||||||
|
TextField amountInput;
|
||||||
// Initialize the input fields with some initial data if we get a formal ingredient
|
// Initialize the input fields with some initial data if we get a formal ingredient
|
||||||
if (ingredient.getClass().equals(FormalIngredient.class)) {
|
if (ingredient.getClass().equals(FormalIngredient.class)) {
|
||||||
FormalIngredient formal = (FormalIngredient) ingredient;
|
FormalIngredient formal = (FormalIngredient) ingredient;
|
||||||
templateAmount = Optional.of(formal.getAmount());
|
templateAmount = Optional.of(formal.getAmount());
|
||||||
unit = Optional.of(Unit.fromString(formal.getUnitSuffix()).orElseThrow(
|
unit = Optional.of(Unit.fromString(formal.getUnitSuffix()).orElseThrow(
|
||||||
() -> new RuntimeException("FormalIngredient whereas invalid unit")));
|
() -> 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
|
// Initialize the input boxes
|
||||||
TextField amountInput = new TextField(templateAmount.map(Object::toString).orElse(null));
|
|
||||||
ChoiceBox<Unit> unitChoice = new ChoiceBox<>();
|
ChoiceBox<Unit> unitChoice = new ChoiceBox<>();
|
||||||
|
|
||||||
// initialize the current unit if it is present
|
// 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
|
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
|
selectedIngredient.setValue(null); // indicate null to signal a new ingredient creation
|
||||||
logger.info("Making new ingredient");
|
logger.info("Making new ingredient");
|
||||||
// TODO printError() integration
|
|
||||||
TextField newIngredientNameInput = makeNewIngredientNameField(selectedIngredient::set);
|
TextField newIngredientNameInput = makeNewIngredientNameField(selectedIngredient::set);
|
||||||
container.getChildren().add(newIngredientNameInput);
|
container.getChildren().add(newIngredientNameInput);
|
||||||
});
|
});
|
||||||
|
|
@ -135,7 +137,9 @@ public class IngredientListCell extends OrderedEditableListCell<RecipeIngredient
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private HBox makeInputLine(RecipeIngredient ingredient, TextField amountInput, ChoiceBox<Unit> unitChoice) {
|
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);
|
HBox container = new HBox(amountInput, unitChoice, ingredientSelect);
|
||||||
try {
|
try {
|
||||||
makeMenuItems(ingredientSelect, server.getIngredients(), Ingredient::getName, i -> {
|
makeMenuItems(ingredientSelect, server.getIngredients(), Ingredient::getName, i -> {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue