|
|
@@ -37,7 +37,7 @@ public class StepPanel extends JPanel implements AutoGrowPanel.DocumentListenabl
|
|
|
|
|
|
@Getter(AccessLevel.PACKAGE) JLabel lblIndex;
|
|
|
@Getter(AccessLevel.PACKAGE) JTextPane txtpnInstructions;
|
|
|
- @Getter(AccessLevel.PACKAGE) AutoGrowPanel panelIngredients;
|
|
|
+ @Getter(AccessLevel.PACKAGE) BetterAutoGrowPanel<IngredientPanel, Ingredient> panelIngredients;
|
|
|
|
|
|
public StepPanel(final Step step) {
|
|
|
GridBagLayout gridBagLayout = new GridBagLayout();
|
|
|
@@ -76,22 +76,14 @@ public class StepPanel extends JPanel implements AutoGrowPanel.DocumentListenabl
|
|
|
gbc_horizontalGlue.gridy = 0;
|
|
|
panelLeft.add(horizontalGlue, gbc_horizontalGlue);
|
|
|
|
|
|
- DurationPanel panelDuration = new DurationPanel("Requires", step.getDuration());
|
|
|
+ DurationPanel panelDuration = new DurationPanel("Requires");
|
|
|
GridBagConstraints gbc_panelDuration = new GridBagConstraints();
|
|
|
gbc_panelDuration.gridx = 2;
|
|
|
gbc_panelDuration.gridy = 0;
|
|
|
panelLeft.add(panelDuration, gbc_panelDuration);
|
|
|
|
|
|
final List<Ingredient> ingredients = step.getIngredients();
|
|
|
- panelIngredients = new AutoGrowPanel(IngredientPanel::new,
|
|
|
- Ingredient::new, ing -> {
|
|
|
- ingredients.add(ing);
|
|
|
- listener.setObserved(step, ingredients);
|
|
|
- }, i -> {
|
|
|
- ingredients.remove(i);
|
|
|
- listener.setObserved(step, ingredients);
|
|
|
- ObserverDispatch.notifySubscribers(step);
|
|
|
- }, 0, ingredients.toArray(new Ingredient[0]));
|
|
|
+ panelIngredients = new BetterAutoGrowPanel<>(Ingredient::new, IngredientPanel::new);
|
|
|
GridBagConstraints gbc_panelIngredients = new GridBagConstraints();
|
|
|
gbc_panelIngredients.gridwidth = 3;
|
|
|
gbc_panelIngredients.insets = new Insets(0, 0, 0, 5);
|
|
|
@@ -113,6 +105,12 @@ public class StepPanel extends JPanel implements AutoGrowPanel.DocumentListenabl
|
|
|
durationListener = ObservableController.from(panelDuration.txtTime,
|
|
|
Step::getDuration, Step::setDuration);
|
|
|
|
|
|
+ panelIngredients.setModel(step.getIngredients(), added -> {
|
|
|
+ listener.setObserved(step, step.getIngredients());
|
|
|
+ if (!added) {
|
|
|
+ ObserverDispatch.notifySubscribers(step);
|
|
|
+ }
|
|
|
+ });
|
|
|
listener.setObserved(step, ingredients);
|
|
|
intructionListener.setObserved(step);
|
|
|
durationListener.setObserved(step);
|