overview controller
This commit is contained in:
parent
f71d2f2751
commit
71d23d52fe
1 changed files with 196 additions and 0 deletions
196
client/src/main/java/client/scenes/OverviewCtrl.java
Normal file
196
client/src/main/java/client/scenes/OverviewCtrl.java
Normal file
|
|
@ -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<Recipe> recipeList;
|
||||
|
||||
@FXML
|
||||
private Button addRecipeButton;
|
||||
|
||||
@FXML
|
||||
private Button removeRecipeButton;
|
||||
|
||||
// === CENTER: RECIPE DETAILS ===
|
||||
@FXML
|
||||
private Label recipeNameLabel;
|
||||
|
||||
@FXML
|
||||
private Button editRecipeTitleButton;
|
||||
|
||||
@FXML
|
||||
private ListView<String> ingredientsListView;
|
||||
|
||||
@FXML
|
||||
private Button addIngredientButton;
|
||||
|
||||
@FXML
|
||||
private ListView<String> 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<Recipe> 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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue