aboutsummaryrefslogtreecommitdiff
path: root/src/com.example.portfolio2/com/example/portfolio2/Controller.java
blob: 3d19efbccc3a7bb6182b6aa29412459675c410bb (plain)
  1. // SPDX-FileCopyrightText: 2025 Jonas Smedegaard <dr@jones.dk>
  2. // SPDX-FileCopyrightText: 2025 <Alexander Marthin Klemensen stud-marthin@ruc.dk>
  3. // SPDX-FileCopyrightText: 2025 <Ian Valentin Christensen stud-ianc@ruc.dk>
  4. // SPDX-FileCopyrightText: 2025 <Zahed Noos zahed@ruc.dk>
  5. // SPDX-License-Identifier: GPL-3.0-or-later
  6. package com.example.portfolio2;
  7. import javafx.scene.control.ComboBox;
  8. import javafx.scene.control.Label;
  9. import javafx.scene.control.TextArea;
  10. /// Bachelorizer - Controller
  11. class Controller {
  12. /// Storage model
  13. private Database store;
  14. /// UI model
  15. private UI ui;
  16. /// Application view
  17. private Window view;
  18. /// clear the participation database at program launch
  19. void initialize() {
  20. store.initialize();
  21. }
  22. /// default constructor
  23. ///
  24. /// @param store Storage model
  25. /// @param ui UI model
  26. /// @param view Application view
  27. Controller(
  28. final Database store, final UI ui, final Window view
  29. ) {
  30. this.store = store;
  31. this.ui = ui;
  32. this.view = view;
  33. }
  34. /// callback when category has been selected
  35. ///
  36. /// @param section section the category is tied to
  37. /// @param category selected category
  38. // TODO: require a UI instead
  39. void onCategorySelected(
  40. final GUI.Section section,
  41. final String category
  42. ) {
  43. view.clearSelections(section);
  44. view.setOptions(section, store.selectProgram(category));
  45. }
  46. /// callback when activity has been selected
  47. ///
  48. /// @param combo involved activity box
  49. /// @param select selected item
  50. /// @param area whole text area
  51. void onActivitySelected(
  52. final ComboBox<String> combo,
  53. final ComboBox<String> select,
  54. final TextArea area
  55. ) {
  56. // pass the value chosen in the box
  57. addActivity(select.getValue(), area);
  58. // update text area based on category choice
  59. //
  60. // Users can choose from the ComboBox,
  61. // and string (activity) and the area will then update.
  62. updateArea(combo, area);
  63. }
  64. /// callback when subject module has been selected
  65. ///
  66. /// @param subject1 involved 1st column subject module box
  67. /// @param subject2 involved 2nd column subject module box
  68. void onSubjectModuleSelected(
  69. final ComboBox<String> subject1,
  70. final ComboBox<String> subject2
  71. ) {
  72. // remove chosen option from opposite subject module box
  73. for (String sub: store.getAllSubjects()) {
  74. if (sub.equals(subject1.getValue())) {
  75. subject2.getItems().remove(
  76. subject1.getValue());
  77. } else if (
  78. !sub.equals(subject1.getValue())
  79. && !subject2.getItems().contains(sub)
  80. ) {
  81. subject2.getItems().add(sub);
  82. }
  83. }
  84. }
  85. /// add participation to database
  86. /// @param s activity identifier
  87. /// @param textArea whole text area
  88. void addActivity(final String s, final TextArea textArea) {
  89. store.addParticipation(store.getActivityIndeks(s));
  90. }
  91. /// update text area for an activity box
  92. ///
  93. /// Clears the text area
  94. /// and adds all activity names from activities in participation.
  95. ///
  96. /// @param combo involved activity box
  97. /// @param textArea whole text area
  98. void updateArea(
  99. final ComboBox<String> combo, final TextArea textArea
  100. ) {
  101. textArea.clear();
  102. for (String s: store.getParticipation(combo.getValue())
  103. ) {
  104. textArea.appendText(s + "\n");
  105. }
  106. }
  107. /// update label with current ECTS of program type
  108. /// @param ectslabel text display area for ECTS points
  109. /// @param comboBox involved activity box
  110. void updateEcts(
  111. final Label ectslabel, final ComboBox<String> comboBox
  112. ) {
  113. ectslabel.setText("ECTS: "
  114. + store.getSumEcts(comboBox.getValue()));
  115. }
  116. void fillElective(final ComboBox<String> electiveBox) {
  117. electiveBox.getItems().addAll(store.getAllActivities());
  118. }
  119. }