Skip to content
Snippets Groups Projects
Commit 64630f09 authored by Karsch Lukas's avatar Karsch Lukas
Browse files

final modifications to make the file manager work

parent 61fe6a1d
No related branches found
No related tags found
No related merge requests found
...@@ -12,6 +12,8 @@ import org.apache.logging.log4j.Logger; ...@@ -12,6 +12,8 @@ import org.apache.logging.log4j.Logger;
public class GuiController extends Application { public class GuiController extends Application {
private final static Logger log = LogManager.getLogger(GuiController.class); private final static Logger log = LogManager.getLogger(GuiController.class);
private final static View STARTUP_VIEW = View.MAIN;
private static Stage stage; private static Stage stage;
private static TastyPages model; private static TastyPages model;
...@@ -33,12 +35,11 @@ public class GuiController extends Application { ...@@ -33,12 +35,11 @@ public class GuiController extends Application {
@Override @Override
public void start(Stage stage) throws Exception { public void start(Stage stage) throws Exception {
GuiController.stage = stage; GuiController.stage = stage;
final View startupView = View.MAIN;
Parent parent = startupView.getScene(); Parent parent = STARTUP_VIEW.getScene();
final Scene scene = new Scene(parent, 1400, 800); final Scene scene = new Scene(parent, 1400, 800);
stage.setTitle(startupView.getWindowTitle()); stage.setTitle(STARTUP_VIEW.getWindowTitle());
stage.setMaximized(true); //open scene in full screen stage.setMaximized(true); //open scene in full screen
stage.setScene(scene); stage.setScene(scene);
stage.show(); stage.show();
...@@ -51,4 +52,8 @@ public class GuiController extends Application { ...@@ -51,4 +52,8 @@ public class GuiController extends Application {
public static Stage getApplicationStage() { public static Stage getApplicationStage() {
return stage; return stage;
} }
public static View getStartupView() {
return STARTUP_VIEW;
}
} }
...@@ -13,11 +13,13 @@ import java.io.IOException; ...@@ -13,11 +13,13 @@ import java.io.IOException;
public abstract class BaseController { public abstract class BaseController {
private final static Logger log = LogManager.getLogger(BaseController.class); private final static Logger log = LogManager.getLogger(BaseController.class);
protected Scene currentScene; protected Scene currentScene; //TODO this should be static?
private static View currentView = TastyPages.startUpView; private static View currentView = GuiController.getStartupView();
protected void changeScene(final View newScene) { protected void changeScene(final View newScene) {
if (newScene == currentView) { return; } if (newScene == currentView) {
return;
}
final Stage stage = GuiController.getApplicationStage(); final Stage stage = GuiController.getApplicationStage();
try { try {
boolean wasMaximized = stage.isMaximized(); boolean wasMaximized = stage.isMaximized();
......
...@@ -17,8 +17,6 @@ public enum View { ...@@ -17,8 +17,6 @@ public enum View {
private static final Logger log = LogManager.getLogger(View.class); private static final Logger log = LogManager.getLogger(View.class);
private final static TastyPages model = GuiController.getModel();
private final String path; private final String path;
private final String windowTitle; private final String windowTitle;
...@@ -31,8 +29,9 @@ public enum View { ...@@ -31,8 +29,9 @@ public enum View {
log.info("Loading FXML for '{}' view from: {}", windowTitle, path); log.info("Loading FXML for '{}' view from: {}", windowTitle, path);
final FXMLLoader loader = new FXMLLoader(getClass().getResource(path)); final FXMLLoader loader = new FXMLLoader(getClass().getResource(path));
log.debug("Successfully retrieved resource from {}", path); log.debug("Successfully retrieved resource from {}", path);
TastyPages model = GuiController.getModel();
//set the correct controller factory for views (necessary to enable dependency injection) //set the correct controller factory for views (used for dependency injection)
switch (this) { switch (this) {
case MAIN -> loader.setControllerFactory((callback) -> case MAIN -> loader.setControllerFactory((callback) ->
new MainPageController(model.getRecipeManager(), model.getIngredientManager(), model.getCategoryManager()) new MainPageController(model.getRecipeManager(), model.getIngredientManager(), model.getCategoryManager())
......
...@@ -74,7 +74,6 @@ public class Recipe implements RecipeComponent { ...@@ -74,7 +74,6 @@ public class Recipe implements RecipeComponent {
setCategoriesFromObjects(categories); setCategoriesFromObjects(categories);
this.creationTime = LocalDateTime.now(); this.creationTime = LocalDateTime.now();
<<<<<<< src/main/java/mi/hdm/recipes/Recipe.java
this.code = calculateUniqueCode(); this.code = calculateUniqueCode();
} }
...@@ -98,6 +97,7 @@ public class Recipe implements RecipeComponent { ...@@ -98,6 +97,7 @@ public class Recipe implements RecipeComponent {
setCategories(categories); setCategories(categories);
this.creationTime = creationTime; this.creationTime = creationTime;
this.code = code; this.code = code;
//TODO: fix filepath
filepathForImage = "C:\\Users\\Lara Blersch\\Documents\\Studium\\SE2\\tasty-pages\\src\\main\\resources\\images\\dish-fork-and-knife.png"; //path to default image which can be changed by the user later filepathForImage = "C:\\Users\\Lara Blersch\\Documents\\Studium\\SE2\\tasty-pages\\src\\main\\resources\\images\\dish-fork-and-knife.png"; //path to default image which can be changed by the user later
} }
...@@ -202,8 +202,6 @@ public class Recipe implements RecipeComponent { ...@@ -202,8 +202,6 @@ public class Recipe implements RecipeComponent {
this.ingredients = ingredients; this.ingredients = ingredients;
} }
<<<<<<< src/main/java/mi/hdm/recipes/Recipe.java
private void setCategoriesFromObjects(List<Category> categories) { private void setCategoriesFromObjects(List<Category> categories) {
if (categories != null) { if (categories != null) {
this.categories = categories.stream() this.categories = categories.stream()
...@@ -222,11 +220,11 @@ public class Recipe implements RecipeComponent { ...@@ -222,11 +220,11 @@ public class Recipe implements RecipeComponent {
result.put(c.getUniqueCode(), map.get(c)); result.put(c.getUniqueCode(), map.get(c));
} }
return result; return result;
}
public void setImage(String path) { public void setImage(String path) {
filepathForImage = path; filepathForImage = path;
} }
=======
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
......
...@@ -7,7 +7,6 @@ import java.util.ArrayList; ...@@ -7,7 +7,6 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
public class RecipeSearch { public class RecipeSearch {
<<<<<<< src/main/java/mi/hdm/recipes/RecipeSearch.java
//TODO: lets make these methods static, no need to instantiate a new object every time //TODO: lets make these methods static, no need to instantiate a new object every time
private static final Logger log = LogManager.getLogger(RecipeSearch.class); private static final Logger log = LogManager.getLogger(RecipeSearch.class);
......
...@@ -22,7 +22,7 @@ class RecipeSearchTest { ...@@ -22,7 +22,7 @@ class RecipeSearchTest {
private static final IngredientManager ingredientManager = new IngredientManager(); private static final IngredientManager ingredientManager = new IngredientManager();
private List<Recipe> recipes; private List<Recipe> recipes;
//private RecipeSearch underTest; //not needed when methods are static private RecipeSearch underTest; //not needed when methods are static
@BeforeAll @BeforeAll
public static void setupAll() { public static void setupAll() {
......
...@@ -3,17 +3,20 @@ package mi.hdm.shoppingList; ...@@ -3,17 +3,20 @@ package mi.hdm.shoppingList;
import mi.hdm.exceptions.InvalidIngredientException; import mi.hdm.exceptions.InvalidIngredientException;
import mi.hdm.recipes.Ingredient; import mi.hdm.recipes.Ingredient;
import mi.hdm.recipes.Recipe; import mi.hdm.recipes.Recipe;
import mi.hdm.recipes.RecipeManager;
import mi.hdm.recipes.ValidObjectsPool; import mi.hdm.recipes.ValidObjectsPool;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import java.util.List;
import java.util.Map; import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
class ShoppingListTest { class ShoppingListTest {
private final ShoppingList underTest = new ShoppingList(ValidObjectsPool.getRecipeManager()); private final static RecipeManager recipeManager = ValidObjectsPool.getRecipeManager();
private final static ShoppingList underTest = new ShoppingList(recipeManager);
private final static Ingredient ing1 = ValidObjectsPool.getValidIngredientOne(); private final static Ingredient ing1 = ValidObjectsPool.getValidIngredientOne();
private final static Ingredient ing2 = ValidObjectsPool.getValidIngredientTwo(); private final static Ingredient ing2 = ValidObjectsPool.getValidIngredientTwo();
...@@ -21,7 +24,7 @@ class ShoppingListTest { ...@@ -21,7 +24,7 @@ class ShoppingListTest {
@BeforeEach @BeforeEach
public void setup() { public void setup() {
ValidObjectsPool.getRecipeManager().clear(); recipeManager.clear();
underTest.clear(); underTest.clear();
} }
...@@ -51,8 +54,18 @@ class ShoppingListTest { ...@@ -51,8 +54,18 @@ class ShoppingListTest {
@Test @Test
public void shouldAllAllIngredientsRecursively() { public void shouldAllAllIngredientsRecursively() {
//TODO: write test for adding ingredients to shopping list recursively //given
throw new RuntimeException("not implemented"); Recipe r1 = new Recipe("parent", Map.of(ValidObjectsPool.getValidIngredientOne(), 100), "Desc", List.of("prep"), List.of(), 10);
Recipe r2 = new Recipe("child", Map.of(r1, 100), "Desc", List.of("prep"), List.of(), 10);
Map<String, Boolean> expected = Map.of(ValidObjectsPool.getValidIngredientOne().getUniqueCode(), false);
recipeManager.addRecipe(r1);
recipeManager.addRecipe(r2);
//when
underTest.addAllToShoppingList(r2);
//expect
assertEquals(expected, underTest.getList());
} }
@Test @Test
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment