aboutsummaryrefslogtreecommitdiff
path: root/src/com.example.portfolio2/com/example/portfolio2/Controller.java
blob: cf98c3cc0c587b7b4e094b6df5f6812e9f37317a (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. class Controller{
  11. private Model model;
  12. // We do this without using the view directly like this, instead passing options.
  13. private HelloApplication view;
  14. // calls on the database
  15. void initialize() {
  16. model.initialize();
  17. }
  18. Controller(Model model, HelloApplication view){
  19. this.model=model; this.view=view;
  20. }
  21. void onComboSelected(ComboBox<String> combo, ComboBox<String> select, TextArea area) {
  22. // Clear the activity selection box
  23. select.getItems().clear();
  24. area.clear(); // Clear text area
  25. // Fill activity box using model method
  26. select.getItems().addAll(model.selectProgram((String) combo.getValue()));
  27. }
  28. void onActivitySelected(ComboBox<String> combo, ComboBox<String> select, TextArea area) {
  29. // Passes the value chosen in the box
  30. addActivity((String) select.getValue(), area);
  31. // Updates the text area based on the category choice
  32. // users can choose from the ComboBox, string (activity) and the area would update.
  33. updateArea(combo, area);
  34. }
  35. void onSubjectModuleSelected(ComboBox<String> subject1, ComboBox<String> subject2, List<String> subjectModules) {
  36. // Beautiful loop we've created to remove option chosen in one subject module box from the other
  37. for (String sub : subjectModules) {
  38. if (sub.equals(subject1.getValue())) {
  39. subject2.getItems().remove(subject1.getValue());
  40. } else if (!sub.equals(subject1.getValue()) && !subject2.getItems().contains(sub)) {
  41. subject2.getItems().add(sub);
  42. }
  43. }
  44. }
  45. // Calls on model method to add participation in the database
  46. void addActivity(String s, TextArea textArea) {
  47. model.addParticipation(model.getActivityIndeks(s));
  48. }
  49. // Clears the text area and adds all activity names from activities in participation
  50. void updateArea(ComboBox combo, TextArea textArea) {
  51. textArea.clear();
  52. for(String s : model.getParticipation((String) combo.getValue())) {
  53. textArea.appendText(s + "\n");
  54. }
  55. }
  56. // Updates the labels with the current ECTS of the program type
  57. void updateEcts(Label ectslabel, ComboBox<String> comboBox) {
  58. ectslabel.setText("ECTS: "+model.getSumEcts(comboBox.getValue()));
  59. }
  60. void fillElective(ComboBox<String> electiveBox) {
  61. electiveBox.getItems().addAll(model.getAllActivities());
  62. }
  63. }