Browse Source

Merge branches 'bugfix/propagate' and 'refactor/hide-empty-summary'

* bugfix/propagate:
  Fix updates for ingredients changing instead of just add/remove.

* refactor/hide-empty-summary:
  Hide Elements from the SummaryPanel when the Element has no ingredients.
Sam Jaffe 4 years ago
parent
commit
560fd5ec9a

+ 1 - 2
README.md

@@ -12,7 +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
-- [ ] Hide summary.ElementPanel for no-ingredient Elements
 - [ ] Ensure that instructions are not cut off in lock-view
 - [ ] Support images
 - [ ] Ingredient/Tag searching for recipes
@@ -24,4 +23,4 @@ A java program for the purpose of storing and categorizing various recipes.
 
 ## 0.3.0 Features
 
-- [ ] Create dependency tree for Products
+- [ ] Create dependency tree for Products

+ 8 - 1
src/main/lombok/org/leumasjaffe/recipe/view/summary/SummaryPanel.java

@@ -4,6 +4,10 @@ import java.awt.Dimension;
 import java.awt.GridBagConstraints;
 import java.awt.GridBagLayout;
 import java.awt.Insets;
+import java.util.Collection;
+import java.util.function.Function;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
 
 import javax.swing.JPanel;
 import javax.swing.JSeparator;
@@ -46,7 +50,10 @@ public class SummaryPanel extends JPanel {
 	JSpinner spnServingsToMake;
 	
 	public SummaryPanel(final ScaleFactor scale) {
-		controller = new ReplaceChildrenAction<>(RecipeCard::getElements, element -> {
+		final Predicate<Element> hasIngredients = e -> !e.getIngredients().isEmpty();
+		final Function<RecipeCard, Collection<Element>> func =
+				rc -> rc.getComponents().filter(hasIngredients).collect(Collectors.toList());
+		controller = new ReplaceChildrenAction<>(func, element -> {
 			JPanel wrapper = new JPanel(new VerticalLayout());
 			wrapper.add(new ElementPanel(element, scale));
 			wrapper.add(new JSeparator());