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.

107 lines
3.0 KiB

  1. package de.uniluebeck.mi.projmi6.controller;
  2. import de.uniluebeck.mi.projmi6.model.HL7Message;
  3. import de.uniluebeck.mi.projmi6.view.MessageIcon;
  4. import javafx.beans.property.SimpleListProperty;
  5. import javafx.collections.FXCollections;
  6. import javafx.fxml.FXML;
  7. import javafx.fxml.FXMLLoader;
  8. import javafx.scene.Parent;
  9. import javafx.scene.Scene;
  10. import javafx.scene.image.Image;
  11. import javafx.stage.Modality;
  12. import javafx.stage.Stage;
  13. import java.io.IOException;
  14. /**
  15. * This controller controlls the small message icon at the bottom of the application's main window.
  16. * @author Johannes
  17. */
  18. public class MessageController {
  19. /**
  20. * The superior controller
  21. */
  22. final MainController mainController;
  23. /**
  24. * The list of unread messages
  25. */
  26. private final SimpleListProperty<HL7Message> messages = new SimpleListProperty<>(FXCollections.observableArrayList());
  27. /**
  28. * The view that is mantained by this controller
  29. */
  30. @FXML
  31. private MessageIcon messageIcon;
  32. /**
  33. * Constructor
  34. * @param mainController The controller that creates this instance
  35. */
  36. public MessageController(MainController mainController) {
  37. this.mainController = mainController;
  38. }
  39. /**
  40. * FXMLLoaders initialize()-method
  41. */
  42. @FXML
  43. private void initialize() {
  44. messageIcon.messageCountProperty().bind(messages.sizeProperty());
  45. }
  46. /**
  47. * EventHandler for the {@link #messageIcon}.
  48. */
  49. @FXML
  50. private void onMessageIconClicked() {
  51. showMessageList();
  52. }
  53. /**
  54. * Opens a window that shows all the unread messages.
  55. * @see de.uniluebeck.mi.projmi6.controller.MessageListController
  56. */
  57. private void showMessageList() {
  58. //Load the window content from FXML
  59. FXMLLoader fxmlLoader = new FXMLLoader();
  60. fxmlLoader.setLocation(getClass().getClassLoader().getResource("message_list.fxml"));
  61. //Non-empty constructor of the controller class
  62. MessageListController messageListController = new MessageListController(messages, mainController);
  63. fxmlLoader.setControllerFactory(clazz -> messageListController);
  64. Parent root = null;
  65. try {
  66. root = fxmlLoader.load();
  67. } catch (IOException e) {
  68. e.printStackTrace();
  69. return;
  70. }
  71. //Create stage and open window.
  72. Stage stage = new Stage();
  73. stage.setTitle("Neue HL7-Nachrichten");
  74. stage.setScene(new Scene(root, 600, 400));
  75. stage.getIcons().add(new Image("icon.png"));
  76. stage.initModality(Modality.WINDOW_MODAL);
  77. stage.initOwner(messageIcon.getScene().getWindow());
  78. stage.show();
  79. }
  80. /**
  81. * Adds a message to the list of unread messages that is controlled by this controller
  82. * @param message The message that will be added.
  83. */
  84. public void addMessage(HL7Message message) {
  85. messages.add(message);
  86. mainController.getLogController().refreshLogFromDb();
  87. }
  88. }