Fixed some refactoring issues and implemented delete functions in the GUI

main
Sunguin Peng 9 years ago
parent e3ff9d3bfc
commit 5cc305d896

Binary file not shown.

Binary file not shown.

@ -743,7 +743,7 @@ public class Dataset {
HashMap<String, Airline> airlineByIATA= new HashMap<String, Airline>(); HashMap<String, Airline> airlineByIATA= new HashMap<String, Airline>();
//create Airline country link //create Airline country link
for (Airline airline: airlines){ for (Airline airline: airlines){
airlineByIATA.put(airline.getAlias(), airline); airlineByIATA.put(airline.getIATA(), airline);
//System.out.println(airline.getAlias()); //System.out.println(airline.getAlias());
airline.setCountry(countryDictionary.get(airline.getCountryName())); airline.setCountry(countryDictionary.get(airline.getCountryName()));
} }
@ -834,6 +834,7 @@ public class Dataset {
System.err.println( e.getClass().getName() + ": " + e.getMessage() ); System.err.println( e.getClass().getName() + ": " + e.getMessage() );
System.exit(0); System.exit(0);
} }
createDataLinks();
} }
public void addAirport(String name, String city, String country, String IATA_FFA, String ICAO, String latitude, String longitude, public void addAirport(String name, String city, String country, String IATA_FFA, String ICAO, String latitude, String longitude,
@ -893,6 +894,7 @@ public class Dataset {
System.err.println( e.getClass().getName() + ": " + e.getMessage() ); System.err.println( e.getClass().getName() + ": " + e.getMessage() );
System.exit(0); System.exit(0);
} }
createDataLinks();
} }
public void addCity(City city){ public void addCity(City city){
@ -1018,6 +1020,7 @@ public class Dataset {
System.err.println( e.getClass().getName() + ": " + e.getMessage() ); System.err.println( e.getClass().getName() + ": " + e.getMessage() );
System.exit(0); System.exit(0);
} }
createDataLinks();
} }
@ -1136,10 +1139,14 @@ public class Dataset {
try { try {
Class.forName("org.sqlite.JDBC"); Class.forName("org.sqlite.JDBC");
c = DriverManager.getConnection("jdbc:sqlite:res/userdb.db"); 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(); stmt = c.createStatement();
//System.out.println("Airline deleted");
stmt.execute(deleteQuery); stmt.execute(deleteQuery);
//System.out.println("Airline deleted");
stmt.close(); stmt.close();
//System.out.println("Airline deleted");
stmt = c.createStatement(); stmt = c.createStatement();
//check if number of countries that contain airlines > 0 else delete the country //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" + String countCountry = "SELECT COUNT(*) FROM `"+this.name+"_Airline` JOIN `"+this.name+"_Country` ON" +
@ -1152,6 +1159,7 @@ public class Dataset {
} }
countCountryRes.close(); countCountryRes.close();
stmt.close(); stmt.close();
//check if number of counties that contain airports > 0 else delete the country //check if number of counties that contain airports > 0 else delete the country
String countCountryA = "SELECT COUNT(*) FROM `"+this.name+"_Airport` JOIN `"+this.name+"_Country` ON" + String countCountryA = "SELECT COUNT(*) FROM `"+this.name+"_Airport` JOIN `"+this.name+"_Country` ON" +
" `"+this.name+"_Country`.`Country_Name` = `"+this.name+"_Airport`.`Country`" + " `"+this.name+"_Country`.`Country_Name` = `"+this.name+"_Airport`.`Country`" +
@ -1172,7 +1180,7 @@ public class Dataset {
c.close(); c.close();
} catch ( Exception e ) { } catch ( Exception e ) {
System.err.println( e.getClass().getName() + ": " + e.getMessage() ); System.err.println( e.getClass().getName() + ": " + e.getMessage() );
System.exit(0); //System.exit(0);
} }
airlines.remove(airline); airlines.remove(airline);
} }

