From dbe8b93e0c2774ad05871a1a3523b80a635a6300 Mon Sep 17 00:00:00 2001 From: Johannes Oehm Date: Thu, 19 Nov 2015 10:27:41 +0100 Subject: [PATCH] =?UTF-8?q?Patient=20Stations=C3=BCbersicht=20wird=20async?= =?UTF-8?q?hron=20geladen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/PatientTablesController.java | 81 +++++++++++++++++++--- src/main/resources/patient_tables.fxml | 2 + 2 files changed, 75 insertions(+), 8 deletions(-) diff --git a/src/main/java/de/uniluebeck/mi/projmi6/controller/PatientTablesController.java b/src/main/java/de/uniluebeck/mi/projmi6/controller/PatientTablesController.java index 20b752e..2fa7e79 100644 --- a/src/main/java/de/uniluebeck/mi/projmi6/controller/PatientTablesController.java +++ b/src/main/java/de/uniluebeck/mi/projmi6/controller/PatientTablesController.java @@ -146,7 +146,7 @@ public class PatientTablesController { return tableRow; }); lblTablePatientEmpty.setText("Liste ist leer."); - lblTableStationEmpty.setText("Daten werden geladen..."); + lblTableStationEmpty.setText(""); cmbStationenFilter.itemsProperty().bind(mainController.getStammdaten().stationenProperty()); @@ -198,13 +198,7 @@ public class PatientTablesController { cmbStationenFilter.valueProperty().addListener((observableValue, oldValue, newValue) -> { - try { - List uebersichtsItems = DBHandler.getStationsUebersichtsItems(newValue.getStation()); - stationsUebersicht.setAll(uebersichtsItems); - System.out.println(uebersichtsItems); - } catch (SQLException e) { - e.printStackTrace(); - } + updateStationsHistorieFromDb(); }); tblStationOverview.itemsProperty().bind(Bindings.createObjectBinding(() -> { if (btnEntlassenePatientenZeigen.isSelected()) { @@ -304,6 +298,77 @@ public class PatientTablesController { } + @FXML + Button btnStatRefresh; + + @FXML + private void clickedRefreshStation(){ + updateStationsHistorieFromDb(); + } + + private Task loadStationsHistorieTask = null; + + public void updateStationsHistorieFromDb() { + if (this.loadStationsHistorieTask != null && this.loadStationsHistorieTask.isRunning()) { + loadStationsHistorieTask.cancel(); + return; + } + + btnStatRefresh.setDisable(true); + + stationsUebersicht.clear(); + + mainController.increaseParallelTaskCount(); + + lblTableStationEmpty.setText("Liste wird geladen..."); + + Task> loadStatHist = new Task>() { + + @Override + protected List call() throws Exception { + return FXCollections.observableArrayList( + DBHandler.getStationsUebersichtsItems(cmbStationenFilter.getValue().getStation())); + } + + @Override + protected void succeeded() { + super.succeeded(); + if(!isCancelled()) { + lblTableStationEmpty.setText("Liste ist leer."); + stationsUebersicht.setAll(this.getValue()); + btnStatRefresh.setDisable(false); + mainController.decreaseParallelTaskCount(); + } + } + + @Override + protected void cancelled() { + super.cancelled(); + btnStatRefresh.setDisable(false); + mainController.decreaseParallelTaskCount(); + System.out.println("Cancelled"); + } + + @Override + protected void failed() { + super.failed(); + if(!isCancelled()){ + lblTablePatientEmpty.setText("Laden fehlgeschlagen!"); + getException().printStackTrace(); + } + mainController.decreaseParallelTaskCount(); + btnStatRefresh.setDisable(false); + } + }; + this.loadStationsHistorieTask = loadStatHist; + + Thread thread = new Thread(loadStationsHistorieTask); + thread.setDaemon(true); + thread.start(); + } + + + private Task loadPatientTask = null; @FXML diff --git a/src/main/resources/patient_tables.fxml b/src/main/resources/patient_tables.fxml index e1aad8f..d31a6a7 100644 --- a/src/main/resources/patient_tables.fxml +++ b/src/main/resources/patient_tables.fxml @@ -61,6 +61,8 @@