aboutsummaryrefslogtreecommitdiff
path: root/src/dk.biks.bachelorizer/dk/biks/bachelorizer/Controller.java
blob: 63eac9d3a485ce97423ab7bf2184b4310dcede8e (plain)
  1. // SPDX-FileCopyrightText: 2025 <Alexander Marthin Klemensen stud-marthin@ruc.dk>
  2. // SPDX-FileCopyrightText: 2025 <Ian Valentin Christensen stud-ianc@ruc.dk>
  3. // SPDX-FileCopyrightText: 2025 Jonas Smedegaard <dr@jones.dk>
  4. // SPDX-FileCopyrightText: 2025 <Zahed Noos zahed@ruc.dk>
  5. // SPDX-License-Identifier: GPL-3.0-or-later
  6. package dk.biks.bachelorizer;
  7. import java.util.List;
  8. import javafx.scene.control.ComboBox;
  9. import javafx.scene.control.Label;
  10. import javafx.scene.control.TextArea;
  11. /// Bachelorizer - Controller
  12. class Controller {
  13. /// Storage model
  14. private Database store;
  15. /// UI model
  16. private UI ui;
  17. /// Application view
  18. private Window view;
  19. /// Parameters passed on command-line and in JNLP file
  20. private List<String> parameters;
  21. /// clear the participation database at program launch
  22. void initialize() {
  23. store.initialize();
  24. }
  25. /// default constructor
  26. ///
  27. /// @param store Storage model
  28. /// @param ui UI model
  29. /// @param view Application view
  30. Controller(
  31. final Database store, final UI ui, final Window view
  32. ) {
  33. this.store = store;
  34. this.ui = ui;
  35. this.view = view;
  36. }
  37. /// parse application parameters
  38. ///
  39. /// Parse parameters as GNU-style options and arguments,
  40. /// i.e. treat dash-prefixed words as options
  41. /// until an optional first bare "--",
  42. /// taking first non-option argument as name of student
  43. /// and remaining ones as activity selections.
  44. ///
  45. /// @param parameters Application parameters
  46. public final void setParameters(final List<String> parameters) {
  47. boolean optionsDone = false;
  48. boolean studentAssigned = false;
  49. /* TODO
  50. for (String item: parameters) {
  51. if (!optionsDone && item.matches("--")) {
  52. optionsDone = true;
  53. } else if (!item.startsWith("-")) {
  54. if (!studentAssigned) {
  55. store.addStudent(item);
  56. studentAssigned = true;
  57. // TODO ui.showStudent(
  58. // model.getStudentName());
  59. } else {
  60. store.addParticipation(
  61. store.getActivityIndeks(item));
  62. // TODO ui.showActivities();
  63. }
  64. }
  65. }
  66. */
  67. }
  68. /// callback when category has been selected
  69. ///
  70. /// @param section section the category is tied to
  71. /// @param category selected category
  72. // TODO: require a UI instead
  73. void onCategorySelected(
  74. final GUI.Section section,
  75. final String category
  76. ) {
  77. view.clearSelections(section);
  78. view.setOptions(section, store.selectProgram(category));
  79. }
  80. /// callback when activity has been selected
  81. ///
  82. /// @param combo involved activity box
  83. /// @param select selected item
  84. /// @param area whole text area
  85. void onActivitySelected(
  86. final ComboBox<String> combo,
  87. final ComboBox<String> select,
  88. final TextArea area
  89. ) {
  90. // pass the value chosen in the box
  91. addActivity(select.getValue(), area);
  92. // update text area based on category choice
  93. //
  94. // Users can choose from the ComboBox,
  95. // and string (activity) and the area will then update.
  96. updateArea(combo, area);
  97. }
  98. /// callback when subject module has been selected
  99. ///
  100. /// @param subject1 involved 1st column subject module box
  101. /// @param subject2 involved 2nd column subject module box
  102. void onSubjectModuleSelected(
  103. final ComboBox<String> subject1,
  104. final ComboBox<String> subject2
  105. ) {
  106. // remove chosen option from opposite subject module box
  107. for (String sub: store.getAllSubjects()) {
  108. if (sub.equals(subject1.getValue())) {
  109. subject2.getItems().remove(
  110. subject1.getValue());
  111. } else if (
  112. !sub.equals(subject1.getValue())
  113. && !subject2.getItems().contains(sub)
  114. ) {
  115. subject2.getItems().add(sub);
  116. }
  117. }
  118. }
  119. /// add participation to database
  120. /// @param s activity identifier
  121. /// @param textArea whole text area
  122. void addActivity(final String s, final TextArea textArea) {
  123. store.addParticipation(store.getActivityIndeks(s));
  124. }
  125. /// update text area for an activity box
  126. ///
  127. /// Clears the text area
  128. /// and adds all activity names from activities in participation.
  129. ///
  130. /// @param combo involved activity box
  131. /// @param textArea whole text area
  132. void updateArea(
  133. final ComboBox<String> combo, final TextArea textArea
  134. ) {
  135. textArea.clear();
  136. for (String s: store.getParticipation(combo.getValue())
  137. ) {
  138. textArea.appendText(s + "\n");
  139. }
  140. }
  141. /// update label with current ECTS of program type
  142. /// @param ectslabel text display area for ECTS points
  143. /// @param comboBox involved activity box
  144. void updateEcts(
  145. final Label ectslabel, final ComboBox<String> comboBox
  146. ) {
  147. ectslabel.setText("ECTS: "
  148. + store.getSumEcts(comboBox.getValue()));
  149. }
  150. void fillElective(final ComboBox<String> electiveBox) {
  151. electiveBox.getItems().addAll(store.getAllActivities());
  152. }
  153. }