-
Kevin Thaller authoredKevin Thaller authored
CourseModificationController.java 3.44 KiB
package de.thdeg.grademanager.gui;
import de.thdeg.grademanager.model.Course;
import de.thdeg.grademanager.model.enumeration.BachelorSemester;
import de.thdeg.grademanager.model.enumeration.CourseType;
import de.thdeg.grademanager.model.enumeration.ExamType;
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.Alert;
import javafx.scene.control.ButtonType;
import javafx.scene.control.ComboBox;
import javafx.scene.control.TextField;
import javafx.stage.Stage;
import java.io.IOException;
import java.util.Optional;
public class CourseModificationController {
@FXML
protected ComboBox<BachelorSemester> bachelorSemesterComboBox;
@FXML
protected ComboBox<CourseType> courseTypeComboBox;
@FXML
protected ComboBox<ExamType> examTypeComboBox;
ObservableList<BachelorSemester> bachelorSemesterList = FXCollections.observableArrayList(BachelorSemester.values());
ObservableList<CourseType> courseTypeList = FXCollections.observableArrayList(CourseType.values());
ObservableList<ExamType> examTypeList = FXCollections.observableArrayList(ExamType.values());
@FXML
protected void initialize() {
bachelorSemesterComboBox.setItems(bachelorSemesterList);
courseTypeComboBox.setItems(courseTypeList);
examTypeComboBox.setItems(examTypeList);
}
@FXML
protected TextField name;
@FXML
protected BachelorSemester bachelorSemester;
@FXML
protected CourseType courseType;
@FXML
protected TextField sws;
@FXML
protected TextField ects;
@FXML
protected ExamType examType;
@FXML
protected TextField warning;
@FXML
protected void onSaveButtonClick(ActionEvent event) throws IOException {
if (!name.getText().isBlank() && bachelorSemesterComboBox.getValue() != null &&
courseTypeComboBox.getValue() != null && !sws.getText().isBlank() && !ects.getText().isBlank() &&
examTypeComboBox.getValue() != null) {
bachelorSemester = bachelorSemesterComboBox.getValue();
courseType = courseTypeComboBox.getValue();
examType = examTypeComboBox.getValue();
Course k = new Course(1,
name.getText(),
bachelorSemester,
courseType,
Integer.parseInt(sws.getText()),
Integer.parseInt(ects.getText()),
examType);
switchToCoursesOfStudyModification(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();
}
}
private Stage stage;
private Scene scene;
private FXMLLoader root;
@FXML
protected void switchToCoursesOfStudyModification(ActionEvent event) throws IOException {
root = new FXMLLoader(Main.class.getResource("courses-of-study-modification.fxml"));
stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
scene = new Scene(root.load(), 960, 540);
stage.setTitle("CoursesOfStudy Modification");
stage.setScene(scene);
stage.show();
}
}