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