delayed refresh after CRUD
This commit is contained in:
@@ -11,6 +11,7 @@ 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.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;
|
||||||
@@ -83,7 +84,6 @@ public class ProductController {
|
|||||||
//data declaration
|
//data declaration
|
||||||
private ObservableList<ProductDTO> data = FXCollections.observableArrayList();
|
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
|
||||||
@@ -134,14 +134,6 @@ 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();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -236,8 +228,7 @@ public class ProductController {
|
|||||||
alert.showAndWait();
|
alert.showAndWait();
|
||||||
}
|
}
|
||||||
|
|
||||||
//refresh display and reset inputs
|
displayProductWithFollowUp();
|
||||||
displayProduct();
|
|
||||||
btnDelete.setDisable(true);
|
btnDelete.setDisable(true);
|
||||||
btnEdit.setDisable(true);
|
btnEdit.setDisable(true);
|
||||||
txtSearch.setText("");
|
txtSearch.setText("");
|
||||||
@@ -263,6 +254,11 @@ public class ProductController {
|
|||||||
* Filter the table given the string from the searchbar
|
* Filter the table given the string from the searchbar
|
||||||
* @param filter word to filter table
|
* @param filter word to filter table
|
||||||
*/
|
*/
|
||||||
|
private void displayProductWithFollowUp() {
|
||||||
|
displayProduct();
|
||||||
|
new Timeline(new KeyFrame(Duration.seconds(2), e -> applyFilters())).play();
|
||||||
|
}
|
||||||
|
|
||||||
private void displayFilteredProduct(String filter){
|
private void displayFilteredProduct(String filter){
|
||||||
if ((txtSearch.getText() == null || txtSearch.getText().isEmpty()) && selectedCategoryId() == null){
|
if ((txtSearch.getText() == null || txtSearch.getText().isEmpty()) && selectedCategoryId() == null){
|
||||||
displayProduct();
|
displayProduct();
|
||||||
@@ -360,8 +356,7 @@ public class ProductController {
|
|||||||
dialogStage.setScene(scene);
|
dialogStage.setScene(scene);
|
||||||
dialogStage.showAndWait();
|
dialogStage.showAndWait();
|
||||||
|
|
||||||
//When dialog closes update table view and disable edit and delete buttons, and reset search bar
|
displayProductWithFollowUp();
|
||||||
displayProduct();
|
|
||||||
btnDelete.setDisable(true);
|
btnDelete.setDisable(true);
|
||||||
btnEdit.setDisable(true);
|
btnEdit.setDisable(true);
|
||||||
txtSearch.setText("");
|
txtSearch.setText("");
|
||||||
|
|||||||
Reference in New Issue
Block a user