@ -122,7 +122,7 @@ public class Route {
} }
//JavaDoc needed //JavaDoc needed
public int getAirlineID() throws DataException { public int getAirlineID() throws DataException {
if (this.airline != null) { if (this.getAirline() != null) {
return this.getAirline().getID(); return this.getAirline().getID();
}else { }else {
return 0; return 0;
@ -240,7 +240,7 @@ public class Route {
*/ */
public void hasDuplicate(Route route) throws DataException{ public void hasDuplicate(Route route) throws DataException{
//routeAirline + routeSourceAirport + routeArrvAirport + routeCodeShare + routeStops + routeEquip //routeAirline + routeSourceAirport + routeArrvAirport + routeCodeShare + routeStops + routeEquip
if (route.getAirline().equals(this.airline) && route.getDepartureAirport().equals(this.departureAirport) if (route.getAirlineName().equals(this.airlineName) && route.getDepartureAirport().equals(this.departureAirport)
&& route.getArrivalAirport().equals(this.arrivalAirport) && route.getCode().equals(this.codeShare) && route.getArrivalAirport().equals(this.arrivalAirport) && route.getCode().equals(this.codeShare)
&& route.getStops() == this.stops && route.getEquipment().equals(this.equipment)){ && route.getStops() == this.stops && route.getEquipment().equals(this.equipment)){
throw new DataException("This Route already exists."); throw new DataException("This Route already exists.");

@ -1,25 +1,19 @@
package seng202.group9.GUI; package seng202.group9.GUI;
import javafx.collections.FXCollections; import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.*; import javafx.scene.control.*;
import javafx.scene.control.cell.PropertyValueFactory; import javafx.scene.control.cell.PropertyValueFactory;
import seng202.group9.Controller.App;
import seng202.group9.Controller.Dataset; import seng202.group9.Controller.Dataset;
import seng202.group9.Core.Airline; import seng202.group9.Core.Airline;
import java.net.URL;
import java.util.ResourceBundle;
/** /**
* Created by Sunguin on 2016/09/13. * Created by Sunguin on 2016/09/13.
*/ */
public class AirlineRDController extends Controller { public class AirlineRDController extends Controller {
@FXML @FXML
private TableView<Airline> tableView; private TableView<Airline> tableViewAirlineRD;
@FXML @FXML
private TableColumn<Airline, String> airlIDcol; private TableColumn<Airline, String> airlIDcol;
@FXML @FXML
@ -73,7 +67,7 @@ public class AirlineRDController extends Controller {
airlCallsignBox.clear(); airlCallsignBox.clear();
airlCountryBox.clear(); airlCountryBox.clear();
airlActiveCBox.getSelectionModel().clearSelection(); airlActiveCBox.getSelectionModel().clearSelection();
tableView.setItems(FXCollections.observableArrayList(theDataSet.getAirlines())); tableViewAirlineRD.setItems(FXCollections.observableArrayList(theDataSet.getAirlines()));
} catch ( Exception e ) { } catch ( Exception e ) {
Alert alert = new Alert(Alert.AlertType.ERROR); Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Airline Data Error"); alert.setTitle("Airline Data Error");
@ -95,9 +89,15 @@ public class AirlineRDController extends Controller {
airlActivecol.setCellValueFactory(new PropertyValueFactory<Airline, String>("Active")); airlActivecol.setCellValueFactory(new PropertyValueFactory<Airline, String>("Active"));
theDataSet = getParent().getCurrentDataset(); theDataSet = getParent().getCurrentDataset();
tableView.setItems(FXCollections.observableArrayList(theDataSet.getAirlines())); tableViewAirlineRD.setItems(FXCollections.observableArrayList(theDataSet.getAirlines()));
//ObservableList<String> activeOptions= FXCollections.observableArrayList("Y", "N");
airlActiveCBox.setValue("Y");
airlActiveCBox.getItems().addAll("Y", "N"); airlActiveCBox.getItems().addAll("Y", "N");
} }
public void deleteAirline() {
Airline toDelete = tableViewAirlineRD.getSelectionModel().getSelectedItem();
theDataSet.deleteAirline(toDelete);
tableViewAirlineRD.setItems(FXCollections.observableArrayList(theDataSet.getAirlines()));
}
} }

@ -90,26 +90,10 @@ public class AirportRDController extends Controller{
airpDSTcol.setCellValueFactory(new PropertyValueFactory<Airport, String>("DST")); airpDSTcol.setCellValueFactory(new PropertyValueFactory<Airport, String>("DST"));
airpTzcol.setCellValueFactory(new PropertyValueFactory<Airport, String>("Tz")); airpTzcol.setCellValueFactory(new PropertyValueFactory<Airport, String>("Tz"));
// airpTimezonecol.setCellFactory(new Callback<TableColumn<Airport, String>, TableCell<Airport, String>>() {
//
// @Override
// public TableCell<Airport, City> call(TableColumn<Airport, City> param) {
// TableCell<Airport, City> timeZoneCell = new TableCell<Airport, City>() {
// @Override
// protected void updateItem(City timezone, boolean empty) {
// if (timezone != null) {
// Label timeZoneLabel = new Label(timezone.getTimeOlson());
// setGraphic(timeZoneLabel);
// }
// }
// };
//
// return timeZoneCell;
// }
// });
theDataSet = getParent().getCurrentDataset(); theDataSet = getParent().getCurrentDataset();
tableViewAirportRD.setItems(FXCollections.observableArrayList(theDataSet.getAirports())); tableViewAirportRD.setItems(FXCollections.observableArrayList(theDataSet.getAirports()));
airpDSTCBox.setValue("E");
airpDSTCBox.getItems().addAll("E", "A", "S", "O", "Z", "N", "U"); airpDSTCBox.getItems().addAll("E", "A", "S", "O", "Z", "N", "U");
} }
@ -147,4 +131,9 @@ public class AirportRDController extends Controller{
} }
} }
public void deleteAirport(){
Airport toDelete = tableViewAirportRD.getSelectionModel().getSelectedItem();
theDataSet.deleteAirport(toDelete);
tableViewAirportRD.setItems(FXCollections.observableArrayList(theDataSet.getAirports()));
}
} }

@ -5,6 +5,7 @@ import javafx.fxml.FXML;
import javafx.scene.control.*; import javafx.scene.control.*;
import javafx.scene.control.cell.PropertyValueFactory; import javafx.scene.control.cell.PropertyValueFactory;
import seng202.group9.Controller.App; import seng202.group9.Controller.App;
import seng202.group9.Controller.DataException;
import seng202.group9.Controller.Dataset; import seng202.group9.Controller.Dataset;
import seng202.group9.Core.Route; import seng202.group9.Core.Route;
@ -66,12 +67,19 @@ public class RouteRDController extends Controller {
rStopsBox.clear(); rStopsBox.clear();
rEquipmentBox.clear(); rEquipmentBox.clear();
tableViewRouteRD.setItems(FXCollections.observableArrayList(theDataSet.getRoutes())); tableViewRouteRD.setItems(FXCollections.observableArrayList(theDataSet.getRoutes()));
} catch ( Exception e ) { } catch (DataException e){
Alert alert = new Alert(Alert.AlertType.ERROR); Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Route Data Error"); alert.setTitle("Route Data Error");
alert.setHeaderText("Error adding a custom route entry."); alert.setHeaderText("Error adding a custom route entry.");
alert.setContentText(e.getMessage()); alert.setContentText(e.getMessage());
alert.showAndWait(); alert.showAndWait();
} catch ( Exception e ) {
e.printStackTrace();
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Route Error");
alert.setHeaderText("Error adding a custom route entry.");
alert.setContentText(e.getMessage());
alert.showAndWait();
} }
} }
@ -89,6 +97,14 @@ public class RouteRDController extends Controller {
theDataSet = getParent().getCurrentDataset(); theDataSet = getParent().getCurrentDataset();
tableViewRouteRD.setItems(FXCollections.observableArrayList(theDataSet.getRoutes())); tableViewRouteRD.setItems(FXCollections.observableArrayList(theDataSet.getRoutes()));
rCodeshareCBox.setValue("");
rCodeshareCBox.getItems().addAll("Y", ""); rCodeshareCBox.getItems().addAll("Y", "");
}
public void deleteRoute(){
Route toDelete = tableViewRouteRD.getSelectionModel().getSelectedItem();
theDataSet.deleteRoute(toDelete);
tableViewRouteRD.setItems(FXCollections.observableArrayList(theDataSet.getRoutes()));
} }
} }

