aboutsummaryrefslogtreecommitdiff
path: root/src/com.example.portfolio2/com/example/portfolio2/Controller.java
blob: 0df3cd4ff73e2ca9b412a94eca57468e3a618ced (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(final Database store, UI ui, final Window view) {
  28. this.store = store;
  29. this.ui = ui;
  30. this.view = view;
  31. }
  32. /// callback when category has been selected
  33. ///
  34. /// @param section section the category is tied to
  35. /// @param category selected category
  36. // TODO: require a UI instead
  37. void onCategorySelected(
  38. final GUI.Section section,
  39. final String category
  40. ) {
  41. view.clearSelections(section);
  42. view.setOptions(section,store.selectProgram(category));
  43. }
  44. /// callback when activity has been selected
  45. ///
  46. /// @param combo involved activity box
  47. /// @param select selected item
  48. /// @param area whole text area
  49. void onActivitySelected(
  50. final ComboBox<String> combo,
  51. final ComboBox<String> select,
  52. final TextArea area
  53. ) {
  54. // pass the value chosen in the box
  55. addActivity(select.getValue(), area);
  56. // update text area based on category choice
  57. //
  58. // Users can choose from the ComboBox,
  59. // and string (activity) and the area will then update.
  60. updateArea(combo, area);
  61. }
  62. /// callback when subject module has been selected
  63. ///
  64. /// @param subject1 involved 1st column subject module box
  65. /// @param subject2 involved 2nd column subject module box
  66. void onSubjectModuleSelected(
  67. final ComboBox<String> subject1,
  68. final ComboBox<String> subject2
  69. ) {
  70. // remove chosen option from opposite subject module box
  71. for (String sub: store.getAllSubjects()) {
  72. if (sub.equals(subject1.getValue())) {
  73. subject2.getItems().remove(
  74. subject1.getValue());
  75. } else if (
  76. !sub.equals(subject1.getValue())
  77. && !subject2.getItems().contains(sub)
  78. ) {
  79. subject2.getItems().add(sub);
  80. }
  81. }
  82. }
  83. /// add participation to database
  84. /// @param s activity identifier
  85. /// @param textArea whole text area
  86. void addActivity(final String s, final TextArea textArea) {
  87. store.addParticipation(store.getActivityIndeks(s));
  88. }
  89. /// update text area for an activity box
  90. ///
  91. /// Clears the text area
  92. /// and adds all activity names from activities in participation.
  93. ///
  94. /// @param combo involved activity box
  95. /// @param textArea whole text area
  96. void updateArea(
  97. final ComboBox<String> combo, final TextArea textArea
  98. ) {
  99. textArea.clear();
  100. for (String s: store.getParticipation(combo.getValue())
  101. ) {
  102. textArea.appendText(s + "\n");
  103. }
  104. }
  105. /// update label with current ECTS of program type
  106. /// @param ectslabel text display area for ECTS points
  107. /// @param comboBox involved activity box
  108. void updateEcts(
  109. final Label ectslabel, final ComboBox<String> comboBox
  110. ) {
  111. ectslabel.setText("ECTS: "
  112. + store.getSumEcts(comboBox.getValue()));
  113. }
  114. void fillElective(final ComboBox<String> electiveBox) {
  115. electiveBox.getItems().addAll(store.getAllActivities());
  116. }
  117. }