Im Rahmen der Veranstaltung "CS3330 - Projektpraktikum MedizinischeInformatik" an der Universität zu Lübeck entstandenes Krankenhausinformationssystem (KIS).
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

132 lines
3.8 KiB

  1. package de.uniluebeck.mi.projmi6.controller;
  2. import de.uniluebeck.mi.projmi6.db.DBHandler;
  3. import de.uniluebeck.mi.projmi6.model.HL7LogEntry;
  4. import javafx.collections.FXCollections;
  5. import javafx.concurrent.Task;
  6. import javafx.fxml.FXML;
  7. import javafx.scene.control.*;
  8. import javafx.scene.control.cell.PropertyValueFactory;
  9. import javafx.scene.text.Text;
  10. import java.time.LocalDateTime;
  11. import java.util.List;
  12. /**
  13. * Created by 631806 on 19.11.15.
  14. */
  15. public class LogController {
  16. final MainController mainController;
  17. @FXML
  18. TableView<HL7LogEntry> tblLog;
  19. @FXML
  20. TableColumn<HL7LogEntry, String> colLogIp, colLogMessage;
  21. @FXML
  22. TableColumn<HL7LogEntry, LocalDateTime> colLogTime;
  23. @FXML
  24. TableColumn<HL7LogEntry, HL7LogEntry.Direction> colLogDirection;
  25. @FXML
  26. Button btnRefresh;
  27. private Task<List<HL7LogEntry>> loadLogEntryTask = null;
  28. public LogController(MainController mainController) {
  29. this.mainController = mainController;
  30. }
  31. @FXML
  32. private void initialize() {
  33. initColumns();
  34. refreshLogFromDb();
  35. }
  36. private void initColumns() {
  37. colLogDirection.setCellValueFactory(new PropertyValueFactory<HL7LogEntry, HL7LogEntry.Direction>("direction"));
  38. colLogIp.setCellValueFactory(new PropertyValueFactory<HL7LogEntry, String>("source"));
  39. colLogTime.setCellValueFactory(new PropertyValueFactory<HL7LogEntry, LocalDateTime>("timestamp"));
  40. colLogMessage.setCellValueFactory(new PropertyValueFactory<HL7LogEntry, String>("message"));
  41. colLogMessage.setCellFactory(column -> {
  42. return new TableCell<HL7LogEntry, String>() {
  43. private TextArea textArea = new TextArea();
  44. {
  45. textArea.setEditable(false);
  46. textArea.setPrefRowCount(5);
  47. }
  48. @Override
  49. protected void updateItem(String item, boolean empty) {
  50. super.updateItem(item, empty);
  51. this.setText(null);
  52. if (item == null || empty) {
  53. this.setGraphic(null);
  54. return;
  55. }
  56. textArea.setText(item);
  57. textArea.setWrapText(true);
  58. this.setGraphic(textArea);
  59. }
  60. };
  61. });
  62. }
  63. public void refreshLogFromDb() {
  64. if (this.loadLogEntryTask != null && this.loadLogEntryTask.isRunning()) {
  65. return;
  66. }
  67. btnRefresh.setDisable(true);
  68. tblLog.setItems(null);
  69. mainController.increaseParallelTaskCount();
  70. tblLog.setPlaceholder(new Text("Liste wird geladen..."));
  71. loadLogEntryTask = new Task<List<HL7LogEntry>>() {
  72. @Override
  73. protected List<HL7LogEntry> call() throws Exception {
  74. return FXCollections.observableArrayList(DBHandler.getLastHL7LogEntries());
  75. }
  76. @Override
  77. protected void succeeded() {
  78. super.succeeded();
  79. tblLog.setPlaceholder(new Text("Liste ist leer."));
  80. tblLog.setItems(FXCollections.observableArrayList(this.getValue()));
  81. mainController.decreaseParallelTaskCount();
  82. btnRefresh.setDisable(false);
  83. }
  84. @Override
  85. protected void failed() {
  86. super.failed();
  87. tblLog.setPlaceholder(new Text("Laden fehlgeschlagen"));
  88. mainController.decreaseParallelTaskCount();
  89. tblLog.setItems(null);
  90. getException().printStackTrace();
  91. }
  92. };
  93. Thread thread = new Thread(loadLogEntryTask);
  94. thread.setDaemon(true);
  95. thread.start();
  96. }
  97. @FXML
  98. private void clickedRefresh() {
  99. refreshLogFromDb();
  100. }
  101. }