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