|
|
@@ -6,6 +6,7 @@ import org.jdesktop.swingx.VerticalLayout;
|
|
|
import org.leumasjaffe.observer.IndirectObservableListener;
|
|
|
import org.leumasjaffe.observer.ObservableController;
|
|
|
import org.leumasjaffe.observer.ObservableListener;
|
|
|
+import org.leumasjaffe.observer.ObserverDispatch;
|
|
|
import org.leumasjaffe.recipe.controller.ReplaceChildrenController;
|
|
|
import org.leumasjaffe.recipe.model.Duration;
|
|
|
import org.leumasjaffe.recipe.model.Ingredient;
|
|
|
@@ -30,7 +31,7 @@ import javax.swing.JFormattedTextField;
|
|
|
public class PreparationPanel extends JPanel {
|
|
|
ReplaceChildrenController<Preparation, Ingredient> controller;
|
|
|
IndirectObservableListener<JPanel, Preparation> childListener;
|
|
|
- ObservableListener<JFormattedTextField, Preparation> durationListener;
|
|
|
+ ObservableListener<JFormattedTextField, Preparation> durationController;
|
|
|
|
|
|
public PreparationPanel() {
|
|
|
controller = new ReplaceChildrenController<>(Preparation::getIngredients,
|
|
|
@@ -91,7 +92,7 @@ public class PreparationPanel extends JPanel {
|
|
|
// This indirection allows for testing of controller
|
|
|
childListener = new IndirectObservableListener<>(panelIngredients,
|
|
|
(c, v) -> controller.accept(c, v));
|
|
|
- durationListener = ObservableController.from(panelDuration.txtTime,
|
|
|
+ durationController = ObservableController.from(panelDuration.txtTime,
|
|
|
Preparation::getDuration, Preparation::setDuration);
|
|
|
}
|
|
|
|
|
|
@@ -101,8 +102,15 @@ public class PreparationPanel extends JPanel {
|
|
|
}
|
|
|
|
|
|
public void setModel(final Phase phase) {
|
|
|
- durationListener.setObserved(phase.getPreparation().get());
|
|
|
childListener.setObserved(phase.getPreparation().get(), phase);
|
|
|
+ durationController.setObserved(phase.getPreparation().get());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void removeNotify() {
|
|
|
+ super.removeNotify();
|
|
|
+ ObserverDispatch.unsubscribeAll(childListener);
|
|
|
+ ObserverDispatch.unsubscribeAll(durationController);
|
|
|
}
|
|
|
|
|
|
}
|