diff --git a/src/main/kotlin/application/controller/MenuBarController.kt b/src/main/kotlin/application/controller/MenuBarController.kt index d3846b5..672410a 100644 --- a/src/main/kotlin/application/controller/MenuBarController.kt +++ b/src/main/kotlin/application/controller/MenuBarController.kt @@ -10,9 +10,11 @@ import javafx.fxml.FXML import javafx.fxml.Initializable import javafx.scene.control.* import javafx.stage.FileChooser +import java.io.* import java.net.URL import java.util.* + class MenuBarController : Initializable { @FXML @@ -60,6 +62,7 @@ class MenuBarController : Initializable { fileChooser.title = "Choose a file to import" val window = menuBar.scene.window val file = fileChooser.showOpenDialog(window) + try { if (file.extension != "csv") { val alert = Alert(Alert.AlertType.WARNING) @@ -68,15 +71,36 @@ class MenuBarController : Initializable { alert.contentText = "Please choose à .csv file." alert.showAndWait() } - val vessels = createVesselCollection(file) observableVessel.vessels.clear() - observableVessel.vessels = vessels + if(toMuchVessel(file)){ + observableVessel.vessels = mutableMapOf() + }else { + val vessels = createVesselCollection(file) + observableVessel.vessels = vessels + } } catch (ignore: IllegalStateException) { } } } + private fun toMuchVessel(file: File): Boolean { + val nbLine = file.readLines().size + if (nbLine > 50000) { + val alert = Alert(Alert.AlertType.CONFIRMATION) + alert.title = "Warning!!" + alert.headerText = "Warning: This file contain a lot of messages." + alert.contentText = "Are you sure you want to continue." + val buttonTypeYes = ButtonType("Yes") + val buttonTypeNo = ButtonType("No ") + alert.buttonTypes.setAll(buttonTypeYes, buttonTypeNo) + val result = alert.showAndWait() + + return result.get() != buttonTypeYes + } + return false + } + private fun setOnActionAllMessageButton() { allMessages.onAction = EventHandler { observableMapState.state = ALL_MESSAGES