Fehler bei XML speicherung angepasst
parent
489ea74b7a
commit
537aa94d54
|
@ -0,0 +1 @@
|
|||
Subproject commit 489ea74b7a7a3b9f156fd899a1015e63e77b4f2f
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
186
flights.xml
186
flights.xml
|
@ -1,11 +1,11 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<java version="21" class="java.beans.XMLDecoder">
|
||||
<java version="21.0.1" class="java.beans.XMLDecoder">
|
||||
<object class="models.Flights" id="Flights0">
|
||||
<void property="flights">
|
||||
<void method="add">
|
||||
<object class="models.Flight">
|
||||
<void property="TToF">
|
||||
<double>2.0</double>
|
||||
<double>1.0</double>
|
||||
</void>
|
||||
<void property="abflugort">
|
||||
<string>123</string>
|
||||
|
@ -14,132 +14,39 @@
|
|||
<string>12:00</string>
|
||||
</void>
|
||||
<void property="ankunftszeit">
|
||||
<string>14:00</string>
|
||||
<string>13:00</string>
|
||||
</void>
|
||||
<void property="anzahlLandungen">
|
||||
<int>2</int>
|
||||
<int>12</int>
|
||||
</void>
|
||||
<void property="datumStr">
|
||||
<string>2024-06-10</string>
|
||||
<string>2024-06-17</string>
|
||||
</void>
|
||||
<void property="kommentar">
|
||||
<string>asd</string>
|
||||
</void>
|
||||
<void property="muster">
|
||||
<string>asdasd</string>
|
||||
</void>
|
||||
<void property="pilot">
|
||||
<object class="models.Pilot">
|
||||
<void property="adresse">
|
||||
<string>sad</string>
|
||||
</void>
|
||||
<void property="kontaktinformationen">
|
||||
<string>ads</string>
|
||||
</void>
|
||||
<void property="name">
|
||||
<string>sad</string>
|
||||
</void>
|
||||
</object>
|
||||
</void>
|
||||
</object>
|
||||
</void>
|
||||
<void method="add">
|
||||
<object class="models.Flight">
|
||||
<void property="TToF">
|
||||
<double>1.0</double>
|
||||
</void>
|
||||
<void property="abflugort">
|
||||
<string>test</string>
|
||||
</void>
|
||||
<void property="abflugzeit">
|
||||
<string>11:00</string>
|
||||
</void>
|
||||
<void property="ankunftszeit">
|
||||
<string>12:00</string>
|
||||
</void>
|
||||
<void property="anzahlLandungen">
|
||||
<int>2</int>
|
||||
</void>
|
||||
<void property="datumStr">
|
||||
<string>2024-06-11</string>
|
||||
</void>
|
||||
<void property="kommentar">
|
||||
<string>asd</string>
|
||||
</void>
|
||||
<void property="muster">
|
||||
<string>test</string>
|
||||
</void>
|
||||
<void property="pilot">
|
||||
<object class="models.Pilot" id="Pilot0">
|
||||
<void property="adresse">
|
||||
<string>sad</string>
|
||||
<string>asd</string>
|
||||
</void>
|
||||
<void property="kontaktinformationen">
|
||||
<string>ads</string>
|
||||
<string>asd</string>
|
||||
</void>
|
||||
<void property="lizenzen">
|
||||
<void method="add">
|
||||
<string>äää</string>
|
||||
</void>
|
||||
<void method="add">
|
||||
<string>äää</string>
|
||||
<string>dasd</string>
|
||||
</void>
|
||||
</void>
|
||||
<void property="name">
|
||||
<string>sad</string>
|
||||
</void>
|
||||
</object>
|
||||
</void>
|
||||
</object>
|
||||
</void>
|
||||
<void method="add">
|
||||
<object class="models.Flight">
|
||||
<void property="TToF">
|
||||
<double>6.75</double>
|
||||
</void>
|
||||
<void property="abflugort">
|
||||
<string>max</string>
|
||||
</void>
|
||||
<void property="abflugzeit">
|
||||
<string>09:15</string>
|
||||
</void>
|
||||
<void property="ankunftszeit">
|
||||
<string>16:00</string>
|
||||
</void>
|
||||
<void property="anzahlLandungen">
|
||||
<int>2</int>
|
||||
</void>
|
||||
<void property="datumStr">
|
||||
<string>2024-06-14</string>
|
||||
</void>
|
||||
<void property="kommentar">
|
||||
<string>Kommentar</string>
|
||||
</void>
|
||||
<void property="muster">
|
||||
<string>Max</string>
|
||||
</void>
|
||||
<void property="pilot">
|
||||
<object class="models.Pilot" id="Pilot1">
|
||||
<void property="adresse">
|
||||
<string>max</string>
|
||||
</void>
|
||||
<void property="kontaktinformationen">
|
||||
<string>max</string>
|
||||
</void>
|
||||
<void property="lizenzen">
|
||||
<void method="add">
|
||||
<string>hallo</string>
|
||||
</void>
|
||||
<void method="add">
|
||||
<string>test</string>
|
||||
</void>
|
||||
</void>
|
||||
<void property="name">
|
||||
<string>max</string>
|
||||
<string>asdaa</string>
|
||||
</void>
|
||||
<void property="zertifikate">
|
||||
<void method="add">
|
||||
<string>test</string>
|
||||
<string>asdasd</string>
|
||||
</void>
|
||||
</void>
|
||||
</object>
|
||||
|
@ -152,7 +59,7 @@
|
|||
<double>1.0</double>
|
||||
</void>
|
||||
<void property="abflugort">
|
||||
<string>mannheim</string>
|
||||
<string>12322</string>
|
||||
</void>
|
||||
<void property="abflugzeit">
|
||||
<string>12:00</string>
|
||||
|
@ -164,39 +71,84 @@
|
|||
<int>1</int>
|
||||
</void>
|
||||
<void property="datumStr">
|
||||
<string>2024-06-14</string>
|
||||
<string>2024-06-17</string>
|
||||
</void>
|
||||
<void property="kommentar">
|
||||
<string>max</string>
|
||||
<string>asd</string>
|
||||
</void>
|
||||
<void property="muster">
|
||||
<string>newTest</string>
|
||||
<string>asdtest</string>
|
||||
</void>
|
||||
<void property="nachtflug">
|
||||
<boolean>true</boolean>
|
||||
<void property="pilot">
|
||||
<object class="models.Pilot" id="Pilot1">
|
||||
<void property="adresse">
|
||||
<string>asd</string>
|
||||
</void>
|
||||
<void property="kontaktinformationen">
|
||||
<string>asd</string>
|
||||
</void>
|
||||
<void property="lizenzen">
|
||||
<void method="add">
|
||||
<string>dasd</string>
|
||||
</void>
|
||||
</void>
|
||||
<void property="name">
|
||||
<string>asdaa</string>
|
||||
</void>
|
||||
<void property="zertifikate">
|
||||
<void method="add">
|
||||
<string>asdasd</string>
|
||||
</void>
|
||||
</void>
|
||||
</object>
|
||||
</void>
|
||||
</object>
|
||||
</void>
|
||||
<void method="add">
|
||||
<object class="models.Flight">
|
||||
<void property="TToF">
|
||||
<double>1.0</double>
|
||||
</void>
|
||||
<void property="abflugort">
|
||||
<string>12322</string>
|
||||
</void>
|
||||
<void property="abflugzeit">
|
||||
<string>12:00</string>
|
||||
</void>
|
||||
<void property="ankunftszeit">
|
||||
<string>13:00</string>
|
||||
</void>
|
||||
<void property="anzahlLandungen">
|
||||
<int>1</int>
|
||||
</void>
|
||||
<void property="datumStr">
|
||||
<string>2024-06-17</string>
|
||||
</void>
|
||||
<void property="kommentar">
|
||||
<string>asd</string>
|
||||
</void>
|
||||
<void property="muster">
|
||||
<string>asdtest</string>
|
||||
</void>
|
||||
<void property="pilot">
|
||||
<object class="models.Pilot" id="Pilot2">
|
||||
<void property="adresse">
|
||||
<string>max</string>
|
||||
<string>asd</string>
|
||||
</void>
|
||||
<void property="kontaktinformationen">
|
||||
<string>max</string>
|
||||
<string>asd</string>
|
||||
</void>
|
||||
<void property="lizenzen">
|
||||
<void method="add">
|
||||
<string>hallo</string>
|
||||
</void>
|
||||
<void method="add">
|
||||
<string>test</string>
|
||||
<string>dasd</string>
|
||||
</void>
|
||||
</void>
|
||||
<void property="name">
|
||||
<string>max</string>
|
||||
<string>asdaa</string>
|
||||
</void>
|
||||
<void property="zertifikate">
|
||||
<void method="add">
|
||||
<string>test</string>
|
||||
<string>asdasd</string>
|
||||
</void>
|
||||
</void>
|
||||
</object>
|
||||
|
|
58
pilots.xml
58
pilots.xml
|
@ -1,77 +1,53 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<java version="21" class="java.beans.XMLDecoder">
|
||||
<java version="21.0.1" class="java.beans.XMLDecoder">
|
||||
<object class="models.Pilots" id="Pilots0">
|
||||
<void property="pilots">
|
||||
<void method="add">
|
||||
<object class="models.Pilot">
|
||||
<void property="adresse">
|
||||
<string>sad</string>
|
||||
<string>asd</string>
|
||||
</void>
|
||||
<void property="kontaktinformationen">
|
||||
<string>ads</string>
|
||||
<string>asd</string>
|
||||
</void>
|
||||
<void property="name">
|
||||
<string>sad</string>
|
||||
</void>
|
||||
</object>
|
||||
</void>
|
||||
<void method="add">
|
||||
<object class="models.Pilot">
|
||||
<void property="adresse">
|
||||
<string>asdasd</string>
|
||||
</void>
|
||||
<void property="kontaktinformationen">
|
||||
<string>asdasd</string>
|
||||
</void>
|
||||
<void property="name">
|
||||
<string>sad</string>
|
||||
<string>asd</string>
|
||||
</void>
|
||||
</object>
|
||||
</void>
|
||||
<void method="add">
|
||||
<object class="models.Pilot" id="Pilot0">
|
||||
<void property="adresse">
|
||||
<string>sad</string>
|
||||
<string>asd</string>
|
||||
</void>
|
||||
<void property="kontaktinformationen">
|
||||
<string>ads</string>
|
||||
<string>asd</string>
|
||||
</void>
|
||||
<void property="lizenzen">
|
||||
<void method="add">
|
||||
<string>äää</string>
|
||||
</void>
|
||||
<void method="add">
|
||||
<string>äää</string>
|
||||
<string>dasd</string>
|
||||
</void>
|
||||
</void>
|
||||
<void property="name">
|
||||
<string>sad</string>
|
||||
<string>asdaa</string>
|
||||
</void>
|
||||
<void property="zertifikate">
|
||||
<void method="add">
|
||||
<string>asdasd</string>
|
||||
</void>
|
||||
</void>
|
||||
</object>
|
||||
</void>
|
||||
<void method="add">
|
||||
<object class="models.Pilot" id="Pilot1">
|
||||
<object class="models.Pilot">
|
||||
<void property="adresse">
|
||||
<string>max</string>
|
||||
<string>s</string>
|
||||
</void>
|
||||
<void property="kontaktinformationen">
|
||||
<string>max</string>
|
||||
</void>
|
||||
<void property="lizenzen">
|
||||
<void method="add">
|
||||
<string>hallo</string>
|
||||
</void>
|
||||
<void method="add">
|
||||
<string>test</string>
|
||||
</void>
|
||||
<string>d</string>
|
||||
</void>
|
||||
<void property="name">
|
||||
<string>max</string>
|
||||
</void>
|
||||
<void property="zertifikate">
|
||||
<void method="add">
|
||||
<string>test</string>
|
||||
</void>
|
||||
<string>a</string>
|
||||
</void>
|
||||
</object>
|
||||
</void>
|
||||
|
|
|
@ -19,11 +19,13 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
public class AddFlightController {
|
||||
private Flights flights;
|
||||
private Stage stage;
|
||||
private DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("HH:mm");
|
||||
|
||||
public AddFlightController(Stage stage) {
|
||||
this.stage = stage;
|
||||
loadFlights();
|
||||
}
|
||||
|
||||
public ObservableList<Pilot> loadPilots() {
|
||||
|
@ -74,6 +76,27 @@ public class AddFlightController {
|
|||
}
|
||||
}
|
||||
|
||||
public void saveFlight(Flight flight){
|
||||
if(flights == null){
|
||||
flights = new Flights(new ArrayList<>());
|
||||
}
|
||||
|
||||
boolean flightExists = false;
|
||||
for (int i = 0; i < flights.getFlights().size(); i++) {
|
||||
if (flights.getFlights().get(i).getMuster().equals(flight.getMuster())) {
|
||||
flights.getFlights().set(i, flight);
|
||||
flightExists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!flightExists) {
|
||||
flights.getFlights().add(flight);
|
||||
}
|
||||
|
||||
XMLHelper.saveToXML(flights, "flights.xml");
|
||||
}
|
||||
|
||||
public double calculateFlightDuration(String abflugzeit, String ankunftszeit) throws DateTimeParseException {
|
||||
LocalTime start = LocalTime.parse(abflugzeit, timeFormatter);
|
||||
LocalTime end = LocalTime.parse(ankunftszeit, timeFormatter);
|
||||
|
@ -93,12 +116,7 @@ public class AddFlightController {
|
|||
field.setStyle("-fx-border-color: red;");
|
||||
}
|
||||
|
||||
public void clearFieldStyles(Control... fields) {
|
||||
for (Control field : fields) {
|
||||
field.setStyle(null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void showAlert(String title, String message) {
|
||||
Alert alert = new Alert(Alert.AlertType.ERROR);
|
||||
alert.setTitle(title);
|
||||
|
@ -106,4 +124,8 @@ public class AddFlightController {
|
|||
alert.setContentText(message);
|
||||
alert.showAndWait();
|
||||
}
|
||||
|
||||
public void loadFlights() {
|
||||
flights = (Flights) XMLHelper.loadFromXML("flights.xml");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
package controllers;
|
||||
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import models.Pilot;
|
||||
import models.Pilots;
|
||||
import utils.XMLHelper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class DeletePilotController {
|
||||
private ObservableList<Pilot> pilotsList;
|
||||
|
||||
public DeletePilotController() {
|
||||
loadPilots();
|
||||
}
|
||||
|
||||
public ObservableList<Pilot> getPilotsList() {
|
||||
return pilotsList;
|
||||
}
|
||||
|
||||
public void loadPilots() {
|
||||
Pilots pilotsData = (Pilots) XMLHelper.loadFromXML("pilots.xml");
|
||||
List<Pilot> pilotList = pilotsData != null ? pilotsData.getPilots() : new java.util.ArrayList<>();
|
||||
pilotsList = FXCollections.observableArrayList(pilotList);
|
||||
}
|
||||
|
||||
public boolean deletePilot(Pilot pilot) {
|
||||
if (pilot != null) {
|
||||
// Create a new list to avoid modifying the observable list directly
|
||||
List<Pilot> updatedList = new java.util.ArrayList<>(pilotsList);
|
||||
// Remove the selected pilot from the list
|
||||
updatedList.remove(pilot);
|
||||
// Save the updated list back to the XML file
|
||||
XMLHelper.saveToXML(new Pilots(updatedList), "pilots.xml");
|
||||
// Reload the pilots list to update the observable list
|
||||
loadPilots();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -1,46 +0,0 @@
|
|||
package controllers;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.LocalTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.DateTimeParseException;
|
||||
|
||||
import javafx.scene.control.Alert;
|
||||
import javafx.scene.control.Control;
|
||||
|
||||
public class FlightController {
|
||||
private DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("HH:mm");
|
||||
|
||||
public double calculateFlightDuration(String abflugzeit, String ankunftszeit) throws DateTimeParseException {
|
||||
LocalTime start = LocalTime.parse(abflugzeit, timeFormatter);
|
||||
LocalTime end = LocalTime.parse(ankunftszeit, timeFormatter);
|
||||
return (double) Duration.between(start, end).toMinutes() / 60;
|
||||
}
|
||||
|
||||
public boolean isValidTime(String time) {
|
||||
try {
|
||||
LocalTime.parse(time, timeFormatter);
|
||||
return true;
|
||||
} catch (DateTimeParseException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void setErrorStyle(Control field) {
|
||||
field.setStyle("-fx-border-color: red;");
|
||||
}
|
||||
|
||||
public void clearFieldStyles(Control... fields) {
|
||||
for (Control field : fields) {
|
||||
field.setStyle(null);
|
||||
}
|
||||
}
|
||||
|
||||
public void showAlert(String title, String message) {
|
||||
Alert alert = new Alert(Alert.AlertType.ERROR);
|
||||
alert.setTitle(title);
|
||||
alert.setHeaderText(null);
|
||||
alert.setContentText(message);
|
||||
alert.showAndWait();
|
||||
}
|
||||
}
|
|
@ -6,10 +6,8 @@ import javafx.stage.Stage;
|
|||
import models.Flight;
|
||||
import models.Flights;
|
||||
import utils.XMLHelper;
|
||||
import views.EditFlightScreen;
|
||||
import views.HomeScreen;
|
||||
|
||||
import java.util.List;
|
||||
import views.ViewLogbookScreen;
|
||||
|
||||
public class LogbookController {
|
||||
private Stage stage;
|
||||
|
@ -17,7 +15,6 @@ public class LogbookController {
|
|||
|
||||
public LogbookController(Stage stage) {
|
||||
this.stage = stage;
|
||||
this.flightList = FXCollections.observableArrayList();
|
||||
loadFlights();
|
||||
}
|
||||
|
||||
|
@ -28,28 +25,34 @@ public class LogbookController {
|
|||
private void loadFlights() {
|
||||
Flights flights = (Flights) XMLHelper.loadFromXML("flights.xml");
|
||||
if (flights != null) {
|
||||
List<Flight> flightEntries = flights.getFlights();
|
||||
flightList.addAll(flightEntries);
|
||||
flightList = FXCollections.observableArrayList(flights.getFlights());
|
||||
} else {
|
||||
flightList = FXCollections.observableArrayList();
|
||||
}
|
||||
}
|
||||
|
||||
public void editFlight(Flight selectedFlight) {
|
||||
if (selectedFlight != null) {
|
||||
new EditFlightScreen(stage, selectedFlight).display();
|
||||
} else {
|
||||
showAlert("Fehler", "Bitte wählen Sie einen Flug aus.");
|
||||
/* public void editFlight(Flight flight) {
|
||||
if (flight != null) {
|
||||
new EditFlightScreen(stage, flight, this).display();
|
||||
}
|
||||
} */
|
||||
|
||||
public void updateFlight(Flight updatedFlight) {
|
||||
for (int i = 0; i < flightList.size(); i++) {
|
||||
if (flightList.get(i).getId().equals(updatedFlight.getId())) {
|
||||
flightList.set(i, updatedFlight);
|
||||
break;
|
||||
}
|
||||
}
|
||||
saveFlights();
|
||||
}
|
||||
|
||||
private void saveFlights() {
|
||||
Flights flights = new Flights(flightList);
|
||||
XMLHelper.saveToXML(flights, "flights.xml");
|
||||
}
|
||||
|
||||
public void goBack() {
|
||||
new HomeScreen(stage).display();
|
||||
}
|
||||
|
||||
private void showAlert(String title, String message) {
|
||||
javafx.scene.control.Alert alert = new javafx.scene.control.Alert(javafx.scene.control.Alert.AlertType.ERROR);
|
||||
alert.setTitle(title);
|
||||
alert.setHeaderText(null);
|
||||
alert.setContentText(message);
|
||||
alert.showAndWait();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
package controllers;
|
||||
|
||||
import models.Pilot;
|
||||
import models.Pilots;
|
||||
import utils.XMLHelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ManagePilotProfileController {
|
||||
private Pilots pilots;
|
||||
|
||||
public ManagePilotProfileController() {
|
||||
loadPilots();
|
||||
}
|
||||
|
||||
public List<Pilot> getPilotsList() {
|
||||
return pilots != null ? pilots.getPilots() : new ArrayList<>();
|
||||
}
|
||||
|
||||
public Pilot getPilot(String name) {
|
||||
if (pilots != null) {
|
||||
for (Pilot pilot : pilots.getPilots()) {
|
||||
if (pilot.getName().equals(name)) {
|
||||
return pilot;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void savePilot(Pilot pilot) throws Exception {
|
||||
if (pilots == null) {
|
||||
pilots = new Pilots(new ArrayList<>());
|
||||
}
|
||||
|
||||
boolean pilotExists = false;
|
||||
for (int i = 0; i < pilots.getPilots().size(); i++) {
|
||||
if (pilots.getPilots().get(i).getName().equals(pilot.getName())) {
|
||||
pilots.getPilots().set(i, pilot);
|
||||
pilotExists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!pilotExists) {
|
||||
pilots.getPilots().add(pilot);
|
||||
}
|
||||
|
||||
XMLHelper.saveToXML(pilots, "pilots.xml");
|
||||
}
|
||||
|
||||
public void loadPilots() {
|
||||
pilots = (Pilots) XMLHelper.loadFromXML("pilots.xml");
|
||||
}
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
package controllers;
|
||||
|
||||
import models.Pilot;
|
||||
import views.PilotView;
|
||||
|
||||
public class PilotController {
|
||||
private Pilot model;
|
||||
private PilotView view;
|
||||
|
||||
public PilotController(Pilot model, PilotView view) {
|
||||
this.model = model;
|
||||
this.view = view;
|
||||
}
|
||||
|
||||
public void setPilotName(String name) {
|
||||
model.setName(name);
|
||||
}
|
||||
|
||||
public String getPilotName() {
|
||||
return model.getName();
|
||||
}
|
||||
|
||||
public void updateView() {
|
||||
view.displayPilotDetails(model);
|
||||
}
|
||||
}
|
|
@ -6,11 +6,13 @@ import java.io.ObjectOutputStream;
|
|||
import java.io.Serializable;
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.UUID;
|
||||
import javafx.beans.property.*;
|
||||
|
||||
public class Flight implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String id; // Neue ID für jeden Flug
|
||||
private String datumStr; // String zur Speicherung des Datums in XML
|
||||
private transient ObjectProperty<LocalDate> datum; // transient, um die direkte Serialization zu vermeiden
|
||||
private StringProperty muster;
|
||||
|
@ -27,6 +29,7 @@ public class Flight implements Serializable {
|
|||
|
||||
// Standardkonstruktor
|
||||
public Flight() {
|
||||
this.id = UUID.randomUUID().toString(); // Generiere eine eindeutige ID
|
||||
this.datum = new SimpleObjectProperty<>();
|
||||
this.muster = new SimpleStringProperty();
|
||||
this.abflugort = new SimpleStringProperty();
|
||||
|
@ -39,18 +42,10 @@ public class Flight implements Serializable {
|
|||
this.kommentar = new SimpleStringProperty();
|
||||
}
|
||||
|
||||
public Flight(LocalDate datum, String muster, String abflugort, String abflugzeit, String ankunftszeit, double tToF, int anzahlLandungen, Pilot pilot, boolean nachtflug, String kommentar) {
|
||||
this();
|
||||
this.setDatum(datum);
|
||||
this.muster.set(muster);
|
||||
this.abflugort.set(abflugort);
|
||||
this.abflugzeit.set(abflugzeit);
|
||||
this.ankunftszeit.set(ankunftszeit);
|
||||
this.tToF.set(tToF);
|
||||
this.anzahlLandungen.set(anzahlLandungen);
|
||||
this.pilot.set(pilot);
|
||||
this.nachtflug.set(nachtflug);
|
||||
this.kommentar.set(kommentar);
|
||||
// Getter und Setter Methoden
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public LocalDate getDatum() {
|
||||
|
@ -62,17 +57,17 @@ public class Flight implements Serializable {
|
|||
this.datumStr = datum != null ? datum.format(formatter) : null;
|
||||
}
|
||||
|
||||
public ObjectProperty<LocalDate> datumProperty() {
|
||||
return datum;
|
||||
}
|
||||
|
||||
public String getDatumStr() {
|
||||
return datumStr;
|
||||
}
|
||||
|
||||
public void setDatumStr(String datumStr) {
|
||||
this.datumStr = datumStr;
|
||||
this.datum.set(datumStr != null ? LocalDate.parse(datumStr, formatter) : null);
|
||||
this.datum = datumStr != null ? new SimpleObjectProperty<>(LocalDate.parse(datumStr, formatter)) : new SimpleObjectProperty<>();
|
||||
}
|
||||
|
||||
public ObjectProperty<LocalDate> datumProperty() {
|
||||
return datum;
|
||||
}
|
||||
|
||||
public String getMuster() {
|
||||
|
@ -194,17 +189,13 @@ public class Flight implements Serializable {
|
|||
// Custom Serialization
|
||||
private void writeObject(ObjectOutputStream oos) throws IOException {
|
||||
oos.defaultWriteObject();
|
||||
oos.writeObject(datum.get() != null ? datum.get().format(formatter) : null);
|
||||
oos.writeObject(datumStr);
|
||||
}
|
||||
|
||||
// Custom Deserialization
|
||||
private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException {
|
||||
ois.defaultReadObject();
|
||||
String datumStr = (String) ois.readObject();
|
||||
if (datumStr != null) {
|
||||
this.datum = new SimpleObjectProperty<>(LocalDate.parse(datumStr, formatter));
|
||||
} else {
|
||||
this.datum = new SimpleObjectProperty<>();
|
||||
}
|
||||
datumStr = (String) ois.readObject();
|
||||
datum = datumStr != null ? new SimpleObjectProperty<>(LocalDate.parse(datumStr, formatter)) : new SimpleObjectProperty<>();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ public class Flights implements Serializable {
|
|||
private List<Flight> flights;
|
||||
|
||||
public Flights() {
|
||||
this.flights = new ArrayList<>();
|
||||
flights = new ArrayList<>();
|
||||
}
|
||||
|
||||
public Flights(List<Flight> flights) {
|
||||
|
@ -22,4 +22,20 @@ public class Flights implements Serializable {
|
|||
public void setFlights(List<Flight> flights) {
|
||||
this.flights = flights;
|
||||
}
|
||||
|
||||
public void addFlight(Flight flight) {
|
||||
flights.add(flight);
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return flights.size();
|
||||
}
|
||||
|
||||
public Flight get(int index) {
|
||||
return flights.get(index);
|
||||
}
|
||||
|
||||
public void set(int index, Flight flight) {
|
||||
flights.set(index, flight);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,8 +4,22 @@ import java.beans.XMLDecoder;
|
|||
import java.beans.XMLEncoder;
|
||||
import java.io.*;
|
||||
|
||||
import models.Flight;
|
||||
import models.Flights;
|
||||
|
||||
public class XMLHelper {
|
||||
|
||||
private static final String FLIGHTS_XML = "flights.xml";
|
||||
|
||||
/* public static Flights loadFlights() {
|
||||
// Implement loading flights from XML
|
||||
return (Flights) loadFromXML(FLIGHTS_XML);
|
||||
}
|
||||
|
||||
public static void saveFlights(Flights flights) {
|
||||
saveToXML(flights, FLIGHTS_XML);
|
||||
} */
|
||||
|
||||
public static void saveToXML(Object obj, String filePath) {
|
||||
try (XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(new FileOutputStream(filePath)))) {
|
||||
encoder.writeObject(obj);
|
||||
|
|
|
@ -11,16 +11,33 @@ import javafx.scene.layout.HBox;
|
|||
import javafx.scene.layout.VBox;
|
||||
import javafx.stage.Stage;
|
||||
import models.Flight;
|
||||
import models.Flights;
|
||||
import models.Pilot;
|
||||
import utils.XMLHelper;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class AddFlightScreen {
|
||||
private Stage stage;
|
||||
private AddFlightController controller;
|
||||
private Flight flight;
|
||||
|
||||
private DatePicker datumField;
|
||||
private TextField musterField;
|
||||
private TextField abflugortField;
|
||||
private TextField abflugzeitField;
|
||||
private TextField ankunftszeitField;
|
||||
private TextField tToFField;
|
||||
private TextField anzahlLandungenField;
|
||||
private CheckBox nachtflugBox;
|
||||
private TextField kommentarField;
|
||||
private ComboBox<Pilot> pilotComboBox;
|
||||
|
||||
public AddFlightScreen(Stage stage) {
|
||||
public AddFlightScreen(Stage stage, Flight flight) {
|
||||
this.stage = stage;
|
||||
this.flight = flight;
|
||||
this.controller = new AddFlightController(stage);
|
||||
}
|
||||
|
||||
|
@ -29,54 +46,49 @@ public class AddFlightScreen {
|
|||
label.setStyle("-fx-font-size: 18px; -fx-font-weight: bold;");
|
||||
|
||||
Label datumLabel = new Label("Datum:");
|
||||
DatePicker datumField = new DatePicker(LocalDate.now()); // Set today's date
|
||||
datumField = new DatePicker(LocalDate.now());
|
||||
|
||||
Label musterLabel = new Label("Muster:");
|
||||
TextField musterField = new TextField();
|
||||
musterField = new TextField();
|
||||
musterField.setPromptText("Muster");
|
||||
|
||||
Label abflugortLabel = new Label("Abflugort:");
|
||||
TextField abflugortField = new TextField();
|
||||
abflugortField = new TextField();
|
||||
abflugortField.setPromptText("Abflugort");
|
||||
|
||||
Label abflugzeitLabel = new Label("Abflugzeit:");
|
||||
TextField abflugzeitField = new TextField();
|
||||
abflugzeitField = new TextField();
|
||||
abflugzeitField.setPromptText("HH:mm");
|
||||
|
||||
Label ankunftszeitLabel = new Label("Ankunftszeit:");
|
||||
TextField ankunftszeitField = new TextField();
|
||||
ankunftszeitField = new TextField();
|
||||
ankunftszeitField.setPromptText("HH:mm");
|
||||
|
||||
Label tToFLabel = new Label("Flugdauer (Stunden):");
|
||||
TextField tToFField = new TextField();
|
||||
tToFField = new TextField();
|
||||
tToFField.setPromptText("Flugdauer (Stunden)");
|
||||
tToFField.setEditable(false); // Make the field read-only
|
||||
tToFField.setStyle("-fx-control-inner-background: #E0E0E0;"); // Gray out the field
|
||||
|
||||
Label anzahlLandungenLabel = new Label("Anzahl der Landungen:");
|
||||
TextField anzahlLandungenField = new TextField();
|
||||
anzahlLandungenField = new TextField();
|
||||
anzahlLandungenField.setPromptText("Anzahl der Landungen");
|
||||
|
||||
Label nachtflugLabel = new Label("Nachtflug:");
|
||||
CheckBox nachtflugBox = new CheckBox();
|
||||
nachtflugBox = new CheckBox();
|
||||
|
||||
Label kommentarLabel = new Label("Kommentar:");
|
||||
TextField kommentarField = new TextField();
|
||||
kommentarField = new TextField();
|
||||
kommentarField.setPromptText("Kommentar");
|
||||
|
||||
ObservableList<Pilot> pilotList = controller.loadPilots();
|
||||
Label pilotLabel = new Label("Pilot:");
|
||||
ComboBox<Pilot> pilotComboBox = new ComboBox<>(pilotList);
|
||||
pilotComboBox = new ComboBox<>(pilotList);
|
||||
|
||||
|
||||
Button saveBtn = new Button("Speichern");
|
||||
saveBtn.setStyle("-fx-background-color: #000000; -fx-text-fill: #FFFFFF; -fx-font-weight: bold;");
|
||||
saveBtn.setOnAction(e -> {
|
||||
Flight newFlight = new Flight();
|
||||
controller.clearFieldStyles(datumField, musterField, abflugortField, abflugzeitField, ankunftszeitField, tToFField, anzahlLandungenField, kommentarField);
|
||||
|
||||
// Save the flight with the corrected TToF value
|
||||
controller.saveFlight(newFlight, datumField, musterField, abflugortField, abflugzeitField, ankunftszeitField, tToFField, anzahlLandungenField, pilotComboBox, nachtflugBox, kommentarField);
|
||||
});
|
||||
saveBtn.setOnAction(e -> saveFlight(flight, datumField, musterField, abflugortField, abflugzeitField,
|
||||
ankunftszeitField, tToFField, anzahlLandungenField, pilotComboBox, nachtflugBox, kommentarField));//todo: saveFlight in Controller
|
||||
|
||||
Button backButton = new Button("Zurück");
|
||||
backButton.setStyle("-fx-background-color: #000000; -fx-text-fill: #FFFFFF; -fx-font-weight: bold;");
|
||||
|
@ -128,6 +140,11 @@ public class AddFlightScreen {
|
|||
|
||||
stage.setScene(scene);
|
||||
stage.show();
|
||||
|
||||
if (flight != null) {
|
||||
populateFieldsWithFlight(flight);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void updateFlightDuration(TextField abflugzeitField, TextField ankunftszeitField, TextField tToFField) {
|
||||
|
@ -146,4 +163,57 @@ public class AddFlightScreen {
|
|||
tToFField.setText("");
|
||||
}
|
||||
}
|
||||
|
||||
private void populateFieldsWithFlight(Flight flight) {
|
||||
datumField.setValue(LocalDate.parse(flight.getDatumStr()));
|
||||
musterField.setText(flight.getMuster());
|
||||
abflugortField.setText(flight.getAbflugort());
|
||||
abflugzeitField.setText(flight.getAbflugzeit());
|
||||
ankunftszeitField.setText(flight.getAnkunftszeit());
|
||||
tToFField.setText(Double.toString(flight.getTToF()));
|
||||
anzahlLandungenField.setText(Integer.toString(flight.getAnzahlLandungen()));
|
||||
nachtflugBox.setSelected(flight.isNachtflug());
|
||||
kommentarField.setText(flight.getKommentar());
|
||||
pilotComboBox.setValue(flight.getPilot());
|
||||
}
|
||||
|
||||
private void saveFlight(Flight newFlight, DatePicker datumField, TextField musterField, TextField abflugortField,
|
||||
TextField abflugzeitField, TextField ankunftszeitField, TextField tToFField, TextField anzahlLandungenField,
|
||||
ComboBox<Pilot> pilotComboBox, CheckBox nachtflugBox, TextField kommentarField) {
|
||||
try {
|
||||
double flightDuration = Double.parseDouble(tToFField.getText().replace(',', '.'));
|
||||
int landings = Integer.parseInt(anzahlLandungenField.getText());
|
||||
boolean isNachtflug = nachtflugBox.isSelected();
|
||||
|
||||
newFlight.setDatum(datumField.getValue());
|
||||
newFlight.setMuster(musterField.getText());
|
||||
newFlight.setAbflugort(abflugortField.getText());
|
||||
newFlight.setAbflugzeit(abflugzeitField.getText());
|
||||
newFlight.setAnkunftszeit(ankunftszeitField.getText());
|
||||
newFlight.setTToF(flightDuration);
|
||||
newFlight.setAnzahlLandungen(landings);
|
||||
newFlight.setPilot(pilotComboBox.getValue());
|
||||
newFlight.setNachtflug(isNachtflug);
|
||||
newFlight.setKommentar(kommentarField.getText());
|
||||
newFlight.setDatumStr(datumField.getValue().format(DateTimeFormatter.ISO_LOCAL_DATE));
|
||||
|
||||
controller.saveFlight(newFlight);
|
||||
|
||||
new HomeScreen(stage).display();
|
||||
} catch (NumberFormatException e) {
|
||||
showAlert("Ungültige Eingabe", "Bitte stellen Sie sicher, dass die Flugdauer und die Anzahl der Landungen numerisch sind.");
|
||||
} catch (IllegalArgumentException e) {
|
||||
showAlert("Fehlende Eingabe", e.getMessage());
|
||||
} catch (Exception e) {
|
||||
showAlert("Fehler", "Es ist ein Fehler beim Speichern des Flugs aufgetreten.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
private void showAlert(String title, String message) {
|
||||
Alert alert = new Alert(Alert.AlertType.ERROR);
|
||||
alert.setTitle(title);
|
||||
alert.setHeaderText(null);
|
||||
alert.setContentText(message);
|
||||
alert.showAndWait();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package views;
|
||||
|
||||
import controllers.DeletePilotController;
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.Scene;
|
||||
|
@ -11,35 +12,30 @@ import javafx.scene.layout.BorderPane;
|
|||
import javafx.scene.layout.VBox;
|
||||
import javafx.stage.Stage;
|
||||
import models.Pilot;
|
||||
import models.Pilots;
|
||||
import utils.XMLHelper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class DeletePilotScreen {
|
||||
private Stage stage;
|
||||
private DeletePilotController controller;
|
||||
|
||||
public DeletePilotScreen(Stage stage) {
|
||||
this.stage = stage;
|
||||
this.controller = new DeletePilotController();
|
||||
}
|
||||
|
||||
public void display() {
|
||||
Label label = new Label("Piloten löschen");
|
||||
label.setStyle("-fx-font-size: 18px; -fx-font-weight: bold;");
|
||||
|
||||
Pilots pilotsData = (Pilots) XMLHelper.loadFromXML("pilots.xml");
|
||||
List<Pilot> pilotList = pilotsData != null ? pilotsData.getPilots() : new java.util.ArrayList<>();
|
||||
ComboBox<Pilot> pilotComboBox = new ComboBox<>(javafx.collections.FXCollections.observableArrayList(pilotList));
|
||||
ComboBox<Pilot> pilotComboBox = new ComboBox<>(controller.getPilotsList());
|
||||
pilotComboBox.setPromptText("Pilot auswählen");
|
||||
|
||||
Button deleteBtn = new Button("Löschen");
|
||||
deleteBtn.setStyle("-fx-background-color: #000000; -fx-text-fill: #FFFFFF; -fx-font-weight: bold;");
|
||||
deleteBtn.setOnAction(e -> {
|
||||
Pilot selectedPilot = pilotComboBox.getValue();
|
||||
if (selectedPilot != null) {
|
||||
pilotList.remove(selectedPilot);
|
||||
XMLHelper.saveToXML(new Pilots(pilotList), "pilots.xml");
|
||||
new HomeScreen(stage).display();
|
||||
if (selectedPilot != null && controller.deletePilot(selectedPilot)) {
|
||||
showAlert("Erfolg", "Der Pilot wurde erfolgreich gelöscht.");
|
||||
pilotComboBox.setItems(controller.getPilotsList()); // Refresh the combo box
|
||||
} else {
|
||||
showAlert("Fehler", "Bitte wählen Sie einen Piloten aus.");
|
||||
}
|
||||
|
@ -52,7 +48,6 @@ public class DeletePilotScreen {
|
|||
VBox vbox = new VBox(10, label, pilotComboBox, deleteBtn);
|
||||
vbox.setAlignment(Pos.CENTER);
|
||||
vbox.setPadding(new Insets(20));
|
||||
|
||||
|
||||
BorderPane borderPane = new BorderPane();
|
||||
borderPane.setTop(backButton);
|
||||
|
@ -68,7 +63,7 @@ public class DeletePilotScreen {
|
|||
}
|
||||
|
||||
private void showAlert(String title, String message) {
|
||||
Alert alert = new Alert(Alert.AlertType.ERROR);
|
||||
Alert alert = new Alert(Alert.AlertType.INFORMATION);
|
||||
alert.setTitle(title);
|
||||
alert.setHeaderText(null);
|
||||
alert.setContentText(message);
|
||||
|
|
|
@ -1,178 +0,0 @@
|
|||
package views;
|
||||
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.layout.BorderPane;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.stage.Stage;
|
||||
import models.Flight;
|
||||
import models.Flights;
|
||||
import utils.XMLHelper;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
public class EditFlightScreen {
|
||||
private Stage stage;
|
||||
private Flight flight;
|
||||
|
||||
public EditFlightScreen(Stage stage, Flight flight) {
|
||||
this.stage = stage;
|
||||
this.flight = flight;
|
||||
}
|
||||
|
||||
public void display() {
|
||||
Label label = new Label("Flugdaten bearbeiten:");
|
||||
label.setStyle("-fx-font-size: 18px; -fx-font-weight: bold;");
|
||||
DatePicker datumField = new DatePicker(flight.getDatum());
|
||||
TextField musterField = new TextField(flight.getMuster());
|
||||
TextField abflugortField = new TextField(flight.getAbflugort());
|
||||
TextField abflugzeitField = new TextField(flight.getAbflugzeit());
|
||||
TextField ankunftszeitField = new TextField(flight.getAnkunftszeit());
|
||||
TextField tToFField = new TextField(String.valueOf(flight.getTToF()));
|
||||
TextField anzahlLandungenField = new TextField(String.valueOf(flight.getAnzahlLandungen()));
|
||||
CheckBox nachtflugBox = new CheckBox("Nachtflug");
|
||||
nachtflugBox.setSelected(flight.isNachtflug());
|
||||
TextField kommentarField = new TextField(flight.getKommentar());
|
||||
|
||||
datumField.setPromptText("YYYY-MM-DD");
|
||||
musterField.setPromptText("Muster");
|
||||
abflugortField.setPromptText("Abflugort");
|
||||
abflugzeitField.setPromptText("HH:MM");
|
||||
ankunftszeitField.setPromptText("HH:MM");
|
||||
tToFField.setPromptText("Flugdauer (Stunden)");
|
||||
anzahlLandungenField.setPromptText("Anzahl der Landungen");
|
||||
kommentarField.setPromptText("Kommentar");
|
||||
|
||||
// Nur numerische Eingaben für Flugdauer und Anzahl der Landungen zulassen
|
||||
tToFField.textProperty().addListener((observable, oldValue, newValue) -> {
|
||||
if (!newValue.matches("\\d*\\.?\\d*")) {
|
||||
tToFField.setText(oldValue);
|
||||
}
|
||||
});
|
||||
|
||||
anzahlLandungenField.textProperty().addListener((observable, oldValue, newValue) -> {
|
||||
if (!newValue.matches("\\d*")) {
|
||||
anzahlLandungenField.setText(oldValue);
|
||||
}
|
||||
});
|
||||
|
||||
Button saveBtn = new Button("Speichern");
|
||||
saveBtn.setStyle("-fx-background-color: #000000; -fx-text-fill: #FFFFFF; -fx-font-weight: bold;");
|
||||
saveBtn.setOnAction(e -> handleSaveFlight(datumField, musterField, abflugortField, abflugzeitField, ankunftszeitField,
|
||||
tToFField, anzahlLandungenField, nachtflugBox.isSelected(), kommentarField));
|
||||
|
||||
Button backButton = new Button("Zurück");
|
||||
backButton.setStyle("-fx-background-color: #000000; -fx-text-fill: #FFFFFF; -fx-font-weight: bold;");
|
||||
backButton.setOnAction(e -> new ViewLogbookScreen(stage).display());
|
||||
|
||||
VBox vbox = new VBox(10, label, datumField, musterField, abflugortField, abflugzeitField, ankunftszeitField,
|
||||
tToFField, anzahlLandungenField, nachtflugBox, kommentarField, saveBtn);
|
||||
vbox.setAlignment(Pos.CENTER);
|
||||
vbox.setPadding(new Insets(20));
|
||||
|
||||
|
||||
BorderPane borderPane = new BorderPane();
|
||||
borderPane.setTop(backButton);
|
||||
borderPane.setCenter(vbox);
|
||||
BorderPane.setAlignment(backButton, Pos.TOP_LEFT);
|
||||
BorderPane.setMargin(backButton, new Insets(10));
|
||||
|
||||
Scene scene = new Scene(borderPane, 800, 600);
|
||||
scene.getStylesheets().add(getClass().getResource("/resources/styles.css").toExternalForm());
|
||||
|
||||
stage.setScene(scene);
|
||||
stage.show();
|
||||
}
|
||||
|
||||
private void handleSaveFlight(DatePicker datumField, TextField musterField, TextField abflugortField, TextField abflugzeitField,
|
||||
TextField ankunftszeitField, TextField tToFField, TextField anzahlLandungenField, boolean isNachtflug,
|
||||
TextField kommentarField) {
|
||||
clearFieldStyles(datumField, musterField, abflugortField, abflugzeitField, ankunftszeitField, tToFField, anzahlLandungenField);
|
||||
|
||||
try {
|
||||
if (datumField.getValue() == null) {
|
||||
setErrorStyle(datumField);
|
||||
throw new IllegalArgumentException("Datum ist erforderlich.");
|
||||
}
|
||||
if (musterField.getText().isEmpty()) {
|
||||
setErrorStyle(musterField);
|
||||
throw new IllegalArgumentException("Muster ist erforderlich.");
|
||||
}
|
||||
if (abflugortField.getText().isEmpty()) {
|
||||
setErrorStyle(abflugortField);
|
||||
throw new IllegalArgumentException("Abflugort ist erforderlich.");
|
||||
}
|
||||
if (abflugzeitField.getText().isEmpty()) {
|
||||
setErrorStyle(abflugzeitField);
|
||||
throw new IllegalArgumentException("Abflugzeit ist erforderlich.");
|
||||
}
|
||||
if (ankunftszeitField.getText().isEmpty()) {
|
||||
setErrorStyle(ankunftszeitField);
|
||||
throw new IllegalArgumentException("Ankunftszeit ist erforderlich.");
|
||||
}
|
||||
if (tToFField.getText().isEmpty()) {
|
||||
setErrorStyle(tToFField);
|
||||
throw new IllegalArgumentException("Flugdauer ist erforderlich.");
|
||||
}
|
||||
if (anzahlLandungenField.getText().isEmpty()) {
|
||||
setErrorStyle(anzahlLandungenField);
|
||||
throw new IllegalArgumentException("Anzahl der Landungen ist erforderlich.");
|
||||
}
|
||||
|
||||
double flightDuration = Double.parseDouble(tToFField.getText());
|
||||
int landings = Integer.parseInt(anzahlLandungenField.getText());
|
||||
|
||||
flight.setDatum(datumField.getValue());
|
||||
flight.setMuster(musterField.getText());
|
||||
flight.setAbflugort(abflugortField.getText());
|
||||
flight.setAbflugzeit(abflugzeitField.getText());
|
||||
flight.setAnkunftszeit(ankunftszeitField.getText());
|
||||
flight.setTToF(flightDuration);
|
||||
flight.setAnzahlLandungen(landings);
|
||||
flight.setNachtflug(isNachtflug);
|
||||
flight.setKommentar(kommentarField.getText());
|
||||
|
||||
Flights flights = (Flights) XMLHelper.loadFromXML("flights.xml");
|
||||
if (flights != null) {
|
||||
List<Flight> flightEntries = flights.getFlights();
|
||||
for (int i = 0; i < flightEntries.size(); i++) {
|
||||
if (flightEntries.get(i).equals(flight)) {
|
||||
flightEntries.set(i, flight);
|
||||
break;
|
||||
}
|
||||
}
|
||||
XMLHelper.saveToXML(flights, "flights.xml");
|
||||
}
|
||||
|
||||
new ViewLogbookScreen(stage).display();
|
||||
} catch (NumberFormatException e) {
|
||||
showAlert("Ungültige Eingabe", "Bitte stellen Sie sicher, dass die Flugdauer und die Anzahl der Landungen numerisch sind.");
|
||||
} catch (IllegalArgumentException e) {
|
||||
showAlert("Fehlende Eingabe", e.getMessage());
|
||||
} catch (Exception e) {
|
||||
showAlert("Fehler", "Es ist ein Fehler beim Speichern des Flugs aufgetreten.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void setErrorStyle(Control field) {
|
||||
field.setStyle("-fx-border-color: red;");
|
||||
}
|
||||
|
||||
private void clearFieldStyles(Control... fields) {
|
||||
for (Control field : fields) {
|
||||
field.setStyle(null);
|
||||
}
|
||||
}
|
||||
|
||||
private void showAlert(String title, String message) {
|
||||
Alert alert = new Alert(Alert.AlertType.ERROR);
|
||||
alert.setTitle(title);
|
||||
alert.setHeaderText(null);
|
||||
alert.setContentText(message);
|
||||
alert.showAndWait();
|
||||
}
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
package views;
|
||||
|
||||
import models.Flight;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class FlightView {
|
||||
public void displayFlightDetails(Flight flight) {
|
||||
System.out.println("Flight Details: ");
|
||||
System.out.println("Datum: " + flight.getDatum());
|
||||
System.out.println("Muster: " + flight.getMuster());
|
||||
System.out.println("Abflugort: " + flight.getAbflugort());
|
||||
System.out.println("Abflugzeit: " + flight.getAbflugzeit());
|
||||
System.out.println("Ankunftszeit: " + flight.getAnkunftszeit());
|
||||
System.out.println("Flugdauer: " + flight.getTToF());
|
||||
System.out.println("Anzahl der Landungen: " + flight.getAnzahlLandungen());
|
||||
System.out.println("Pilotinformationen: " + flight.getPilotInformationen());
|
||||
System.out.println("Nachtflug: " + (flight.isNachtflug() ? "Ja" : "Nein"));
|
||||
System.out.println("Kommentar: " + flight.getKommentar());
|
||||
}
|
||||
|
||||
public void displayAllFlights(List<Flight> flights) {
|
||||
for (Flight flight : flights) {
|
||||
displayFlightDetails(flight);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -36,7 +36,7 @@ public class HomeScreen {
|
|||
Button helpBtn = createHelpButton("/resources/icons/help_icon.png", "Hilfe anzeigen");
|
||||
Button editPilotsBtn = createButton("Pilot bearbeiten", "/resources/icons/manage_pilot_icon.png", "Bearbeiten Sie ein Pilotenprofil");
|
||||
|
||||
btn1.setOnAction(e -> new AddFlightScreen(stage).display());
|
||||
btn1.setOnAction(e -> new AddFlightScreen(stage, null).display());
|
||||
btn2.setOnAction(e -> new ViewLogbookScreen(stage).display());
|
||||
btn3.setOnAction(e -> new ManagePilotProfileScreen(stage).display());
|
||||
btn4.setOnAction(e -> new DeletePilotScreen(stage).display());
|
||||
|
@ -44,7 +44,7 @@ public class HomeScreen {
|
|||
editPilotsBtn.setOnAction(e -> {
|
||||
Pilots pilots = (Pilots) XMLHelper.loadFromXML("pilots.xml");
|
||||
if (pilots != null && !pilots.getPilots().isEmpty()) {
|
||||
new ManagePilotProfileScreen(stage).displayEditSelection(pilots); // Aufruf mit Pilotenliste
|
||||
new ManagePilotProfileScreen(stage).displayEditSelection(); // Aufruf mit Pilotenliste
|
||||
} else {
|
||||
showAlert("Keine Piloten", "Es sind keine Piloten zum Bearbeiten verfügbar.");
|
||||
}
|
||||
|
|
|
@ -1,33 +1,35 @@
|
|||
package views;
|
||||
|
||||
import controllers.ManagePilotProfileController;
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.layout.BorderPane;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.stage.Stage;
|
||||
import models.Pilot;
|
||||
import models.Pilots;
|
||||
import utils.XMLHelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class ManagePilotProfileScreen {
|
||||
private Stage stage;
|
||||
private ManagePilotProfileController controller;
|
||||
|
||||
public ManagePilotProfileScreen(Stage stage) {
|
||||
this.stage = stage;
|
||||
this.controller = new ManagePilotProfileController();
|
||||
}
|
||||
|
||||
public void display() {
|
||||
display(null);
|
||||
}
|
||||
|
||||
public void displayEditSelection(Pilots pilots) {
|
||||
public void displayEditSelection() {
|
||||
Label label = new Label("Wählen Sie einen Piloten zum Bearbeiten aus:");
|
||||
ComboBox<Pilot> pilotComboBox = new ComboBox<>();
|
||||
pilotComboBox.getItems().addAll(pilots.getPilots());
|
||||
pilotComboBox.getItems().addAll(controller.getPilotsList());
|
||||
pilotComboBox.setPromptText("Pilot auswählen");
|
||||
|
||||
Button selectBtn = new Button("Auswählen");
|
||||
|
@ -46,7 +48,6 @@ public class ManagePilotProfileScreen {
|
|||
VBox vbox = new VBox(10, label, pilotComboBox, selectBtn);
|
||||
vbox.setAlignment(Pos.CENTER);
|
||||
vbox.setPadding(new Insets(20));
|
||||
|
||||
|
||||
BorderPane borderPane = new BorderPane();
|
||||
borderPane.setTop(backButton);
|
||||
|
@ -57,65 +58,69 @@ public class ManagePilotProfileScreen {
|
|||
Scene scene = new Scene(borderPane, 800, 600);
|
||||
scene.getStylesheets().add(getClass().getResource("/resources/styles.css").toExternalForm());
|
||||
|
||||
|
||||
stage.setScene(scene);
|
||||
stage.show();
|
||||
}
|
||||
|
||||
public void display(Pilot pilot) {
|
||||
Label label = new Label(pilot == null ? "Pilotendaten eingeben:" : "Pilotendaten bearbeiten:");
|
||||
TextField nameField = new TextField(pilot != null ? pilot.getName() : "");
|
||||
TextField adresseField = new TextField(pilot != null ? pilot.getAdresse() : "");
|
||||
TextField kontaktinformationenField = new TextField(pilot != null ? pilot.getKontaktinformationen() : "");
|
||||
TextField lizenzField = new TextField();
|
||||
TextField zertifikatField = new TextField();
|
||||
Label label = new Label(pilot == null ? "Neuen Piloten anlegen" : "Pilotenprofil bearbeiten");
|
||||
label.setStyle("-fx-font-size: 18px; -fx-font-weight: bold;");
|
||||
|
||||
TextField nameField = new TextField();
|
||||
nameField.setPromptText("Name");
|
||||
TextField adresseField = new TextField();
|
||||
adresseField.setPromptText("Adresse");
|
||||
TextField kontaktinformationenField = new TextField();
|
||||
kontaktinformationenField.setPromptText("Kontaktinformationen");
|
||||
lizenzField.setPromptText("Neue Lizenz");
|
||||
zertifikatField.setPromptText("Neues Zertifikat");
|
||||
|
||||
ListView<String> lizenzListView = new ListView<>();
|
||||
ListView<String> zertifikatListView = new ListView<>();
|
||||
|
||||
if (pilot != null) {
|
||||
lizenzListView.getItems().addAll(pilot.getLizenzen());
|
||||
zertifikatListView.getItems().addAll(pilot.getZertifikate());
|
||||
nameField.setText(pilot.getName());
|
||||
adresseField.setText(pilot.getAdresse());
|
||||
kontaktinformationenField.setText(pilot.getKontaktinformationen());
|
||||
}
|
||||
|
||||
Button addLizenzBtn = new Button("Lizenz hinzufügen");
|
||||
addLizenzBtn.setOnAction(e -> {
|
||||
if (!lizenzField.getText().isEmpty()) {
|
||||
lizenzListView.getItems().add(lizenzField.getText());
|
||||
ListView<String> lizenzListView = new ListView<>();
|
||||
lizenzListView.getItems().addAll(pilot != null ? pilot.getLizenzen() : new ArrayList<>());
|
||||
|
||||
TextField lizenzField = new TextField();
|
||||
lizenzField.setPromptText("Neue Lizenz hinzufügen");
|
||||
Button addLizenzButton = new Button("Hinzufügen");
|
||||
addLizenzButton.setOnAction(e -> {
|
||||
String lizenz = lizenzField.getText();
|
||||
if (!lizenz.isEmpty()) {
|
||||
lizenzListView.getItems().add(lizenz);
|
||||
lizenzField.clear();
|
||||
}
|
||||
});
|
||||
|
||||
Button addZertifikatBtn = new Button("Zertifikat hinzufügen");
|
||||
addZertifikatBtn.setOnAction(e -> {
|
||||
if (!zertifikatField.getText().isEmpty()) {
|
||||
zertifikatListView.getItems().add(zertifikatField.getText());
|
||||
ListView<String> zertifikatListView = new ListView<>();
|
||||
zertifikatListView.getItems().addAll(pilot != null ? pilot.getZertifikate() : new ArrayList<>());
|
||||
|
||||
TextField zertifikatField = new TextField();
|
||||
zertifikatField.setPromptText("Neues Zertifikat hinzufügen");
|
||||
Button addZertifikatButton = new Button("Hinzufügen");
|
||||
addZertifikatButton.setOnAction(e -> {
|
||||
String zertifikat = zertifikatField.getText();
|
||||
if (!zertifikat.isEmpty()) {
|
||||
zertifikatListView.getItems().add(zertifikat);
|
||||
zertifikatField.clear();
|
||||
}
|
||||
});
|
||||
|
||||
Button submitBtn = new Button(pilot == null ? "Hinzufügen" : "Speichern");
|
||||
|
||||
submitBtn.setOnAction(e -> handleSaveProfile(pilot, nameField, adresseField, kontaktinformationenField,
|
||||
lizenzListView, zertifikatListView));
|
||||
|
||||
Button viewPilotsBtn = new Button("Alle Piloten anzeigen");
|
||||
viewPilotsBtn.setOnAction(e -> new PilotView(stage).displayAllPilots());
|
||||
Button saveBtn = new Button("Speichern");
|
||||
saveBtn.setOnAction(e -> savePilot(pilot, nameField, adresseField, kontaktinformationenField, lizenzListView, zertifikatListView));
|
||||
|
||||
Button backButton = new Button("Zurück");
|
||||
backButton.setOnAction(e -> new HomeScreen(stage).display());
|
||||
|
||||
VBox vbox = new VBox(10, label, nameField, adresseField, kontaktinformationenField, lizenzField, addLizenzBtn,
|
||||
lizenzListView, zertifikatField, addZertifikatBtn, zertifikatListView, submitBtn, viewPilotsBtn);
|
||||
VBox lizenzBox = new VBox(10, new Label("Lizenzen"), lizenzListView, lizenzField, addLizenzButton);
|
||||
lizenzBox.setAlignment(Pos.CENTER);
|
||||
VBox zertifikatBox = new VBox(10, new Label("Zertifikate"), zertifikatListView, zertifikatField, addZertifikatButton);
|
||||
zertifikatBox.setAlignment(Pos.CENTER);
|
||||
|
||||
VBox vbox = new VBox(10, label, nameField, adresseField, kontaktinformationenField, lizenzBox, zertifikatBox, saveBtn);
|
||||
vbox.setAlignment(Pos.CENTER);
|
||||
vbox.setPadding(new Insets(20));
|
||||
|
||||
|
||||
BorderPane borderPane = new BorderPane();
|
||||
borderPane.setTop(backButton);
|
||||
|
@ -130,8 +135,8 @@ public class ManagePilotProfileScreen {
|
|||
stage.show();
|
||||
}
|
||||
|
||||
private void handleSaveProfile(Pilot pilot, TextField nameField, TextField adresseField,
|
||||
TextField kontaktinformationenField, ListView<String> lizenzListView, ListView<String> zertifikatListView) {
|
||||
private void savePilot(Pilot pilot, TextField nameField, TextField adresseField, TextField kontaktinformationenField,
|
||||
ListView<String> lizenzListView, ListView<String> zertifikatListView) {
|
||||
clearFieldStyles(nameField, adresseField, kontaktinformationenField);
|
||||
|
||||
try {
|
||||
|
@ -159,16 +164,7 @@ public class ManagePilotProfileScreen {
|
|||
pilot.setLizenzen(new ArrayList<>(lizenzListView.getItems()));
|
||||
pilot.setZertifikate(new ArrayList<>(zertifikatListView.getItems()));
|
||||
|
||||
Pilots pilots = (Pilots) XMLHelper.loadFromXML("pilots.xml");
|
||||
if (pilots == null) {
|
||||
pilots = new Pilots(new ArrayList<>());
|
||||
}
|
||||
|
||||
if (!pilots.getPilots().contains(pilot)) {
|
||||
pilots.getPilots().add(pilot);
|
||||
}
|
||||
|
||||
XMLHelper.saveToXML(pilots, "pilots.xml");
|
||||
controller.savePilot(pilot);
|
||||
|
||||
new HomeScreen(stage).display();
|
||||
} catch (IllegalArgumentException e) {
|
||||
|
|
|
@ -1,83 +0,0 @@
|
|||
package views;
|
||||
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.ScrollPane;
|
||||
import javafx.scene.layout.BorderPane;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.stage.Stage;
|
||||
import models.Pilot;
|
||||
import models.Pilots;
|
||||
import utils.XMLHelper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class PilotView {
|
||||
private Stage stage;
|
||||
|
||||
public PilotView(Stage stage) {
|
||||
this.stage = stage;
|
||||
}
|
||||
|
||||
public void displayPilotDetails(Pilot pilot) {
|
||||
Label nameLabel = new Label("Name: " + pilot.getName());
|
||||
Label adresseLabel = new Label("Adresse: " + pilot.getAdresse());
|
||||
Label kontaktLabel = new Label("Kontaktinformationen: " + pilot.getKontaktinformationen());
|
||||
Label lizenzenLabel = new Label("Lizenzen: " + String.join(", ", pilot.getLizenzen()));
|
||||
Label zertifikateLabel = new Label("Zertifikate: " + String.join(", ", pilot.getZertifikate()));
|
||||
|
||||
VBox vbox = new VBox(10, nameLabel, adresseLabel, kontaktLabel, lizenzenLabel, zertifikateLabel);
|
||||
vbox.setAlignment(Pos.CENTER);
|
||||
vbox.setPadding(new Insets(20));
|
||||
|
||||
|
||||
Button backButton = new Button("Zurück");
|
||||
backButton.setOnAction(e -> new HomeScreen(stage).display());
|
||||
|
||||
BorderPane borderPane = new BorderPane();
|
||||
borderPane.setTop(backButton);
|
||||
borderPane.setCenter(vbox);
|
||||
BorderPane.setAlignment(backButton, Pos.TOP_LEFT);
|
||||
BorderPane.setMargin(backButton, new Insets(10));
|
||||
|
||||
Scene scene = new Scene(borderPane, 800, 600); // Fenstergröße angepasst
|
||||
scene.getStylesheets().add(getClass().getResource("/resources/styles.css").toExternalForm());
|
||||
stage.setScene(scene);
|
||||
stage.setTitle("Pilot Details");
|
||||
stage.show();
|
||||
}
|
||||
|
||||
public void displayAllPilots() {
|
||||
Pilots pilotsData = (Pilots) XMLHelper.loadFromXML("pilots.xml");
|
||||
List<Pilot> pilots = pilotsData != null ? pilotsData.getPilots() : List.of();
|
||||
|
||||
VBox vbox = new VBox(10);
|
||||
vbox.setPadding(new Insets(20));
|
||||
|
||||
for (Pilot pilot : pilots) {
|
||||
Label pilotLabel = new Label(pilot.getName());
|
||||
vbox.getChildren().add(pilotLabel);
|
||||
}
|
||||
|
||||
ScrollPane scrollPane = new ScrollPane(vbox); // ScrollPane hinzugefügt
|
||||
scrollPane.setFitToWidth(true);
|
||||
scrollPane.setFitToHeight(true);
|
||||
|
||||
Button backButton = new Button("Zurück");
|
||||
backButton.setOnAction(e -> new HomeScreen(stage).display());
|
||||
|
||||
BorderPane borderPane = new BorderPane();
|
||||
borderPane.setTop(backButton);
|
||||
borderPane.setCenter(scrollPane); // ScrollPane anstelle von VBox hinzugefügt
|
||||
BorderPane.setAlignment(backButton, Pos.TOP_LEFT);
|
||||
BorderPane.setMargin(backButton, new Insets(10));
|
||||
|
||||
Scene scene = new Scene(borderPane, 800, 600); // Fenstergröße angepasst
|
||||
stage.setScene(scene);
|
||||
stage.setTitle("Alle Piloten");
|
||||
stage.show();
|
||||
}
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
package views;
|
||||
|
||||
import controllers.AddFlightController;
|
||||
import controllers.LogbookController;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.collections.ObservableList;
|
||||
|
@ -18,6 +19,7 @@ import java.time.format.DateTimeFormatter;
|
|||
public class ViewLogbookScreen {
|
||||
private Stage stage;
|
||||
private LogbookController controller;
|
||||
private AddFlightController addFlightController;
|
||||
|
||||
public ViewLogbookScreen(Stage stage) {
|
||||
this.stage = stage;
|
||||
|
@ -26,7 +28,8 @@ public class ViewLogbookScreen {
|
|||
|
||||
public void display() {
|
||||
Label label = new Label("Fluglogbuch Pegasus");
|
||||
label.setStyle("-fx-font-size: 32px; -fx-font-weight: bold; -fx-text-fill: #431EB9; -fx-font-family: 'Arial Black';");
|
||||
label.setStyle(
|
||||
"-fx-font-size: 32px; -fx-font-weight: bold; -fx-text-fill: #431EB9; -fx-font-family: 'Arial Black';");
|
||||
|
||||
TableView<Flight> table = new TableView<>();
|
||||
table.setStyle("-fx-font-weight: bold;");
|
||||
|
@ -65,16 +68,31 @@ public class ViewLogbookScreen {
|
|||
TableColumn<Flight, String> kommentarCol = new TableColumn<>("Kommentar");
|
||||
kommentarCol.setCellValueFactory(cellData -> cellData.getValue().kommentarProperty());
|
||||
|
||||
table.getColumns().addAll(datumCol, musterCol, abflugortCol, abflugzeitCol, ankunftszeitCol, tToFCol, anzahlLandungenCol, pilotCol, nachtflugCol, kommentarCol);
|
||||
table.getColumns().addAll(datumCol, musterCol, abflugortCol, abflugzeitCol, ankunftszeitCol, tToFCol,
|
||||
anzahlLandungenCol, pilotCol, nachtflugCol, kommentarCol);
|
||||
|
||||
ObservableList<Flight> flightList = controller.getFlightList();
|
||||
table.setItems(flightList);
|
||||
|
||||
/*
|
||||
* Button editBtn = new Button("Bearbeiten");
|
||||
* editBtn.
|
||||
* setStyle("-fx-background-color: #000000; -fx-text-fill: #FFFFFF; -fx-font-weight: bold;"
|
||||
* );
|
||||
* editBtn.setOnAction(e -> {
|
||||
* Flight selectedFlight = table.getSelectionModel().getSelectedItem();
|
||||
* controller.editFlight(selectedFlight);
|
||||
* });
|
||||
*/
|
||||
|
||||
Button editBtn = new Button("Bearbeiten");
|
||||
editBtn.setStyle("-fx-background-color: #000000; -fx-text-fill: #FFFFFF; -fx-font-weight: bold;");
|
||||
editBtn.setOnAction(e -> {
|
||||
Flight selectedFlight = table.getSelectionModel().getSelectedItem();
|
||||
controller.editFlight(selectedFlight);
|
||||
if (selectedFlight != null) {
|
||||
AddFlightScreen addFlightScreen = new AddFlightScreen(stage, selectedFlight);
|
||||
addFlightScreen.display();
|
||||
}
|
||||
});
|
||||
|
||||
Button backButton = new Button("Zurück");
|
||||
|
|
Loading…
Reference in New Issue