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