auto-refresh product list

This commit is contained in:
2026-04-20 10:41:49 -06:00
parent dd9ea67d90
commit ea73ab687b

View File

@@ -1,5 +1,7 @@
package org.example.petshopdesktop.controllers; package org.example.petshopdesktop.controllers;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.collections.FXCollections; import javafx.collections.FXCollections;
import javafx.collections.ObservableList; import javafx.collections.ObservableList;
@@ -8,6 +10,7 @@ import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.geometry.Pos; import javafx.geometry.Pos;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.util.Duration;
import javafx.scene.control.*; import javafx.scene.control.*;
import javafx.scene.control.cell.PropertyValueFactory; import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.image.ImageView; import javafx.scene.image.ImageView;
@@ -78,8 +81,9 @@ public class ProductController {
private TextField txtSearch; private TextField txtSearch;
//data declaration //data declaration
private ObservableList<ProductDTO> data = FXCollections.observableArrayList(); //empty private ObservableList<ProductDTO> data = FXCollections.observableArrayList();
private String mode = null; private String mode = null;
private Timeline refreshTimer;
/** /**
* Set up the table view for products and display it when starting up * Set up the table view for products and display it when starting up
@@ -130,6 +134,15 @@ public class ProductController {
} }
}); });
refreshTimer = new Timeline(new KeyFrame(Duration.seconds(30), e -> applyFilters()));
refreshTimer.setCycleCount(Timeline.INDEFINITE);
refreshTimer.play();
tvProducts.sceneProperty().addListener((obs, oldScene, newScene) -> {
if (newScene == null && refreshTimer != null) {
refreshTimer.stop();
}
});
} }
/** /**