diff --git a/res/userdb.db b/res/userdb.db index 4ed4876..d91c022 100644 Binary files a/res/userdb.db and b/res/userdb.db differ diff --git a/src/main/java/seng202/group9/GUI/AirlineRDController.java b/src/main/java/seng202/group9/GUI/AirlineRDController.java index 12bcef9..c1f8081 100644 --- a/src/main/java/seng202/group9/GUI/AirlineRDController.java +++ b/src/main/java/seng202/group9/GUI/AirlineRDController.java @@ -1,15 +1,26 @@ package seng202.group9.GUI; import javafx.collections.FXCollections; +import javafx.collections.ObservableList; import javafx.fxml.FXML; +import javafx.fxml.FXMLLoader; +import javafx.scene.Parent; +import javafx.scene.Scene; import javafx.scene.control.*; import javafx.scene.control.cell.PropertyValueFactory; +import javafx.scene.layout.Pane; +import javafx.stage.Modality; +import javafx.stage.Stage; +import javafx.stage.StageStyle; import seng202.group9.Controller.AirlineFilter; +import seng202.group9.Controller.App; import seng202.group9.Controller.Dataset; +import seng202.group9.Controller.SceneCode; import seng202.group9.Core.Airline; import javax.swing.*; - +import java.io.IOException; +//make a class for the scenes to get the data I guess /** * The GUI controller class for airline_raw_data.fxml. * Extends from the abstract class {@link Controller}. @@ -20,37 +31,37 @@ public class AirlineRDController extends Controller { @FXML private TableView tableViewAirlineRD; @FXML - private TableColumn airlIDcol; + private TableColumn airlIDCol; @FXML - private TableColumn airlNamecol; + private TableColumn airlNameCol; @FXML - private TableColumn airlAliascol; + private TableColumn airlAliasCol; @FXML - private TableColumn airlIATAcol; + private TableColumn airlIATACol; @FXML - private TableColumn airlICAOcol; + private TableColumn airlICAOCol; @FXML - private TableColumn airlCallsigncol; + private TableColumn airlCallsignCol; @FXML - private TableColumn airlCountrycol; + private TableColumn airlCountryCol; @FXML - private TableColumn airlActivecol; + private TableColumn airlActiveCol; //Setting up text fields for adding data @FXML - private TextField airlNameBox; + private TextField airlNameAdd; @FXML - private TextField airlAliasBox; + private TextField airlAliasAdd; @FXML - private TextField airlIATABox; + private TextField airlIATAAdd; @FXML - private TextField airlICAOBox; + private TextField airlICAOAdd; @FXML - private TextField airlCallsignBox; + private TextField airlCallsignAdd; @FXML - private TextField airlCountryBox; + private TextField airlCountryAdd; @FXML - private ComboBox airlActiveCBox; + private TextField airlActiveAdd; //Setting up text fields for filtering data @FXML @@ -77,22 +88,37 @@ public class AirlineRDController extends Controller { */ public void load() { //Sets up the table columns to be ready for use for Airline data - airlIDcol.setCellValueFactory(new PropertyValueFactory("ID")); - airlNamecol.setCellValueFactory(new PropertyValueFactory("Name")); - airlAliascol.setCellValueFactory(new PropertyValueFactory("Alias")); - airlIATAcol.setCellValueFactory(new PropertyValueFactory("IATA")); - airlICAOcol.setCellValueFactory(new PropertyValueFactory("ICAO")); - airlCallsigncol.setCellValueFactory(new PropertyValueFactory("CallSign")); - airlCountrycol.setCellValueFactory(new PropertyValueFactory("CountryName")); - airlActivecol.setCellValueFactory(new PropertyValueFactory("Active")); + airlIDCol.setCellValueFactory(new PropertyValueFactory("ID")); + airlNameCol.setCellValueFactory(new PropertyValueFactory("Name")); + airlAliasCol.setCellValueFactory(new PropertyValueFactory("Alias")); + airlIATACol.setCellValueFactory(new PropertyValueFactory("IATA")); + airlICAOCol.setCellValueFactory(new PropertyValueFactory("ICAO")); + airlCallsignCol.setCellValueFactory(new PropertyValueFactory("CallSign")); + airlCountryCol.setCellValueFactory(new PropertyValueFactory("CountryName")); + airlActiveCol.setCellValueFactory(new PropertyValueFactory("Active")); //Assigning the Dataset to the current Dataset's airlines and displaying it in a table theDataSet = getParent().getCurrentDataset(); tableViewAirlineRD.setItems(FXCollections.observableArrayList(theDataSet.getAirlines())); + } + + /** + * Opens the Airline add form. + */ + public void openAdd() { + try { + FXMLLoader loader = new FXMLLoader(); + Parent root = loader.load(getClass().getClassLoader().getResource("airline_add_form.fxml")); + Stage filter = new Stage(); + filter.initModality(Modality.APPLICATION_MODAL); + filter.setResizable(false); + filter.setTitle("Add New Airline"); + filter.setScene(new Scene(root, 600, 370)); + filter.show(); + } catch (IOException e) { + e.printStackTrace(); + } - //Initializes the value for the drop-down menu for Active for adding a new Airline - airlActiveCBox.setValue("Y"); - airlActiveCBox.getItems().addAll("Y", "N"); } /** @@ -103,45 +129,35 @@ public class AirlineRDController extends Controller { public void addAirlineSingle() { //Tries to add a new airline 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. + + //How to get this dataset into here to show data? try { theDataSet.addAirline( - airlNameBox.getText(), - airlAliasBox.getText(), - airlIATABox.getText(), - airlICAOBox.getText(), - airlCallsignBox.getText(), - airlCountryBox.getText(), - airlActiveCBox.getSelectionModel().getSelectedItem().toString()); - airlNameBox.clear(); - airlAliasBox.clear(); - airlIATABox.clear(); - airlICAOBox.clear(); - airlCallsignBox.clear(); - airlCountryBox.clear(); - airlActiveCBox.getSelectionModel().clearSelection(); - airlActiveCBox.setValue("Y"); + airlNameAdd.getText(), + airlAliasAdd.getText(), + airlIATAAdd.getText(), + airlICAOAdd.getText(), + airlCallsignAdd.getText(), + airlCountryAdd.getText(), + airlActiveAdd.getText()); + airlNameAdd.clear(); + airlAliasAdd.clear(); + airlIATAAdd.clear(); + airlICAOAdd.clear(); + airlCallsignAdd.clear(); + airlCountryAdd.clear(); + airlActiveAdd.getText(); tableViewAirlineRD.setItems(FXCollections.observableArrayList(theDataSet.getAirlines())); - } catch ( Exception e ) { + } catch (Exception e) { Alert alert = new Alert(Alert.AlertType.ERROR); alert.setTitle("Airline Data Error"); alert.setHeaderText("Error adding a custom airline entry."); + System.out.println(e); alert.setContentText(e.getMessage()); alert.showAndWait(); } } - /** - * Deletes a single selected airline entry from the database. - * Updates the GUI accordingly. - * @see Dataset - */ - public void deleteAirline() { - //Gets an airline from the table and deletes it before updating the table - Airline toDelete = tableViewAirlineRD.getSelectionModel().getSelectedItem(); - theDataSet.deleteAirline(toDelete); - tableViewAirlineRD.setItems(FXCollections.observableArrayList(theDataSet.getAirlines())); - } - /** * Filters airlines by any field. * These are specified by what the user has typed in the filter boxes. @@ -150,6 +166,7 @@ public class AirlineRDController extends Controller { */ public void filterAirlines() { //The filter function also operates like a search function + //theDataSet = getParent().getCurrentDataset(); AirlineFilter filter = new AirlineFilter(theDataSet.getAirlines()); if (airlNameFilter.getText() != null) { filter.filterName(airlNameFilter.getText()); @@ -176,6 +193,36 @@ public class AirlineRDController extends Controller { tableViewAirlineRD.setItems(FXCollections.observableArrayList(filter.getFilteredData())); } + /** + * Deletes a single selected airline entry from the database. + * Updates the GUI accordingly. + * @see Dataset + */ + public void deleteAirline() { + //Gets an airline from the table and deletes it before updating the table + Airline toDelete = tableViewAirlineRD.getSelectionModel().getSelectedItem(); + theDataSet.deleteAirline(toDelete); + tableViewAirlineRD.setItems(FXCollections.observableArrayList(theDataSet.getAirlines())); + } + + /** + * Opens the Airline Filter form. + */ + public void openFilter() { + try { + Parent root = FXMLLoader.load(getClass().getResource("/airline_filter_form.fxml")); + final Stage filter = new Stage(); + filter.initModality(Modality.APPLICATION_MODAL); + filter.setResizable(false); + filter.setTitle("Airline Filter"); + filter.setScene(new Scene(root, 600, 370)); + filter.show(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + /** * Analyses the current data and creates a graph based on the data. * Currently not implemented yet. @@ -183,4 +230,8 @@ public class AirlineRDController extends Controller { public void analyse_Button() { JOptionPane.showMessageDialog(null, "This is not Implemented yet"); } + + public void airlineSummaryButton() { + replaceSceneContent(SceneCode.AIRLINE_SUMMARY); + } } diff --git a/src/main/resources/airline_add_form.fxml b/src/main/resources/airline_add_form.fxml new file mode 100644 index 0000000..1a31a01 --- /dev/null +++ b/src/main/resources/airline_add_form.fxml @@ -0,0 +1,82 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + +