package de.thdeg.grademanager.gui; import de.thdeg.grademanager.model.CoursesOfStudy; import de.thdeg.grademanager.model.enumeration.BachelorDegree; import de.thdeg.grademanager.model.enumeration.BachelorSemester; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; import javafx.scene.Node; import javafx.scene.Scene; import javafx.scene.control.*; import javafx.stage.Stage; import java.io.IOException; import java.util.Optional; public class CoursesOfStudyModificationController { @FXML protected ComboBox<BachelorDegree> bachelorDegreeComboBox; @FXML protected ComboBox<BachelorSemester> durationComboBox; ObservableList<BachelorDegree> bachelorDegreeList = FXCollections.observableArrayList(BachelorDegree.values()); ObservableList<BachelorSemester> durationList = FXCollections.observableArrayList(BachelorSemester.values()); @FXML protected void initialize() { bachelorDegreeComboBox.setItems(bachelorDegreeList); durationComboBox.setItems(durationList); } @FXML protected TextField name; @FXML protected BachelorDegree bachelorDegree; @FXML protected BachelorSemester duration; @FXML protected int fees; @FXML protected TextField courses; @FXML protected TextField fieldOfStudy; @FXML protected TextField warning; @FXML protected void onSaveButtonClick(ActionEvent event) throws IOException { if (!name.getText().isBlank() && bachelorDegreeComboBox.getValue() != null && durationComboBox.getValue() != null && !fieldOfStudy.getText().isBlank()) { bachelorDegree = bachelorDegreeComboBox.getValue(); duration = durationComboBox.getValue(); fees = 62; MainController.coursesOfStudyList.add(new CoursesOfStudy( MainController.coursesOfStudyList.size(), name.getText(), bachelorDegree, 2, fees, null, fieldOfStudy.getText())); SwitchWindowHelper.switchTo("Main", event); } else { warning.setText("Bitte alle Felder ausfüllen."); Alert alert = new Alert(Alert.AlertType.ERROR); alert.setTitle("Fehler"); alert.setHeaderText("Bitte alle Felder ausfüllen."); Optional<ButtonType> result = alert.showAndWait(); } } @FXML protected void abortAndSwitchToMain(ActionEvent event) throws IOException { Alert alert = new Alert(Alert.AlertType.CONFIRMATION); alert.setTitle("Bestätigung erforderlich"); alert.setHeaderText("Daten wurden nicht gespeichert. Änderungen verwerfen?"); ButtonType buttonTypeOne = new ButtonType("Ja"); ButtonType buttonTypeCancel = new ButtonType("Abbrechen", ButtonBar.ButtonData.CANCEL_CLOSE); alert.getButtonTypes().setAll(buttonTypeOne, buttonTypeCancel); Optional<ButtonType> result = alert.showAndWait(); if (result.get() == buttonTypeOne) { SwitchWindowHelper.switchTo("Main", event); } } @FXML protected void switchToCourseModification(ActionEvent event) throws IOException { SwitchWindowHelper.switchTo("Course Modification", event); } }