diff --git a/db/nursingHome.db b/db/nursingHome.db index b89b146..9ce1178 100644 Binary files a/db/nursingHome.db and b/db/nursingHome.db differ diff --git a/src/main/java/de/hitec/nhplus/medication/AllMedicationController.java b/src/main/java/de/hitec/nhplus/medication/AllMedicationController.java index 5e57089..769a787 100644 --- a/src/main/java/de/hitec/nhplus/medication/AllMedicationController.java +++ b/src/main/java/de/hitec/nhplus/medication/AllMedicationController.java @@ -7,6 +7,8 @@ import java.util.stream.Collectors; import de.hitec.nhplus.Main; import de.hitec.nhplus.datastorage.DaoFactory; +import de.hitec.nhplus.login.Permissions; +import de.hitec.nhplus.main.MainWindowController; import de.hitec.nhplus.medication.database.MedicationDao; import de.hitec.nhplus.nurse.Nurse; import de.hitec.nhplus.patient.Patient; @@ -15,6 +17,7 @@ import de.hitec.nhplus.treatment.TreatmentModalController; import javafx.beans.property.SimpleStringProperty; import javafx.collections.FXCollections; import javafx.collections.ObservableList; +import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; import javafx.scene.Scene; @@ -51,15 +54,23 @@ public class AllMedicationController { private TableColumn columnCurrentStock; @FXML public Button buttonChangeAvailable; + @FXML + public Button buttonAdd; + @FXML + public Button buttonDelete; private final ObservableList medications = FXCollections.observableArrayList(); private MedicationDao dao; + private boolean hasEditPermissions; /** * Initialization method that is called after the binding of all the fields. */ @FXML public void initialize() { + int editPermissions = Permissions.MANAGEMENT | Permissions.OWNER; + int userPermissions = MainWindowController.getInstance().getUser().getPermissions(); + hasEditPermissions = (userPermissions & editPermissions) != 0; this.readAllAndShowInTableView(); this.columnId.setCellValueFactory(new PropertyValueFactory<>("id")); @@ -86,6 +97,12 @@ public class AllMedicationController { this.tableView.setItems(this.medications); + if (!hasEditPermissions) { + this.buttonAdd.setDisable(true); + this.buttonDelete.setDisable(true); + this.buttonChangeAvailable.setDisable(true); + } + } /** @@ -140,6 +157,22 @@ public class AllMedicationController { this.readAllAndShowInTableView(); } + + @FXML + public void handleDelete() { + Medication selectedItem = this.tableView.getSelectionModel().getSelectedItem(); + if (selectedItem == null) { + return; + } + + try { + this.dao.delete(selectedItem.getId()); + } catch (SQLException exception) { + exception.printStackTrace(); + } + this.readAllAndShowInTableView(); + } + /** * Internal method to create a {@link MedicationModalController MedicationModal}. * @@ -184,4 +217,5 @@ public class AllMedicationController { } }); } + } diff --git a/src/main/java/de/hitec/nhplus/medication/DeprecatedMedicationController.java b/src/main/java/de/hitec/nhplus/medication/DeprecatedMedicationController.java index 8d36f59..03d5947 100644 --- a/src/main/java/de/hitec/nhplus/medication/DeprecatedMedicationController.java +++ b/src/main/java/de/hitec/nhplus/medication/DeprecatedMedicationController.java @@ -15,6 +15,12 @@ import java.sql.SQLException; import java.util.List; import java.util.stream.Collectors; +/** + * The controller for viewing all deprecated {@link Medication}s. + * + * @author Armin Ribic + * @author Dorian Nemec + */ public class DeprecatedMedicationController { @FXML private TableView tableView; @@ -38,6 +44,9 @@ public class DeprecatedMedicationController { private final ObservableList medications = FXCollections.observableArrayList(); private MedicationDao dao; + /** + * Initialization method that is called after the binding of all the fields. + */ public void initialize() { this.readAllAndShowInTableView(); @@ -79,8 +88,9 @@ public class DeprecatedMedicationController { exception.printStackTrace(); } } + @FXML - public void handleChangeAvailable(){ + public void handleChangeAvailable() { Medication selectedItem = tableView.getSelectionModel().getSelectedItem(); if (selectedItem == null) { return; diff --git a/src/main/resources/de/hitec/nhplus/medication/AllMedicationView.fxml b/src/main/resources/de/hitec/nhplus/medication/AllMedicationView.fxml index d9456b9..63407cc 100644 --- a/src/main/resources/de/hitec/nhplus/medication/AllMedicationView.fxml +++ b/src/main/resources/de/hitec/nhplus/medication/AllMedicationView.fxml @@ -73,6 +73,7 @@ fx:id="buttonDelete" mnemonicParsing="false" prefWidth="90.0" + onAction="#handleDelete" text="Löschen" />