|
|
@@ -3,6 +3,9 @@ package org.leumasjaffe.recipe.view;
|
|
|
import javax.swing.JPanel;
|
|
|
|
|
|
import org.jdesktop.swingx.VerticalLayout;
|
|
|
+import org.leumasjaffe.observer.ObservableListener;
|
|
|
+import org.leumasjaffe.recipe.controller.ReplaceChildrenController;
|
|
|
+import org.leumasjaffe.recipe.model.Ingredient;
|
|
|
import org.leumasjaffe.recipe.model.Preparation;
|
|
|
|
|
|
import lombok.AccessLevel;
|
|
|
@@ -19,12 +22,17 @@ import java.awt.Component;
|
|
|
import javax.swing.Box;
|
|
|
|
|
|
@SuppressWarnings("serial")
|
|
|
-@FieldDefaults(level=AccessLevel.PRIVATE, makeFinal=true)
|
|
|
+@FieldDefaults(level=AccessLevel.PRIVATE)
|
|
|
public class PreparationPanel extends JPanel {
|
|
|
- @Getter(AccessLevel.PACKAGE) JLabel lblDuration;
|
|
|
+ ReplaceChildrenController<Preparation, Ingredient> controller;
|
|
|
+ ObservableListener<JPanel, Preparation> childListener;
|
|
|
+
|
|
|
@Getter(AccessLevel.PACKAGE) JPanel panelIngredients;
|
|
|
|
|
|
- public PreparationPanel(Preparation step) {
|
|
|
+ public PreparationPanel(Preparation preparation) {
|
|
|
+ controller = new ReplaceChildrenController<>(Preparation::getIngredients,
|
|
|
+ IngredientPreparationPanel::new);
|
|
|
+
|
|
|
GridBagLayout gridBagLayout = new GridBagLayout();
|
|
|
gridBagLayout.columnWidths = new int[]{0, 0, 0};
|
|
|
gridBagLayout.rowHeights = new int[]{0, 0};
|
|
|
@@ -61,12 +69,12 @@ public class PreparationPanel extends JPanel {
|
|
|
gbc_horizontalGlue.gridy = 0;
|
|
|
panelLeft.add(horizontalGlue, gbc_horizontalGlue);
|
|
|
|
|
|
- lblDuration = new JLabel("Requires: " + step.getDuration().toString());
|
|
|
- GridBagConstraints gbc_lblDuration = new GridBagConstraints();
|
|
|
- gbc_lblDuration.insets = new Insets(0, 0, 5, 0);
|
|
|
- gbc_lblDuration.gridx = 2;
|
|
|
- gbc_lblDuration.gridy = 0;
|
|
|
- panelLeft.add(lblDuration, gbc_lblDuration);
|
|
|
+ DurationPanel panelDuration = new DurationPanel("Requires", preparation.getDuration());
|
|
|
+ GridBagConstraints gbc_panelDuration = new GridBagConstraints();
|
|
|
+ gbc_panelDuration.insets = new Insets(0, 0, 5, 0);
|
|
|
+ gbc_panelDuration.gridx = 2;
|
|
|
+ gbc_panelDuration.gridy = 0;
|
|
|
+ panelLeft.add(panelDuration, gbc_panelDuration);
|
|
|
|
|
|
panelIngredients = new JPanel();
|
|
|
panelIngredients.setLayout(new VerticalLayout(5));
|
|
|
@@ -77,7 +85,12 @@ public class PreparationPanel extends JPanel {
|
|
|
gbc_panelIngredients.gridx = 0;
|
|
|
gbc_panelIngredients.gridy = 1;
|
|
|
panelLeft.add(panelIngredients, gbc_panelIngredients);
|
|
|
- step.getIngredientsAsStream().map(IngredientPreparationPanel::new).forEach(panelIngredients::add);
|
|
|
+
|
|
|
+ // This indirection allows for testing of controller
|
|
|
+ childListener = new ObservableListener<>(panelIngredients,
|
|
|
+ (c, v) -> controller.accept(c, v));
|
|
|
+
|
|
|
+ childListener.setObserved(preparation);
|
|
|
}
|
|
|
|
|
|
}
|