Browse Source

Fix updates for ingredients changing instead of just add/remove.

Sam Jaffe 4 years ago
parent
commit
595350639b

+ 0 - 2
README.md

@@ -12,8 +12,6 @@ A java program for the purpose of storing and categorizing various recipes.
 - [x] Allow specifying instructions on every step
 - [x] Allow user to lock a recipe, to view it as complete instead of in-edit
 - [x] Change number of servings from default
-- [ ] Propagate updates to CollatedDurationPanel
-- [ ] Propagate updates to summary.IngredientPanel
 - [ ] Hide summary.ElementPanel for no-ingredient Elements
 - [ ] Ensure that instructions are not cut off in lock-view
 - [ ] Support images

+ 6 - 1
src/main/lombok/org/leumasjaffe/recipe/controller/ReplaceChildrenAction.java

@@ -3,25 +3,30 @@ package org.leumasjaffe.recipe.controller;
 import java.awt.Component;
 import java.awt.Container;
 import java.util.Collection;
+import java.util.Objects;
 import java.util.function.BiConsumer;
 import java.util.function.Function;
 
 import lombok.AccessLevel;
 import lombok.RequiredArgsConstructor;
 import lombok.experimental.FieldDefaults;
+import lombok.experimental.NonFinal;
 
 @RequiredArgsConstructor
 @FieldDefaults(level=AccessLevel.PRIVATE, makeFinal=true)
 public class ReplaceChildrenAction<T, V> implements BiConsumer<Container, T> {
 	Function<T, ? extends Collection<V>> getChildren;
 	Function<? super V, ? extends Component> makeView;
+	@NonFinal Collection<V> children = null;
 	
 	@Override
 	public void accept(final Container parent, final T model) {
 		final Collection<V> children = getChildren.apply(model);
-		if (parent.getComponents().length == children.size()) {
+		if (Objects.equals(this.children, children)) {
 			return;
 		}
+		this.children = children;
+		
 		// Make sure that our components disappear correctly
 		for (final Component comp : parent.getComponents()) {
 			comp.setVisible(false);