aboutsummaryrefslogtreecommitdiff
path: root/src/com.example.portfolio2/com/example/portfolio2/Controller.java
blob: 91236ea46b99150f06246d14b9996fc624b3addb (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. void onSubjectModuleSelected(
  70. final ComboBox<String> subject1,
  71. final ComboBox<String> subject2
  72. ) {
  73. // remove chosen option from opposite subject module box
  74. for (String sub: store.getAllModules()) {
  75. if (sub.equals(subject1.getValue())) {
  76. subject2.getItems().remove(
  77. subject1.getValue());
  78. } else if (
  79. !sub.equals(subject1.getValue())
  80. && !subject2.getItems().contains(sub)
  81. ) {
  82. subject2.getItems().add(sub);
  83. }
  84. }
  85. }
  86. /// add participation to database
  87. /// @param s activity identifier
  88. /// @param textArea whole text area
  89. void addActivity(final String s, final TextArea textArea) {
  90. store.addParticipation(store.getActivityIndeks(s));
  91. }
  92. /// update text area for an activity box
  93. ///
  94. /// Clears the text area
  95. /// and adds all activity names from activities in participation.
  96. ///
  97. /// @param combo involved activity box
  98. /// @param textArea whole text area
  99. void updateArea(
  100. final ComboBox<String> combo, final TextArea textArea
  101. ) {
  102. textArea.clear();
  103. for (String s: store.getParticipation(combo.getValue())
  104. ) {
  105. textArea.appendText(s + "\n");
  106. }
  107. }
  108. /// update label with current ECTS of program type
  109. /// @param ectslabel text display area for ECTS points
  110. /// @param comboBox involved activity box
  111. void updateEcts(
  112. final Label ectslabel, final ComboBox<String> comboBox
  113. ) {
  114. ectslabel.setText("ECTS: "
  115. + store.getSumEcts(comboBox.getValue()));
  116. }
  117. void fillElective(final ComboBox<String> electiveBox) {
  118. electiveBox.getItems().addAll(store.getAllActivities());
  119. }
  120. }