diff --git a/src/main/java/de/hitec/nhplus/treatment/AllTreatmentController.java b/src/main/java/de/hitec/nhplus/treatment/AllTreatmentController.java index 854c155..117b380 100644 --- a/src/main/java/de/hitec/nhplus/treatment/AllTreatmentController.java +++ b/src/main/java/de/hitec/nhplus/treatment/AllTreatmentController.java @@ -186,32 +186,43 @@ public class AllTreatmentController { @FXML public void handleNewTreatment() { - try { - String selectedPatient = this.comboBoxPatientSelection.getSelectionModel().getSelectedItem(); - Patient patient = searchInPatientList(selectedPatient); + String selectedPatient = this.comboBoxPatientSelection.getSelectionModel().getSelectedItem(); + Patient patient = searchInPatientList(selectedPatient); - String selectedNurse = this.comboBoxNurseSelection.getSelectionModel().getSelectedItem(); - Nurse nurse = searchInNurseList(selectedNurse); - - newTreatmentWindow(patient, nurse); - } catch (NullPointerException exception) { + if(patient == null) { Alert alert = new Alert(Alert.AlertType.INFORMATION); alert.setTitle("Information"); alert.setHeaderText("Patient für die Behandlung fehlt!"); alert.setContentText("Wählen Sie über die Combobox einen Patienten aus!"); alert.showAndWait(); + return; } + + String selectedNurse = this.comboBoxNurseSelection.getSelectionModel().getSelectedItem(); + Nurse nurse = searchInNurseList(selectedNurse); + + if(nurse == null) { + Alert alert = new Alert(Alert.AlertType.INFORMATION); + alert.setTitle("Information"); + alert.setHeaderText("Pfleger für die Behandlung fehlt!"); + alert.setContentText("Wählen Sie über die Combobox einen Pfleger aus!"); + alert.showAndWait(); + return; + } + + newTreatmentWindow(patient, nurse); } @FXML public void handleMouseClick() { tableView.setOnMouseClicked(event -> { - if (event.getClickCount() == 2 && (tableView.getSelectionModel().getSelectedItem() != null)) { - int index = this.tableView.getSelectionModel().getSelectedIndex(); - Treatment treatment = this.treatments.get(index); - treatmentWindow(treatment, treatment.getNurse()); + if (event.getClickCount() != 2 || (tableView.getSelectionModel().getSelectedItem() == null)) { + return; } + int index = this.tableView.getSelectionModel().getSelectedIndex(); + Treatment treatment = this.treatments.get(index); + treatmentWindow(treatment, treatment.getNurse()); }); }