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