From d8a7c9a59cf3044b03de11c641634d8e311f31b6 Mon Sep 17 00:00:00 2001 From: arminribic Date: Tue, 14 May 2024 14:53:42 +0200 Subject: [PATCH] #10: Update Views to Reflect Locked and Active Nurses --- .../nhplus/main/MainWindowController.java | 58 +++++++++-- .../nhplus/nurse/AllNurseController.java | 20 +++- .../nhplus/nurse/LockedNurseController.java | 96 +++++++++++++++++++ .../de/hitec/nhplus/main/MainWindowView.fxml | 13 ++- .../de/hitec/nhplus/nurse/AllNurseView.fxml | 5 +- .../hitec/nhplus/nurse/LockedNurseView.fxml | 77 +++++++++++++++ 6 files changed, 255 insertions(+), 14 deletions(-) create mode 100644 src/main/java/de/hitec/nhplus/nurse/LockedNurseController.java create mode 100644 src/main/resources/de/hitec/nhplus/nurse/LockedNurseView.fxml diff --git a/src/main/java/de/hitec/nhplus/main/MainWindowController.java b/src/main/java/de/hitec/nhplus/main/MainWindowController.java index 6f0ee03..a085cb4 100644 --- a/src/main/java/de/hitec/nhplus/main/MainWindowController.java +++ b/src/main/java/de/hitec/nhplus/main/MainWindowController.java @@ -3,6 +3,7 @@ package de.hitec.nhplus.main; import de.hitec.nhplus.Main; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; +import javafx.scene.control.SelectionModel; import javafx.scene.control.Tab; import javafx.scene.control.TabPane; import javafx.scene.layout.AnchorPane; @@ -23,9 +24,17 @@ public class MainWindowController { @FXML private Tab treatmentTab; @FXML - private AnchorPane nursePage; - @FXML private Tab nurseTab; + @FXML + private TabPane nurseTabPane; + @FXML + private AnchorPane activeNursePage; + @FXML + private Tab activeNurseTab; + @FXML + private AnchorPane lockedNursePage; + @FXML + private Tab lockedNurseTab; @FXML public void initialize() { @@ -36,6 +45,11 @@ public class MainWindowController { treatmentTab.setOnSelectionChanged(event -> loadTreatmentsPage()); nurseTab.setOnSelectionChanged(event -> loadNursePage()); + + nurseTabPane.getSelectionModel().select(activeNurseTab); + + activeNurseTab.setOnSelectionChanged(event -> loadActiveNursePage()); + lockedNurseTab.setOnSelectionChanged(event -> loadLockedNursePage()); } private void loadPatientPage() { @@ -69,15 +83,43 @@ public class MainWindowController { } private void loadNursePage() { + SelectionModel selectionModel = nurseTabPane.getSelectionModel(); + Tab selectedTab = selectionModel.getSelectedItem(); + if(selectedTab == activeNurseTab){ + loadActiveNursePage(); + } + if(selectedTab == lockedNurseTab){ + loadLockedNursePage(); + } + } + + private void loadActiveNursePage() { + System.out.println("TODO: Active Nurse"); try { - BorderPane nursePane = FXMLLoader.load( + BorderPane activeNursePane = FXMLLoader.load( Objects.requireNonNull(Main.class.getResource("/de/hitec/nhplus/nurse/AllNurseView.fxml")) ); - nursePage.getChildren().setAll(nursePane); - AnchorPane.setTopAnchor(nursePane, 0d); - AnchorPane.setBottomAnchor(nursePane, 0d); - AnchorPane.setLeftAnchor(nursePane, 0d); - AnchorPane.setRightAnchor(nursePane, 0d); + activeNursePage.getChildren().setAll(activeNursePane); + AnchorPane.setTopAnchor(activeNursePane, 0d); + AnchorPane.setBottomAnchor(activeNursePane, 0d); + AnchorPane.setLeftAnchor(activeNursePane, 0d); + AnchorPane.setRightAnchor(activeNursePane, 0d); + } catch (IOException exception) { + exception.printStackTrace(); + } + } + + private void loadLockedNursePage() { + System.out.println("TODO: Locked Nurse"); + try { + BorderPane lockedNursePane = FXMLLoader.load( + Objects.requireNonNull(Main.class.getResource("/de/hitec/nhplus/nurse/LockedNurseView.fxml")) + ); + lockedNursePage.getChildren().setAll(lockedNursePane); + AnchorPane.setTopAnchor(lockedNursePane, 0d); + AnchorPane.setBottomAnchor(lockedNursePane, 0d); + AnchorPane.setLeftAnchor(lockedNursePane, 0d); + AnchorPane.setRightAnchor(lockedNursePane, 0d); } catch (IOException exception) { exception.printStackTrace(); } diff --git a/src/main/java/de/hitec/nhplus/nurse/AllNurseController.java b/src/main/java/de/hitec/nhplus/nurse/AllNurseController.java index 7f69645..33f1c9c 100644 --- a/src/main/java/de/hitec/nhplus/nurse/AllNurseController.java +++ b/src/main/java/de/hitec/nhplus/nurse/AllNurseController.java @@ -27,6 +27,8 @@ public class AllNurseController { @FXML public Button buttonAdd; @FXML + public Button buttonLock; + @FXML private TableView tableView; @FXML private TableColumn columnId; @@ -76,7 +78,7 @@ public class AllNurseController { this.nurses.clear(); this.dao = DaoFactory.getInstance().createNurseDAO(); try { - this.nurses.addAll(this.dao.readAll()); + this.nurses.addAll(this.dao.readAllActive()); }catch (SQLException exception){ exception.printStackTrace(); } @@ -95,6 +97,21 @@ public class AllNurseController { readAllAndShowInTableView(); clearTextfields(); } + @FXML + public void handleLock(){ + Nurse selectedItem = this.tableView.getSelectionModel().getSelectedItem(); + if (selectedItem == null){ + return; + } + + try { + selectedItem.setLocked(true); + this.dao.update(selectedItem); + }catch (SQLException exception){ + exception.printStackTrace(); + } + readAllAndShowInTableView(); + } private void clearTextfields() { this.textFieldFirstName.clear(); @@ -102,4 +119,5 @@ public class AllNurseController { this.textFieldPhoneNumber.clear(); } + } diff --git a/src/main/java/de/hitec/nhplus/nurse/LockedNurseController.java b/src/main/java/de/hitec/nhplus/nurse/LockedNurseController.java new file mode 100644 index 0000000..ecf3626 --- /dev/null +++ b/src/main/java/de/hitec/nhplus/nurse/LockedNurseController.java @@ -0,0 +1,96 @@ +package de.hitec.nhplus.nurse; + +import de.hitec.nhplus.datastorage.DaoFactory; +import de.hitec.nhplus.nurse.database.NurseDao; +import javafx.application.Application; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import javafx.fxml.FXML; +import javafx.scene.control.Button; +import javafx.scene.control.Tab; +import javafx.scene.control.TableColumn; +import javafx.scene.control.TableView; +import javafx.scene.control.cell.PropertyValueFactory; +import javafx.scene.control.cell.TextFieldTableCell; +import javafx.scene.layout.AnchorPane; +import javafx.stage.Stage; + +import java.sql.SQLException; + +public class LockedNurseController { + @FXML + public Button buttonDelete; + @FXML + private Button buttonUnlock; + @FXML + public TableView tableView; + @FXML + public TableColumn columnId; + @FXML + public TableColumn columnFirstName; + @FXML + public TableColumn columnSurName; + @FXML + public TableColumn columnDeleteDate; + + private final ObservableList nurses = FXCollections.observableArrayList(); + private NurseDao dao; + + public void initialize() { + this.readAllAndShowInTableView(); + + this.columnId.setCellValueFactory(new PropertyValueFactory<>("id")); + + this.columnFirstName.setCellValueFactory(new PropertyValueFactory<>("firstName")); + this.columnFirstName.setCellFactory(TextFieldTableCell.forTableColumn()); + + this.columnSurName.setCellValueFactory(new PropertyValueFactory<>("surName")); + this.columnSurName.setCellFactory(TextFieldTableCell.forTableColumn()); + + this.columnDeleteDate.setCellValueFactory(new PropertyValueFactory<>("date")); + this.columnDeleteDate.setCellFactory(TextFieldTableCell.forTableColumn()); + + this.tableView.setItems(this.nurses); + } + + private void readAllAndShowInTableView() { + this.nurses.clear(); + this.dao = DaoFactory.getInstance().createNurseDAO(); + try { + this.nurses.addAll(this.dao.readAllLocked()); + } catch (SQLException exception) { + exception.printStackTrace(); + } + } + + @FXML + public void handleDelete() { + Nurse selectedItem = this.tableView.getSelectionModel().getSelectedItem(); + if (selectedItem == null) { + return; + } + try { + this.dao.delete(selectedItem.getId()); + } catch (SQLException exception) { + exception.printStackTrace(); + } + + } + + @FXML + public void changeUnlock() { + Nurse selectedItem = this.tableView.getSelectionModel().getSelectedItem(); + if (selectedItem == null) { + return; + } + + try { + selectedItem.setLocked(false); + this.dao.update(selectedItem); + } catch (SQLException exception) { + exception.printStackTrace(); + } + readAllAndShowInTableView(); + } + +} diff --git a/src/main/resources/de/hitec/nhplus/main/MainWindowView.fxml b/src/main/resources/de/hitec/nhplus/main/MainWindowView.fxml index 7d1697d..2257239 100644 --- a/src/main/resources/de/hitec/nhplus/main/MainWindowView.fxml +++ b/src/main/resources/de/hitec/nhplus/main/MainWindowView.fxml @@ -16,7 +16,14 @@ - - - + + + + + + + + + + diff --git a/src/main/resources/de/hitec/nhplus/nurse/AllNurseView.fxml b/src/main/resources/de/hitec/nhplus/nurse/AllNurseView.fxml index eec0384..664d6d7 100644 --- a/src/main/resources/de/hitec/nhplus/nurse/AllNurseView.fxml +++ b/src/main/resources/de/hitec/nhplus/nurse/AllNurseView.fxml @@ -77,10 +77,11 @@ text="Hinzufügen" />