Got the basic functionally done on the flight point editor. Currently will change the vaule although a few bugs in the validation aspects.

This commit is contained in:
Liam Beckett
2016-09-24 16:08:41 +12:00
parent f7d1e688fa
commit 5f8e2f2481
8 changed files with 606 additions and 353 deletions
@@ -3,8 +3,11 @@ package seng202.group9.GUI;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.stage.Stage;
import seng202.group9.Controller.Dataset;
import seng202.group9.Controller.Session;
import seng202.group9.Core.FlightPoint;
/**
@@ -22,7 +25,8 @@ public class FlightEditorController extends Controller{
TextField fLatitudeEdit;
@FXML
TextField fLongitudeEdit;
@FXML
private Button flightEditButton;
//Set an empty Dataset to be assigned later
private Dataset theDataSet = null;
@@ -32,30 +36,41 @@ public class FlightEditorController extends Controller{
* Takes in values from the GUI the user has typed in.
* @see Dataset
*/
public void editFlight(FlightPoint flightPoint) {
public void editFlight() {
//Tries to add a new airport and clears the fields to their initial state if successful.
//Otherwise an error message will pop up with what is wrong with the manual data.
try {
fNameEdit.setText(flightPoint.getName());
fTypeEdit.setText(flightPoint.getType());
fAltitudeEdit.setText(Double.toString(flightPoint.getAltitude()));
fLatitudeEdit.setText(Double.toString(flightPoint.getLatitude()));
fLongitudeEdit.setText(Double.toString(flightPoint.getLongitude()));
Session session = getParent().getSession();
int flightPointID = session.getCurrentFlightPointID();
int flightPathID = session.getCurrentFlightPathID();
theDataSet.editFlightPoint(
flightPoint,
theDataSet.editFlight(
theDataSet.getFlightPointDictionary().get(flightPointID),
fNameEdit.getText(),
fTypeEdit.getText(),
fAltitudeEdit.getText(),
fLatitudeEdit.getText(),
fLongitudeEdit.getText()
);
session.setCurrentFlightPointID(flightPointID);
fNameEdit.clear();
fTypeEdit.clear();
fAltitudeEdit.clear();
fLatitudeEdit.clear();
fLongitudeEdit.clear();
Alert alert = new Alert(Alert.AlertType.INFORMATION);
alert.setTitle("Flight Path Edit Successful");
alert.setHeaderText("Flight Point Edited!");
alert.setContentText("Your flight point has been updated in the database.");
alert.showAndWait();
Stage stage = (Stage) flightEditButton.getScene().getWindow();
stage.close();
} catch ( Exception e ) {
e.printStackTrace();
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Flight Data Error");
alert.setHeaderText("Error editing a flight point.");
@@ -64,8 +79,22 @@ public class FlightEditorController extends Controller{
}
}
public void loadValues(){
}
public void load() {
theDataSet = getParent().getCurrentDataset();
Session session = getParent().getSession();
int flightPointID = session.getCurrentFlightPointID();
FlightPoint flightPoint = theDataSet.getFlightPointDictionary().get(flightPointID);
fNameEdit.setText(flightPoint.getName());
fTypeEdit.setText(flightPoint.getType());
fAltitudeEdit.setText(Double.toString(flightPoint.getAltitude()));
fLatitudeEdit.setText(Double.toString(flightPoint.getLatitude()));
fLongitudeEdit.setText(Double.toString(flightPoint.getLongitude()));
}
}
@@ -10,6 +10,7 @@ import javafx.scene.input.MouseEvent;
import seng202.group9.Controller.DataException;
import seng202.group9.Controller.Dataset;
import seng202.group9.Controller.SceneCode;
import seng202.group9.Controller.Session;
import seng202.group9.Core.FlightPath;
import seng202.group9.Core.FlightPoint;
@@ -144,8 +145,6 @@ public class FlightRDController extends Controller {
* Will take the inputs from the text fields and adds the point to the current flight path.
*/
public void addFlightPoint() {
ArrayList<FlightPath> flightPaths;
flightPaths = theDataSet.getFlightPaths();
try {
theDataSet.addFlightPointToPath(currentPathId,
@@ -168,8 +167,7 @@ public class FlightRDController extends Controller {
flightLegDistBox.clear();
flightTotDistBox.clear();
ArrayList<FlightPoint> flightPoints = flightPaths.get(currentPathIndex).getFlight();
flightTableView.setItems(FXCollections.observableArrayList(flightPoints));
updateTable(currentPathIndex);
} catch ( Exception e ) {
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Flight Point Data Error");
@@ -212,25 +210,22 @@ public class FlightRDController extends Controller {
currentPathIndex = theDataSet.getFlightPaths().indexOf(theDataSet.getFlightPathDictionary().get(pathID));
ArrayList<FlightPath> flightPaths;
flightPaths = theDataSet.getFlightPaths();
ArrayList<FlightPoint> flightPoints = flightPaths.get(currentPathIndex).getFlight();
flightTableView.setItems(FXCollections.observableArrayList(flightPoints));
updateTable(currentPathIndex);
}
public void editPoint() {
FlightPoint toEdit = flightTableView.getSelectionModel().getSelectedItem();
int pathID;
try {
pathID = toEdit.getIndex();
Session session = getParent().getSession();
session.setCurrentFlightPointID(toEdit.getID());
session.setCurrentFlightPathtID(currentPathId);
} catch (DataException e) {
e.printStackTrace();
System.out.println("Point is Uneditable as the Index ID is not set.");
return;
}
ArrayList<FlightPath> flightPaths = theDataSet.getFlightPaths();
createPopUpStage(SceneCode.FLIGHT_EDITOR, 600, 289);
flightTableView.setItems(FXCollections.observableArrayList(flightPaths.get(currentPathIndex).getFlight()));
updateTable(currentPathIndex);
}
/**
@@ -249,6 +244,14 @@ public class FlightRDController extends Controller {
flightPathListView();
}
public void updateTable(int currentPathIndex) {
ArrayList<FlightPath> flightPaths;
flightPaths = theDataSet.getFlightPaths();
ArrayList<FlightPoint> flightPoints = flightPaths.get(currentPathIndex).getFlight();
flightTableView.setItems(FXCollections.observableArrayList(flightPoints));
flightTableView.refresh();
}
/**
* Will link to the flight analyser when implemented.
*/