@ -3,7 +3,9 @@
<?import javafx.geometry.Insets?> <?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?> <?import javafx.scene.control.Button?>
<?import javafx.scene.control.ComboBox?> <?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.ContextMenu?>
<?import javafx.scene.control.Label?> <?import javafx.scene.control.Label?>
<?import javafx.scene.control.MenuItem?>
<?import javafx.scene.control.TableColumn?> <?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?> <?import javafx.scene.control.TableView?>
<?import javafx.scene.control.TextField?> <?import javafx.scene.control.TextField?>
@ -34,7 +36,7 @@
<Button layoutX="654.0" layoutY="526.0" mnemonicParsing="false" onAction="#addAirlineSingle" prefHeight="25.0" prefWidth="125.0" text="Add" /> <Button layoutX="654.0" layoutY="526.0" mnemonicParsing="false" onAction="#addAirlineSingle" prefHeight="25.0" prefWidth="125.0" text="Add" />
<Pane layoutX="14.0" layoutY="57.0" prefHeight="403.0" prefWidth="765.0"> <Pane layoutX="14.0" layoutY="57.0" prefHeight="403.0" prefWidth="765.0">
<children> <children>
<TableView fx:id="tableView" layoutX="1.0" prefHeight="403.0" prefWidth="765.0"> <TableView fx:id="tableViewAirlineRD" layoutX="1.0" prefHeight="403.0" prefWidth="765.0">
<columns> <columns>
<TableColumn fx:id="airlIDcol" prefWidth="83.0" text="Airline ID" /> <TableColumn fx:id="airlIDcol" prefWidth="83.0" text="Airline ID" />
<TableColumn fx:id="airlNamecol" prefWidth="450.0" text="Name" /> <TableColumn fx:id="airlNamecol" prefWidth="450.0" text="Name" />
@ -45,6 +47,13 @@
<TableColumn fx:id="airlCountrycol" minWidth="0.0" prefWidth="200.0" text="Country" /> <TableColumn fx:id="airlCountrycol" minWidth="0.0" prefWidth="200.0" text="Country" />
<TableColumn fx:id="airlActivecol" minWidth="8.0" prefWidth="66.0" text="Active" /> <TableColumn fx:id="airlActivecol" minWidth="8.0" prefWidth="66.0" text="Active" />
</columns> </columns>
<contextMenu>
<ContextMenu>
<items>
<MenuItem mnemonicParsing="false" onAction="#deleteAirline" text="Delete" />
</items>
</ContextMenu>
</contextMenu>
</TableView> </TableView>
</children> </children>
</Pane> </Pane>

