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