aboutsummaryrefslogtreecommitdiff
path: root/src/com.example.portfolio2/com/example/portfolio2/Controller.java
blob: 036236f0d62445433e84a73e2ad538c0731f4914 (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 box is selected
  29. ///
  30. /// @param combo involved activity box
  31. /// @param select selected item
  32. /// @param area whole text area
  33. void onComboSelected(final ComboBox<String> combo, final ComboBox<String> select, final TextArea area) {
  34. // clear the activity selection box
  35. select.getItems().clear();
  36. // clear text area
  37. area.clear();
  38. // fill activity box from data in store
  39. select.getItems().addAll(store.selectProgram(combo.getValue()));
  40. }
  41. /// callback when activity box is selected
  42. ///
  43. /// @param combo involved activity box
  44. /// @param select selected item
  45. /// @param area whole text area
  46. void onActivitySelected(final ComboBox<String> combo, final ComboBox<String> select, final TextArea area) {
  47. // pass the value chosen in the box
  48. addActivity(select.getValue(), area);
  49. // update text area based on category choice
  50. //
  51. // users can choose from the ComboBox, string (activity) and the area would update.
  52. updateArea(combo, area);
  53. }
  54. /// callback when subject module box is selected
  55. ///
  56. /// @param subject1 involved 1st column subject module box
  57. /// @param subject2 involved 2nd column subject module box
  58. /// @param subjectModules list of selected subject modules
  59. void onSubjectModuleSelected(final ComboBox<String> subject1, final ComboBox<String> subject2, final List<String> subjectModules) {
  60. // Beautiful loop we've created to remove option chosen in one subject module box from the other
  61. for (String sub: subjectModules) {
  62. if (sub.equals(subject1.getValue())) {
  63. subject2.getItems().remove(subject1.getValue());
  64. } else if (!sub.equals(subject1.getValue()) && !subject2.getItems().contains(sub)) {
  65. subject2.getItems().add(sub);
  66. }
  67. }
  68. }
  69. /// add participation to database
  70. /// @param s activity identifier
  71. /// @param textArea whole text area
  72. void addActivity(final String s, final TextArea textArea) {
  73. store.addParticipation(store.getActivityIndeks(s));
  74. }
  75. /// update text area for an activity box
  76. ///
  77. /// Clears the text area
  78. /// and adds all activity names from activities in participation.
  79. ///
  80. /// @param combo involved activity box
  81. /// @param textArea whole text area
  82. void updateArea(final ComboBox<String> combo, final TextArea textArea) {
  83. textArea.clear();
  84. for (String s: store.getParticipation(combo.getValue())) {
  85. textArea.appendText(s + "\n");
  86. }
  87. }
  88. /// update label with current ECTS of program type
  89. /// @param ectslabel text display area for ECTS points
  90. /// @param comboBox involved activity box
  91. void updateEcts(final Label ectslabel, final ComboBox<String> comboBox) {
  92. ectslabel.setText("ECTS: " + store.getSumEcts(comboBox.getValue()));
  93. }
  94. void fillElective(final ComboBox<String> electiveBox) {
  95. electiveBox.getItems().addAll(store.getAllActivities());
  96. }
  97. }