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