Atempting to get the editor to work for the flight raw data points (Currently broken)

This commit is contained in:
Liam Beckett
2016-09-23 14:45:51 +12:00
parent c1b338e35c
commit 3d6dd0c2cb
8 changed files with 221 additions and 18 deletions
@@ -1,9 +1,17 @@
package seng202.group9.GUI;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.layout.VBox;
import javafx.stage.Modality;
import javafx.stage.Stage;
import seng202.group9.Controller.App;
import seng202.group9.Controller.SceneCode;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.ResourceBundle;
@@ -50,6 +58,45 @@ public abstract class Controller implements Initializable{
}
}
/**
* Creates a popup window with a specific fxml scene
* @param scene
* @param width
* @param height
*/
public Stage createPopUpStage(SceneCode scene, int width, int height) {
FXMLLoader loader = new FXMLLoader();
InputStream in = getClass().getClassLoader().getResourceAsStream(scene.getFilePath());
Parent page = null;
try {
page = loader.load(in);
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
//set contorller and call default calls
Controller controller = (Controller) loader.getController();
controller.setApp(parent);
controller.load();
controller.loadOnce();
//create a new stage to popup
Stage popupStage = new Stage();
popupStage.initModality(Modality.APPLICATION_MODAL);
//inner layout constraints
VBox container = new VBox();
container.getChildren().add(page);
Scene popupScene = new Scene(container, width, height);
//show
popupStage.setScene(popupScene);
popupStage.showAndWait();
return popupStage;
}
/**
* Functions here will only load once and after the load function.
*/
@@ -66,4 +113,4 @@ public abstract class Controller implements Initializable{
}
}
}
@@ -0,0 +1,70 @@
package seng202.group9.GUI;
import javafx.fxml.FXML;
import javafx.scene.control.Alert;
import javafx.scene.control.TextField;
import seng202.group9.Controller.Dataset;
import seng202.group9.Core.FlightPoint;
/**
* Created by Liam Beckett on 23/09/2016.
*/
public class FlightEditorController extends Controller{
//Setting up text fields for adding data
@FXML
TextField fNameEdit;
@FXML
TextField fTypeEdit;
@FXML
TextField fAltitudeEdit;
@FXML
TextField fLatitudeEdit;
@FXML
TextField fLongitudeEdit;
//Set an empty Dataset to be assigned later
private Dataset theDataSet = null;
/**
* Adds a single airport entry in the database.
* Takes in values from the GUI the user has typed in.
* @see Dataset
*/
public void editFlight(FlightPoint flightPoint) {
//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()));
theDataSet.editFlightPoint(
flightPoint,
fNameEdit.getText(),
fTypeEdit.getText(),
fAltitudeEdit.getText(),
fLatitudeEdit.getText(),
fLongitudeEdit.getText()
);
fNameEdit.clear();
fTypeEdit.clear();
fAltitudeEdit.clear();
fLatitudeEdit.clear();
fLongitudeEdit.clear();
} catch ( Exception e ) {
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Flight Data Error");
alert.setHeaderText("Error editing a flight point.");
alert.setContentText(e.getMessage());
alert.showAndWait();
}
}
public void load() {
theDataSet = getParent().getCurrentDataset();
}
}
@@ -9,6 +9,7 @@ import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.input.MouseEvent;
import seng202.group9.Controller.DataException;
import seng202.group9.Controller.Dataset;
import seng202.group9.Controller.SceneCode;
import seng202.group9.Core.FlightPath;
import seng202.group9.Core.FlightPoint;
@@ -174,7 +175,6 @@ public class FlightRDController extends Controller {
alert.setTitle("Flight Point Data Error");
alert.setHeaderText("Error adding a custom flight point entry.");
alert.setContentText(e.getMessage());
}
}
@@ -218,6 +218,21 @@ public class FlightRDController extends Controller {
flightTableView.setItems(FXCollections.observableArrayList(flightPoints));
}
public void editPoint() {
FlightPoint toEdit = flightTableView.getSelectionModel().getSelectedItem();
int pathID;
try {
pathID = toEdit.getIndex();
} 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()));
}
/**
* Removes the selected path from the list view of paths and from the database.
*/