@ -3,7 +3,9 @@
<?import javafx.geometry.Insets?> <?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?> <?import javafx.scene.control.Button?>
<?import javafx.scene.control.ComboBox?> <?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.ContextMenu?>
<?import javafx.scene.control.Label?> <?import javafx.scene.control.Label?>
<?import javafx.scene.control.MenuItem?>
<?import javafx.scene.control.ScrollPane?> <?import javafx.scene.control.ScrollPane?>
<?import javafx.scene.control.TableColumn?> <?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?> <?import javafx.scene.control.TableView?>
@ -110,6 +112,13 @@
<TableColumn fx:id="airpDSTcol" prefWidth="55.0" text="DST" /> <TableColumn fx:id="airpDSTcol" prefWidth="55.0" text="DST" />
<TableColumn fx:id="airpTzcol" minWidth="0.0" prefWidth="200.0" text="Tz database time zone" /> <TableColumn fx:id="airpTzcol" minWidth="0.0" prefWidth="200.0" text="Tz database time zone" />
</columns> </columns>
<contextMenu>
<ContextMenu>
<items>
<MenuItem mnemonicParsing="false" onAction="#deleteAirport" text="Delete" />
</items>
</ContextMenu>
</contextMenu>
</TableView> </TableView>
</children></Pane> </children></Pane>
</children> </children>

@ -3,7 +3,9 @@
<?import javafx.geometry.Insets?> <?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?> <?import javafx.scene.control.Button?>
<?import javafx.scene.control.ComboBox?> <?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.ContextMenu?>
<?import javafx.scene.control.Label?> <?import javafx.scene.control.Label?>
<?import javafx.scene.control.MenuItem?>
<?import javafx.scene.control.TableColumn?> <?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?> <?import javafx.scene.control.TableView?>
<?import javafx.scene.control.TextField?> <?import javafx.scene.control.TextField?>
@ -46,6 +48,13 @@
<TableColumn fx:id="rStopsCol" minWidth="0.0" prefWidth="69.0" text="Stops" /> <TableColumn fx:id="rStopsCol" minWidth="0.0" prefWidth="69.0" text="Stops" />
<TableColumn fx:id="rEquipmentCol" prefWidth="98.0" text="Equipment" /> <TableColumn fx:id="rEquipmentCol" prefWidth="98.0" text="Equipment" />
</columns> </columns>
<contextMenu>
<ContextMenu>
<items>
<MenuItem mnemonicParsing="false" onAction="#deleteRoute" text="Delete" />
</items>
</ContextMenu>
</contextMenu>
</TableView> </TableView>
</children> </children>
</Pane> </Pane>

Loading…
Cancel
Save