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