Open, delete and add dataset now work
This commit is contained in:
@@ -72,12 +72,6 @@ public class App extends Application
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
//testing out dataset
|
||||
try {
|
||||
currentDataset = new Dataset("test's", Dataset.getExisting);
|
||||
}catch (DataException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
//after all loading then load the previous session
|
||||
try{
|
||||
FileInputStream fileIn = new FileInputStream("res/session.ser");
|
||||
@@ -99,7 +93,20 @@ public class App extends Application
|
||||
session = new Session();
|
||||
e.printStackTrace();
|
||||
}
|
||||
//menuController.createPopUpStage(SceneCode.DATASET_CONTROLLER, 600, 400);
|
||||
//testing out dataset
|
||||
try {
|
||||
if (session.getCurrentDataset() != null) {
|
||||
currentDataset = new Dataset(session.getCurrentDataset(), Dataset.getExisting);
|
||||
}else{
|
||||
menuController.createPopUpStage(SceneCode.DATASET_CONTROLLER, 600, 400);
|
||||
}
|
||||
}catch (DataException e){
|
||||
menuController.createPopUpStage(SceneCode.DATASET_CONTROLLER, 600, 400);
|
||||
}catch (NullPointerException e){
|
||||
menuController.createPopUpStage(SceneCode.DATASET_CONTROLLER, 600, 400);
|
||||
}catch (Exception e){
|
||||
menuController.createPopUpStage(SceneCode.DATASET_CONTROLLER, 600, 400);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -198,6 +205,7 @@ public class App extends Application
|
||||
*/
|
||||
public void setCurrentDataset(int index){
|
||||
currentDataset = datasets.get(index);
|
||||
session.setCurrentDataset(currentDataset.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -206,6 +214,7 @@ public class App extends Application
|
||||
*/
|
||||
public void setCurrentDataset(Dataset dataset){
|
||||
currentDataset = dataset;
|
||||
session.setCurrentDataset(currentDataset.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -25,6 +25,8 @@ public class Session implements Serializable {
|
||||
private String airportToEdit;
|
||||
private String routeToEdit;
|
||||
|
||||
private String currentDataset;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor for a new session
|
||||
@@ -42,6 +44,14 @@ public class Session implements Serializable {
|
||||
this.sceneDisplayed = scene;
|
||||
}
|
||||
|
||||
public String getCurrentDataset(){
|
||||
return this.currentDataset;
|
||||
}
|
||||
|
||||
public void setCurrentDataset(String currentDataset){
|
||||
this.currentDataset = currentDataset;
|
||||
}
|
||||
|
||||
/**
|
||||
* changes the serialized scene.
|
||||
* @param sceneDisplayed
|
||||
|
||||
@@ -5,8 +5,12 @@ import javafx.collections.FXCollections;
|
||||
import javafx.collections.ListChangeListener;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.Alert;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.ListView;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.stage.Stage;
|
||||
import seng202.group9.Controller.DataException;
|
||||
import seng202.group9.Controller.Dataset;
|
||||
|
||||
import java.util.*;
|
||||
@@ -22,11 +26,14 @@ public class DatasetController extends Controller{
|
||||
ListView datasetView;
|
||||
@FXML
|
||||
TextField datasetName;
|
||||
@FXML
|
||||
Button openDataset;
|
||||
Dataset curDataset = null;
|
||||
ObservableList<Dataset> datasetList = observableArrayList();
|
||||
|
||||
public void load() {
|
||||
curDataset = getParent().getCurrentDataset();
|
||||
loadTable();
|
||||
}
|
||||
|
||||
public void loadTable(){
|
||||
@@ -38,13 +45,35 @@ public class DatasetController extends Controller{
|
||||
public void deleteDataset(){
|
||||
Dataset datasetToDelete = (Dataset) datasetView.getSelectionModel().getSelectedItem();
|
||||
getParent().deleteDataset(datasetToDelete);
|
||||
loadTable();
|
||||
}
|
||||
|
||||
public void addDataset(){
|
||||
|
||||
String name = datasetName.getText();
|
||||
if (!name.equals("") && name != null) {
|
||||
try {
|
||||
getParent().createDataset(name);
|
||||
} catch (DataException e) {
|
||||
Alert alert = new Alert(Alert.AlertType.ERROR);
|
||||
alert.setTitle("Dataset Creation Error");
|
||||
alert.setHeaderText("Error creating Dataset.");
|
||||
alert.setContentText(e.getMessage());
|
||||
alert.showAndWait();
|
||||
}
|
||||
}else{
|
||||
Alert alert = new Alert(Alert.AlertType.ERROR);
|
||||
alert.setTitle("Dataset Creation Error");
|
||||
alert.setHeaderText("Error creating Dataset.");
|
||||
alert.setContentText("Dataset Name Cannot be Empty");
|
||||
alert.showAndWait();
|
||||
}
|
||||
loadTable();
|
||||
}
|
||||
|
||||
public void openDataset(){
|
||||
|
||||
Dataset datasetToOpen = (Dataset) datasetView.getSelectionModel().getSelectedItem();
|
||||
getParent().setCurrentDataset(datasetToOpen);
|
||||
loadTable();
|
||||
((Stage) openDataset.getScene().getWindow()).close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
<contextMenu>
|
||||
<ContextMenu>
|
||||
<items>
|
||||
<MenuItem fx:id="deleteBtn" mnemonicParsing="false" onAction="#deleteDataset" text="Unspecified Action" />
|
||||
<MenuItem fx:id="deleteBtn" mnemonicParsing="false" onAction="#deleteDataset" text="Delete Dataset" />
|
||||
</items>
|
||||
</ContextMenu>
|
||||
</contextMenu>
|
||||
@@ -34,7 +34,7 @@
|
||||
<Font size="18.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<Button mnemonicParsing="false" onAction="#openDataset" prefHeight="25.0" prefWidth="785.0" text="Open" GridPane.columnSpan="2" GridPane.halignment="CENTER" GridPane.rowIndex="3" />
|
||||
<Button fx:id="openDataset" mnemonicParsing="false" onAction="#openDataset" prefHeight="25.0" prefWidth="785.0" text="Open" GridPane.columnSpan="2" GridPane.halignment="CENTER" GridPane.rowIndex="3" />
|
||||
</children>
|
||||
<padding>
|
||||
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
|
||||
|
||||
Reference in New Issue
Block a user