From 7e924e064a4ca83655cd358c1ec6c8334916385e Mon Sep 17 00:00:00 2001 From: Aysegul Aydinlik Date: Thu, 27 Nov 2025 14:56:09 +0100 Subject: [PATCH] overview controller --- .../main/java/client/scenes/OverviewCtrl.java | 196 ++++++++++++++++++ 1 file changed, 196 insertions(+) create mode 100644 client/src/main/java/client/scenes/OverviewCtrl.java diff --git a/client/src/main/java/client/scenes/OverviewCtrl.java b/client/src/main/java/client/scenes/OverviewCtrl.java new file mode 100644 index 0000000..6a71d19 --- /dev/null +++ b/client/src/main/java/client/scenes/OverviewCtrl.java @@ -0,0 +1,196 @@ +package client.scenes; + + +import java.util.List; + +//import commons.Recipe; or something +import jakarta.inject.Inject; +import javafx.fxml.FXML; +import javafx.scene.control.Button; +import javafx.scene.control.Label; +import javafx.scene.control.ListCell; +import javafx.scene.control.ListView; + +public class OverviewCtrl { + + private final MainCtrl mainCtrl; + + // everything in the top bar === + @FXML + private Button flagEnButton; + + @FXML + private Button flagNlButton; + + @FXML + private Button flagPlButton; + + @FXML + private Button refreshButton; + + @FXML + private Button closeButton; + + @FXML + private Button maximizeButton; + + @FXML + private Button minimizeButton; + + // everything in the left lane + @FXML + private ListView recipeList; + + @FXML + private Button addRecipeButton; + + @FXML + private Button removeRecipeButton; + + // === CENTER: RECIPE DETAILS === + @FXML + private Label recipeNameLabel; + + @FXML + private Button editRecipeTitleButton; + + @FXML + private ListView ingredientsListView; + + @FXML + private Button addIngredientButton; + + @FXML + private ListView preparationListView; + + @FXML + private Button addPreparationStepButton; + + @Inject + public OverviewCtrl(MainCtrl mainCtrl) { + this.mainCtrl = mainCtrl; + } + + @FXML + private void initialize() { + // Show recipe name in the list + recipeList.setCellFactory(list -> new ListCell<>() { + @Override + protected void updateItem(Recipe item, boolean empty) { + super.updateItem(item, empty); + setText(empty || item == null ? "" : item.name); + } + }); + + // When your selection changes, update details in the panel + recipeList.getSelectionModel().selectedItemProperty().addListener( + (obs, oldRecipe, newRecipe) -> showRecipeDetails(newRecipe) + ); + + // Double-click to go to detail screen + recipeList.setOnMouseClicked(event -> { + if (event.getClickCount() == 2) { + openSelectedRecipe(); + } + }); + + refresh(); + } + + // ================== BUTTON HANDLERS ================== + + @FXML + private void refresh() { + // TODO: someone else doing this + List recipes = getMockRecipes(); + recipeList.getItems().setAll(recipes); + + // Select first recipe in the list by default + if (!recipes.isEmpty()) { + recipeList.getSelectionModel().selectFirst(); + } + } + + @FXML + private void addRecipe() { + // Navigate to "create recipe" screen (should be like a pop-up or new screen or just another place in the app) + mainCtrl.showCreateRecipe(); + } + + @FXML + private void removeSelectedRecipe() { + Recipe selected = recipeList.getSelectionModel().getSelectedItem(); + if (selected == null) { + return; + } + + // TODO: someone else todo + recipeList.getItems().remove(selected); + showRecipeDetails(null); + } + + @FXML + private void openSelectedRecipe() { + Recipe selected = recipeList.getSelectionModel().getSelectedItem(); + if (selected == null) { + return; + } + // Let MainCtrl open the full detail screen + mainCtrl.showRecipeDetail(selected.id); + } + + @FXML + private void editRecipeTitle() { + // TODO: someone else todo + // For now reuse openSelectedRecipe() + openSelectedRecipe(); + } + + @FXML + private void addIngredient() { + // TODO: make it possible to add ingredient to current recipe + System.out.println("Add ingredient clicked"); + } + + @FXML + private void addPreparationStep() { + // TODO: make it possible to add step to current recipe + System.out.println("Add preparation step clicked"); + } + + // Language buttons + @FXML + private void switchToEnglish() { + System.out.println("Switch language to EN"); + } + + @FXML + private void switchToDutch() { + System.out.println("Switch language to NL"); + } + + @FXML + private void switchToPolish() { + System.out.println("Switch language to PL"); + } + + // Window control buttons (are we keeping this?) + @FXML + private void closeWindow() { + mainCtrl.closeApplication(); + } + + @FXML + private void maximizeWindow() { + mainCtrl.toggleMaximize(); + } + + @FXML + private void minimizeWindow() { + mainCtrl.minimize(); + } +} + + + +