From 6b2760a4588ded162dbfedd718cb2af05df72b94 Mon Sep 17 00:00:00 2001 From: lsagona Date: Wed, 2 Sep 2020 14:41:45 +0200 Subject: [PATCH] add warning message if the file contain more than 50 000 messages --- .../application/controller/MenuBarController.kt | 28 ++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) 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 -- 1.7.10.4