diff --git a/README.txt b/README.txt index 11e2cd8..8d001f0 100644 --- a/README.txt +++ b/README.txt @@ -16,6 +16,9 @@ Run java -jar seng202_2016_team9_phase2.jar Necessary Files: /res/userdb.db +To not have userdb.db clash problems run: +git update-index --assume-unchanged res/userdb.db + Getting started: The application is shipped with all the example data files pre loaded into the database. If the user wants add more data from a file then they can select a file to import using File -> Import where data is the type of data you are diff --git a/src/main/java/seng202/group9/Controller/App.java b/src/main/java/seng202/group9/Controller/App.java index dae161d..bc481ea 100644 --- a/src/main/java/seng202/group9/Controller/App.java +++ b/src/main/java/seng202/group9/Controller/App.java @@ -33,20 +33,20 @@ public class App extends Application private VBox mainContainer = null; private Session session = null; private MenuController menuController = null; - - public static void main( String[] args ) - { - launch(args); - } + + public static void main( String[] args ) + { + launch(args); + } public Stage getPrimaryStage() { return primaryStage; } /** - * Starts the application - * @param primaryStage main "stage" of the program - */ + * Starts the application + * @param primaryStage main "stage" of the program + */ @Override public void start(Stage primaryStage) { this.primaryStage = primaryStage; diff --git a/src/main/java/seng202/group9/Controller/Dataset.java b/src/main/java/seng202/group9/Controller/Dataset.java index d8520e8..f8b0334 100644 --- a/src/main/java/seng202/group9/Controller/Dataset.java +++ b/src/main/java/seng202/group9/Controller/Dataset.java @@ -27,6 +27,7 @@ public class Dataset { private LinkedHashMap airportDictionary; private LinkedHashMap routeDictionary; private LinkedHashMap flightPathDictionary; + private LinkedHashMap flightPointDictionary; private LinkedHashMap countryDictionary; private LinkedHashMap cityDictionary; @@ -50,6 +51,7 @@ public class Dataset { this.countryDictionary = new LinkedHashMap();; this.cityDictionary = new LinkedHashMap();; this.flightPathDictionary = new LinkedHashMap(); + this.flightPointDictionary = new LinkedHashMap(); if (action == getExisting){ updateDataset(); //after this make connections. ie filling in the country.cities airports.routes etc @@ -668,10 +670,9 @@ public class Dataset { while(IDResult.next()){ nextID = Integer.parseInt(IDResult.getString("seq")) + 1;//for some reason sqlite3 stores incremental values as a string... } - System.out.println(nextID); stmt.close(); stmt = c.createStatement(); - //ADDED + String firstPt = flightPointsToImport.get(0).getName(); String lastPt = flightPointsToImport.get(flightPointsToImport.size() - 1).getName(); FlightPath flightPathToAdd = new FlightPath(firstPt, lastPt); @@ -681,7 +682,7 @@ public class Dataset { stmt.execute(insertFlightPathQuery); stmt.close(); stmt = c.createStatement(); - int flightPathId = 0; + int flightPathId = 1; String getLastestIndex = "SELECT * FROM `sqlite_sequence` WHERE `name` = \"" + this.name.replace("\"", "\"\"") + "_Flight_Path\" LIMIT 1;"; ResultSet lastestIdResult = stmt.executeQuery(getLastestIndex); @@ -692,9 +693,9 @@ public class Dataset { lastestIdResult.close(); stmt = c.createStatement(); flightPathToAdd.setID(flightPathId); - //ADDED + String insertFlightPointQuery = "INSERT INTO `" + this.name + "_Flight_Points` (`Index_ID`, `Name`, `Type`," + - " `Altitude`, `Latitude`, `Longitude`, `Order`) VALUES "; + " `Altitude`, `Latitude`, `Longitude`) VALUES "; int numOfFlights = 0; for (int i = 0; i < flightPointsToImport.size(); i ++){ String flightPointIdentifier = flightPointsToImport.get(i).getType() + flightPointsToImport.get(i).getName() + @@ -707,17 +708,18 @@ public class Dataset { double flightLatitude = flightPointsToImport.get(i).getLatitude(); double flightLongitude = flightPointsToImport.get(i).getLongitude(); //insert import into database - if (numOfFlights > 0){ + if (numOfFlights > 0) { insertFlightPointQuery += ","; } insertFlightPointQuery += "(" + flightPathId +", \""+ flightName +"\", \"" + flightType + "\", "+ flightAltitude + ", " + - "" + flightLatitude + ", " + flightLongitude + ", "+numOfFlights+")"; + "" + flightLatitude + ", " + flightLongitude + ")"; flightPointsToImport.get(i).setID(nextID); flightPointsToImport.get(i).setIndexID(flightPathId); //add data to dataset array. //this is placed after incase the database messes up flightPathToAdd.addFlightPoint(flightPointsToImport.get(i)); //routeDictionary.put(routeIdentifier, flightsToImport.get(i)); + flightPointDictionary.put(nextID, flightPointsToImport.get(i)); nextID++; numOfFlights++; //} @@ -729,7 +731,6 @@ public class Dataset { c.close(); flightPaths.add(flightPathToAdd); - System.out.println(flightPathToAdd.getFlightPoints().get(0).getID()); updateFlightPointInfo(flightPathToAdd); flightPathDictionary.put(flightPathToAdd.getID(), flightPathToAdd); } catch ( Exception e ) { @@ -758,7 +759,6 @@ public class Dataset { //create Airline country link for (Airline airline: airlines){ airlineByIATA.put(airline.getIATA(), airline); - //System.out.println(airline.getAlias()); airline.setRoutes(new ArrayList()); airline.setCountry(countryDictionary.get(airline.getCountryName())); Country country = countryDictionary.get(airline.getCountryName()); @@ -1228,21 +1228,21 @@ public class Dataset { c = DriverManager.getConnection("jdbc:sqlite:res/userdb.db"); stmt = c.createStatement(); - String flightPointIDQuery = "SELECT * FROM `sqlite_sequence` WHERE `name` = \""+this.name.replace("\"", "\"\"")+"_Flight_Points\" LIMIT 1;"; - ResultSet pointIDRes= stmt.executeQuery(flightPointIDQuery); - while (pointIDRes.next()){ + String flightPointIDQuery = "SELECT * FROM `sqlite_sequence` WHERE `name` = \"" + this.name + "_Flight_Points\" LIMIT 1;"; + ResultSet pointIDRes = stmt.executeQuery(flightPointIDQuery); + while (pointIDRes.next()) { pointID = Integer.parseInt(pointIDRes.getString("seq")); } stmt.close(); stmt = c.createStatement(); String insertFlightPointQuery = "INSERT INTO `" + this.name + "_Flight_Points` (`Index_ID`, `Name`, `Type`," + - " `Altitude`, `Latitude`, `Longitude`, `Heading`, `Tot_Dist`, `Leg_Dist`, `Via`, `Order`) VALUES "; + " `Altitude`, `Latitude`, `Longitude`, `Heading`, `Tot_Dist`, `Leg_Dist`, `Via`) VALUES "; String flightType = type.replace("\"", "\"\""); String flightName = name.replace("\"", "\"\""); insertFlightPointQuery += "(" + id +", \""+ flightName +"\", \"" + flightType + "\", "+ altitudeVal + ", " + "" + latitudeVal + ", " + longitudeVal + ", " + headingVal + ", " + totalDistVal + ", " + legDistVal + - ", \"" + via + "\", "+index+")"; + ", \"" + via + "\")"; stmt.execute(insertFlightPointQuery); stmt.close(); //move all the points after this forward @@ -1370,14 +1370,10 @@ public class Dataset { try { Class.forName("org.sqlite.JDBC"); c = DriverManager.getConnection("jdbc:sqlite:res/userdb.db"); - //System.out.println(airline.getID()); - String deleteQuery = "DELETE FROM `"+this.name+"_Airline` WHERE `Airline_ID` = " + airline.getID() + ";"; + String deleteQuery = "DELETE FROM `" + this.name + "_Airline` WHERE `Airline_ID` = " + airline.getID() + ";"; stmt = c.createStatement(); - //System.out.println("Airline deleted"); stmt.execute(deleteQuery); - //System.out.println("Airline deleted"); stmt.close(); - //System.out.println("Airline deleted"); stmt = c.createStatement(); //check if number of countries that contain airlines > 0 else delete the country String countCountry = "SELECT COUNT(*) FROM `"+this.name+"_Airline` JOIN `"+this.name+"_Country` ON" + @@ -1605,6 +1601,11 @@ public class Dataset { System.exit(0); } flightPath.getFlightPoints().remove(flightPoint); + try { + flightPointDictionary.remove(flightPoint.getID()); + } catch (DataException e) { + e.printStackTrace(); + } } /** @@ -1696,6 +1697,15 @@ public class Dataset { return flightPathDictionary; } + /** + * returns a flightpoint dictionary with the flights that are associated with this dataset. + * + * @return + */ + public LinkedHashMap getFlightPointDictionary() { + return flightPointDictionary; + } + /** * returns a Country Dictionary with the COuntries that are associated with this dataset. * @return @@ -1823,9 +1833,59 @@ public class Dataset { Connection c = null; Statement stmt = null; + try { Class.forName("org.sqlite.JDBC"); c = DriverManager.getConnection("jdbc:sqlite:res/userdb.db"); + /* + //UPDATE CITY AND COUNTRIES + */ + if (cityDictionary.containsKey(city) && cityDictionary.get(city) != null){ + airport.setCity(cityDictionary.get(city)); + airport.getCity().setCountry(country); + airport.getCity().setTimezone(Double.parseDouble(timezone)); + airport.getCity().setTimeOlson(olson); + //update city in database + stmt = c.createStatement(); + String updateCityQuery = "UPDATE `"+this.name+"_City` SET `Country_Name` = \""+country+"\", " + + "`Timezone` = "+timezone+", `Olson_Timezone` = \""+olson+"\" WHERE `City_Name` = \""+city+"\""; + stmt.execute(updateCityQuery); + stmt.close(); + }else { + City newCity = new City(city, country, Double.parseDouble(timezone), olson); + airport.setCity(newCity); + airport.setCityName(city); + cities.add(newCity); + cityDictionary.put(city, newCity); + //add new City to database + stmt = c.createStatement(); + String addNewCity = "INSERT INTO `"+this.name+"_City` (`City_Name`, `Country_name`, `Timezone`, `Olson_Timezone`) VALUES " + + "(\""+city+"\", \""+country+"\", "+timezone+", \""+olson+"\")"; + stmt.execute(addNewCity); + stmt.close(); + } + + if (countryDictionary.containsKey(country) && countryDictionary.get(country) != null){ + airport.setCountry(countryDictionary.get(country)); + airport.getCountry().setDST(DST); + //update country in database + stmt = c.createStatement(); + String updateCountryQuery = "UPDATE `"+this.name+"_Country` SET `DST` = "+DST+" WHERE `Country_Name` = \""+country+"\""; + stmt.execute(updateCountryQuery); + stmt.close(); + }else{ + Country newCountry = new Country(DST, name); + airport.setCountry(newCountry); + airport.setCountryName(country); + countries.add(newCountry); + countryDictionary.put(country, newCountry); + //add new COuntry to database + stmt = c.createStatement(); + String createCountryQuery = "INSERT INTO `"+this.name+"_Country` (`Country_Name`, `DST`) VALUES (\""+country+"\", \""+DST+"\")"; + stmt.execute(createCountryQuery); + stmt.close(); + } + stmt = c.createStatement(); String query = "UPDATE `"+this.name+"_Airport` SET `Name` = \""+airport.getName().replace("\"", "\"\"")+"\", `City` = \""+airport.getCityName().replace("\"", "\"\"")+"\", " + "`Country` = \""+airport.getCountryName().replace("\"", "\"\"")+"\", `IATA/FFA` = \""+airport.getIATA_FFA().replace("\"", "\"\"")+"\", " + @@ -1881,10 +1941,10 @@ public class Dataset { Class.forName("org.sqlite.JDBC"); c = DriverManager.getConnection("jdbc:sqlite:res/userdb.db"); stmt = c.createStatement(); - String query = "UPDATE `"+this.name+"_Routes` SET `Airline` = \""+route.getAirlineName().replace("\"", "\"\"")+"\", " + - "`Source_Airport` = \""+route.getDepartureAirport().replace("\"", "\"\"")+"\", `Destination_Airport` = \""+route.getArrivalAirport().replace("\"", "\"\"")+"\", " + - "`Codeshare` = \""+route.getCode().replace("\"", "\"\"")+"\", `Stops` = "+route.getStops()+", `Equipment` = \""+route.getEquipment().replace("\"", "\"\"")+"\" " + - "WHERE `Route_ID` = "+route.getID(); + String query = "UPDATE `" + this.name + "_Routes` SET `Airline` = \"" + route.getAirlineName().replace("\"", "\"\"") + "\", " + + "`Source_Airport` = \"" + route.getDepartureAirport().replace("\"", "\"\"") + "\", `Destination_Airport` = \"" + route.getArrivalAirport().replace("\"", "\"\"") + "\", " + + "`Codeshare` = \"" + route.getCode().replace("\"", "\"\"") + "\", `Stops` = " + route.getStops() + ", `Equipment` = \"" + route.getEquipment().replace("\"", "\"\"") + "\" " + + "WHERE `Route_ID` = " + route.getID(); stmt.execute(query); stmt.close(); c.close(); @@ -1919,14 +1979,14 @@ public class Dataset { * @param longitude * @throws DataException */ - public void editFlight(FlightPoint flightPoint, String name, String type, String altitude, String latitude, String longitude) throws DataException{ + public void editFlight(FlightPoint flightPoint, String name, String type, String altitude, String latitude, String longitude) throws DataException { EntryParser entryParser = new EntryParser(); - FlightPoint flightPoint1 = entryParser.parsePoint(name, type, altitude, latitude, longitude); - flightPoint.setName(flightPoint1.getName()); - flightPoint.setType(flightPoint1.getType()); - flightPoint.setAltitude(flightPoint1.getAltitude()); - flightPoint.setLatitude(flightPoint1.getLatitude()); - flightPoint.setLongitude(flightPoint1.getLongitude()); + FlightPoint parsedFlightPoint = entryParser.parsePoint(name, type, altitude, latitude, longitude); + flightPoint.setName(parsedFlightPoint.getName()); + flightPoint.setType(parsedFlightPoint.getType()); + flightPoint.setAltitude(parsedFlightPoint.getAltitude()); + flightPoint.setLatitude(parsedFlightPoint.getLatitude()); + flightPoint.setLongitude(parsedFlightPoint.getLongitude()); Connection c = null; @@ -1960,7 +2020,7 @@ public class Dataset { System.err.println( e.getClass().getName() + ": " + e.getMessage() ); } flightPath.setDepartureAirport(flightPoint.getName()); - }else if (indexOf == flightPath.getFlightPoints().size() - 1){ + } else if (indexOf == flightPath.getFlightPoints().size() - 1) { try { stmt = c.createStatement(); String query = "UPDATE `"+this.name+"_Flight_Path` SET `Destination_Airport` = \""+flightPoint.getName().replace("\"", "\"\"")+"\" " + @@ -1972,7 +2032,7 @@ public class Dataset { } flightPath.setArrivalAirport(flightPoint.getName()); } - updateFlightPointInfo(flightPath); + createDataLinks(); } diff --git a/src/main/java/seng202/group9/Controller/EntryParser.java b/src/main/java/seng202/group9/Controller/EntryParser.java index fbeddf2..18c62cb 100644 --- a/src/main/java/seng202/group9/Controller/EntryParser.java +++ b/src/main/java/seng202/group9/Controller/EntryParser.java @@ -132,18 +132,26 @@ public class EntryParser { } public FlightPoint parsePoint(String name, String type, String altitude, String latitude, String longitude) throws DataException{ - //(airport) name (first and last point) + //name + name = name.toUpperCase(); if (!isLetter(name)) { - throw new DataException("Airport ICAO code must contain only letters"); - } - if (name.length() != 4) { - throw new DataException("Aiport ICAO code must be of length four"); + throw new DataException("ICAO code must contain only letters"); } //type type = type.toUpperCase(); if (!type.equals("APT") && !type.equals("VOR") && !type.equals("FIX") && !type.equals("NDB") && !type.equals("LATLON")){ throw new DataException("Type of flight must be either APT, VOR, FIX, NDB or LATLON"); } + //altitude + double alt; + try{ + alt = Double.parseDouble(altitude); + }catch (NumberFormatException e){ + throw new DataException ("Altitude must be a number"); + } + if (alt < 0 || alt > 50000){ + throw new DataException("Altitude must be between 0 and 50000ft inclusive."); + } //latitude double lat; try{ @@ -164,13 +172,7 @@ public class EntryParser { if (lng > 180 || lng < -180){ throw new DataException("Longitude must be between -180 and 180 inclusive."); } - //altitude - double alt; - try{ - alt = Double.parseDouble(altitude); - }catch (NumberFormatException e){ - throw new DataException ("Altitude must be a number"); - } + FlightPoint parseSuccess = new FlightPoint(type, name, alt, lat, lng); return parseSuccess; } diff --git a/src/main/java/seng202/group9/Controller/SceneCode.java b/src/main/java/seng202/group9/Controller/SceneCode.java index 0489cef..eb6844b 100644 --- a/src/main/java/seng202/group9/Controller/SceneCode.java +++ b/src/main/java/seng202/group9/Controller/SceneCode.java @@ -12,7 +12,8 @@ public enum SceneCode { AIRPORT_DIST_CALC("airport_dist_calc.fxml"), AIRLINE_ADD("airline_add_form.fxml"), AIRLINE_FILTER("airline_filter_form.fxml"), AIRPORT_ADD("airport_add_form.fxml"), AIRPORT_FILTER("airport_filter_form.fxml"), ROUTE_ADD("route_add_form.fxml"), ROUTE_FILTER("route_filter_form.fxml"), AIRLINE_EDIT("airline_edit_form.fxml"), AIRPORT_EDIT("airport_edit_form.fxml"), - ROUTE_EDIT("route_edit_form.fxml"); + ROUTE_EDIT("route_edit_form.fxml"), FLIGHT_EDITOR("flight_editor_form.fxml"); + private String filePath; diff --git a/src/main/java/seng202/group9/Controller/Session.java b/src/main/java/seng202/group9/Controller/Session.java index 5b6502a..71a3dc5 100644 --- a/src/main/java/seng202/group9/Controller/Session.java +++ b/src/main/java/seng202/group9/Controller/Session.java @@ -3,6 +3,8 @@ package seng202.group9.Controller; import javafx.collections.ObservableList; import seng202.group9.Core.Airline; +import seng202.group9.Core.FlightPoint; + import java.io.Serializable; import java.util.HashMap; @@ -13,6 +15,8 @@ import java.util.HashMap; public class Session implements Serializable { private SceneCode sceneDisplayed; + private int currentFlightPointID; + private int currentFlightPathID; private HashMap filteredAirlines; private HashMap filteredAirports; private HashMap filteredRoutes; @@ -78,6 +82,7 @@ public class Session implements Serializable { return filteredRoutes; } + public void setAirlineToEdit(String name) { this.airlineToEdit = name; } @@ -101,4 +106,36 @@ public class Session implements Serializable { public void setRouteToEdit(String route) { this.routeToEdit = route; } + + /** + * sets the current flight point + * @param currentFlightPointID + */ + public void setCurrentFlightPointID(int currentFlightPointID) { + this.currentFlightPointID = currentFlightPointID; + } + + /** + * gets the current flight point + * @return + */ + public int getCurrentFlightPointID() { + return currentFlightPointID; + } + /** + * sets the current flight point + * @param currentFlightPathID + */ + public void setCurrentFlightPathtID(int currentFlightPathID) { + this.currentFlightPathID = currentFlightPathID; + } + + /** + * gets the current flight point + * @return + */ + public int getCurrentFlightPathID() { + return currentFlightPathID; + } + } diff --git a/src/main/java/seng202/group9/Core/FlightPath.java b/src/main/java/seng202/group9/Core/FlightPath.java index 1ec0931..0f29d90 100644 --- a/src/main/java/seng202/group9/Core/FlightPath.java +++ b/src/main/java/seng202/group9/Core/FlightPath.java @@ -216,4 +216,4 @@ public class FlightPath { flightPoints.get(i).setHeading((int)heading); } } -} +} \ No newline at end of file diff --git a/src/main/java/seng202/group9/GUI/Controller.java b/src/main/java/seng202/group9/GUI/Controller.java index e7d1869..0c3220e 100644 --- a/src/main/java/seng202/group9/GUI/Controller.java +++ b/src/main/java/seng202/group9/GUI/Controller.java @@ -113,4 +113,4 @@ public abstract class Controller implements Initializable{ } -} +} \ No newline at end of file diff --git a/src/main/java/seng202/group9/GUI/FlightEditorController.java b/src/main/java/seng202/group9/GUI/FlightEditorController.java new file mode 100644 index 0000000..78f0b77 --- /dev/null +++ b/src/main/java/seng202/group9/GUI/FlightEditorController.java @@ -0,0 +1,99 @@ +package seng202.group9.GUI; + +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; + +/** + * Controller for the Flights Edit Point Pop up Scene. + * 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; + @FXML + private Button flightEditButton; + + //Set an empty Dataset to be assigned later + private Dataset theDataSet = null; + + /** + * Edits a single flight entry in the database. + * Takes in values from the field the user right clicked. + * @see Dataset + */ + public void editFlight() { + //Data is pre-loaded into the text fields and any accepted changes will be implemented. + //Otherwise an error message will pop up with what is wrong with edit + try { + Session session = getParent().getSession(); + int flightPointID = session.getCurrentFlightPointID(); + + 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."); + alert.setContentText(e.getMessage()); + alert.showAndWait(); + } + } + + /** + * Loader which is used to load the selected information into the text fields for editing. + */ + 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())); + } + +} + diff --git a/src/main/java/seng202/group9/GUI/FlightRDController.java b/src/main/java/seng202/group9/GUI/FlightRDController.java index 7cf4e8a..23a8e2c 100644 --- a/src/main/java/seng202/group9/GUI/FlightRDController.java +++ b/src/main/java/seng202/group9/GUI/FlightRDController.java @@ -9,6 +9,8 @@ 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.Controller.Session; import seng202.group9.Core.FlightPath; import seng202.group9.Core.FlightPoint; @@ -20,7 +22,6 @@ import java.util.LinkedHashMap; * Controller for the Flights Raw Data Scene. * Created by Liam Beckett on 13/09/2016. */ - public class FlightRDController extends Controller { private Dataset theDataSet = null; @@ -143,8 +144,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 flightPaths; - flightPaths = theDataSet.getFlightPaths(); try { theDataSet.addFlightPointToPath(currentPathId, @@ -167,14 +166,12 @@ public class FlightRDController extends Controller { flightLegDistBox.clear(); flightTotDistBox.clear(); - ArrayList 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"); alert.setHeaderText("Error adding a custom flight point entry."); alert.setContentText(e.getMessage()); - } } @@ -203,7 +200,7 @@ public class FlightRDController extends Controller { pathID = toDelete.getIndex(); } catch (DataException e) { e.printStackTrace(); - System.out.println("Point is Undeletable as the Index ID is not set."); + System.err.println("Point is Undeletable as the Index ID is not set."); return; } LinkedHashMap flightPathDict = theDataSet.getFlightPathDictionary(); @@ -212,12 +209,27 @@ public class FlightRDController extends Controller { currentPathIndex = theDataSet.getFlightPaths().indexOf(theDataSet.getFlightPathDictionary().get(pathID)); - ArrayList flightPaths; - flightPaths = theDataSet.getFlightPaths(); - ArrayList flightPoints = flightPaths.get(currentPathIndex).getFlight(); - flightTableView.setItems(FXCollections.observableArrayList(flightPoints)); + updateTable(currentPathIndex); } + /** + * Loads the pop up for the edit data scene and updates the table when the window is closed. + */ + public void editPoint() { + FlightPoint toEdit = flightTableView.getSelectionModel().getSelectedItem(); + try { + Session session = getParent().getSession(); + session.setCurrentFlightPointID(toEdit.getID()); + session.setCurrentFlightPathtID(currentPathId); + } catch (DataException e) { + e.printStackTrace(); + System.err.println("Point is Uneditable as the Index ID is not set."); + return; + } + createPopUpStage(SceneCode.FLIGHT_EDITOR, 600, 289); + updateTable(currentPathIndex); + + } /** * Removes the selected path from the list view of paths and from the database. */ @@ -234,10 +246,22 @@ public class FlightRDController extends Controller { flightPathListView(); } + /** + * Updates the table so that when the database is changed (deleted or edited) it still shows the correct data values. + * @param currentPathIndex The index of the current path in the Path array list. + */ + private void updateTable(int currentPathIndex) { + ArrayList flightPaths; + flightPaths = theDataSet.getFlightPaths(); + ArrayList flightPoints = flightPaths.get(currentPathIndex).getFlight(); + flightTableView.setItems(FXCollections.observableArrayList(flightPoints)); + flightTableView.refresh(); + } + /** * Will link to the flight analyser when implemented. */ - public void flightAnalyser(){ + private void flightAnalyser(){ JOptionPane.showMessageDialog(null, "This is not Implemented yet"); } diff --git a/src/main/resources/flight_editor_form.fxml b/src/main/resources/flight_editor_form.fxml new file mode 100644 index 0000000..31b0702 --- /dev/null +++ b/src/main/resources/flight_editor_form.fxml @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +