Skip to content
Snippets Groups Projects
Commit 1ff89f28 authored by Kevin Thaller's avatar Kevin Thaller
Browse files

introduction of SwitchWindowHelper to reduce lines of code and bug-fix in course-modification.fxml

parent eb64afd1
No related branches found
No related tags found
1 merge request!3jpa+gui+logic
......@@ -8,14 +8,10 @@ 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;
......@@ -71,10 +67,7 @@ public class CourseModificationController {
Integer.parseInt(sws.getText()),
Integer.parseInt(ects.getText()),
examType);
switchToCoursesOfStudyModification(event);
SwitchWindowHelper.switchTo("CoursesOfStudy Modification", event);
} else {
warning.setText("Bitte alle Felder ausfüllen.");
Alert alert = new Alert(Alert.AlertType.ERROR);
......@@ -83,19 +76,4 @@ public class CourseModificationController {
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();
}
}
......@@ -48,7 +48,6 @@ public class CoursesOfStudyModificationController {
@FXML
protected TextField warning;
@FXML
protected void onSaveButtonClick(ActionEvent event) throws IOException {
if (!name.getText().isBlank() && bachelorDegreeComboBox.getValue() != null &&
......@@ -64,7 +63,7 @@ public class CoursesOfStudyModificationController {
fees,
null,
FieldOfStudy.EMBEDDED_SYSTEMS));
switchToMain(event);
SwitchWindowHelper.switchTo("Main", event);
} else {
warning.setText("Bitte alle Felder ausfüllen.");
Alert alert = new Alert(Alert.AlertType.ERROR);
......@@ -74,21 +73,6 @@ public class CoursesOfStudyModificationController {
}
}
private Stage stage;
private Scene scene;
private FXMLLoader root;
@FXML
protected void switchToMain(ActionEvent event) throws IOException {
root = new FXMLLoader(Main.class.getResource("main.fxml"));
stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
scene = new Scene(root.load(), 960, 540);
stage.setTitle("Main");
stage.setScene(scene);
stage.show();
}
@FXML
protected void abortAndSwitchToMain(ActionEvent event) throws IOException {
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
......@@ -102,17 +86,12 @@ public class CoursesOfStudyModificationController {
Optional<ButtonType> result = alert.showAndWait();
if (result.get() == buttonTypeOne) {
switchToMain(event);
SwitchWindowHelper.switchTo("Main", event);
}
}
@FXML
protected void switchToCourseModification(ActionEvent event) throws IOException {
root = new FXMLLoader(Main.class.getResource("course-modification.fxml"));
stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
scene = new Scene(root.load(), 960, 540);
stage.setTitle("Course Modification");
stage.setScene(scene);
stage.show();
SwitchWindowHelper.switchTo("Course Modification", event);
}
}
......@@ -23,7 +23,6 @@ public class MainController {
static public ObservableList<CoursesOfStudy> coursesOfStudyList = FXCollections.observableArrayList();
static public ObservableList<Student> studentList = FXCollections.observableArrayList();
@FXML
protected void initialize() {
if (!coursesOfStudyList.isEmpty()) {
......@@ -34,58 +33,28 @@ public class MainController {
}
}
private Stage stage;
private Scene scene;
private FXMLLoader root;
@FXML
protected void switchToMain(ActionEvent event) throws IOException {
root = new FXMLLoader(Main.class.getResource("main.fxml"));
stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
scene = new Scene(root.load(), 960, 540);
stage.setTitle("Main");
stage.setScene(scene);
stage.show();
SwitchWindowHelper.switchTo("Main", event);
}
@FXML
protected void switchToStudentDetails(ActionEvent event) throws IOException {
root = new FXMLLoader(Main.class.getResource("student-details.fxml"));
stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
scene = new Scene(root.load(), 960, 540);
stage.setTitle("Student Details");
stage.setScene(scene);
stage.show();
SwitchWindowHelper.switchTo("Student Details", event);
}
@FXML
protected void switchToStudentModification(ActionEvent event) throws IOException {
root = new FXMLLoader(Main.class.getResource("student-modification.fxml"));
stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
scene = new Scene(root.load(), 960, 540);
stage.setTitle("Student Modification");
stage.setScene(scene);
stage.show();
SwitchWindowHelper.switchTo("Student Modification", event);
}
@FXML
protected void switchToCoursesOfStudyDetails(ActionEvent event) throws IOException {
root = new FXMLLoader(Main.class.getResource("courses-of-study-details.fxml"));
stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
scene = new Scene(root.load(), 960, 540);
stage.setTitle("Degree Details");
stage.setScene(scene);
stage.show();
SwitchWindowHelper.switchTo("CoursesOfStudy Details", event);
}
@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();
SwitchWindowHelper.switchTo("CoursesOfStudy Modification", event);
}
}
......@@ -8,11 +8,7 @@ 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;
......@@ -68,11 +64,6 @@ public class StudentModificationController {
@FXML
protected RadioButton no;
private Stage stage;
private Scene scene;
private FXMLLoader root;
@FXML
protected void onSaveButtonClick(ActionEvent event) throws IOException {
if(genderComboBox.getValue() != null && !firstName.getText().isBlank() && !lastName.getText().isBlank() &&
......@@ -99,7 +90,7 @@ public class StudentModificationController {
status,
bachelorSemester
));
switchToMain(event);
SwitchWindowHelper.switchTo("Main", event);
}
else
{
......@@ -111,16 +102,6 @@ public class StudentModificationController {
}
}
@FXML
protected void switchToMain(ActionEvent event) throws IOException {
root = new FXMLLoader(Main.class.getResource("main.fxml"));
stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
scene = new Scene(root.load(), 960, 540);
stage.setTitle("Main");
stage.setScene(scene);
stage.show();
}
@FXML
protected void abortAndSwitchToMain(ActionEvent event) throws IOException {
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
......@@ -134,7 +115,7 @@ public class StudentModificationController {
Optional<ButtonType> result = alert.showAndWait();
if (result.get() == buttonTypeOne){
switchToMain(event);
SwitchWindowHelper.switchTo("Main", event);
}
}
}
package de.thdeg.grademanager.gui;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.stage.Stage;
import java.io.IOException;
public class SwitchWindowHelper {
@FXML
public static void switchTo(String windowTitle, ActionEvent event) throws IOException {
FXMLLoader root = new FXMLLoader(Main.class.getResource(getResourceName(windowTitle)));
Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
Scene scene = new Scene(root.load(), 960, 540);
stage.setTitle(windowTitle);
stage.setScene(scene);
stage.show();
}
private static String getResourceName(String windowTitle) {
switch (windowTitle) {
case "Main":
return "main.fxml";
case "Student Details":
return "student-details.fxml";
case "Student Modification":
return "student-modification.fxml";
case "CoursesOfStudy Modification":
return "courses-of-study-modification.fxml";
case "CoursesOfStudy Details":
return "courses-of-study-details.fxml";
case "Course Modification":
return "course-modification.fxml";
}
return "";
}
}
......@@ -19,7 +19,6 @@
<children>
<ButtonBar buttonMinWidth="30.0" prefHeight="40.0" prefWidth="200.0">
<buttons>
<Button alignment="CENTER" minWidth="22.0" mnemonicParsing="false" onAction="#switchToCoursesOfStudyModification" prefHeight="26.0" text="←" />
<Button alignment="CENTER" disable="true" layoutX="31.0" layoutY="17.0" minWidth="22.0" mnemonicParsing="false" prefHeight="26.0" text="→" />
<Region prefHeight="200.0" prefWidth="200.0" />
</buttons>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment