Commit 6b2760a4588ded162dbfedd718cb2af05df72b94

Authored by lsagona
1 parent ea7eacbe63
Exists in master and in 1 other branch dev

add warning message if the file contain more than 50 000 messages

Showing 1 changed file with 26 additions and 2 deletions Side-by-side Diff

src/main/kotlin/application/controller/MenuBarController.kt View file @ 6b2760a
... ... @@ -10,9 +10,11 @@
10 10 import javafx.fxml.Initializable
11 11 import javafx.scene.control.*
12 12 import javafx.stage.FileChooser
  13 +import java.io.*
13 14 import java.net.URL
14 15 import java.util.*
15 16  
  17 +
16 18 class MenuBarController : Initializable {
17 19  
18 20 @FXML
... ... @@ -60,6 +62,7 @@
60 62 fileChooser.title = "Choose a file to import"
61 63 val window = menuBar.scene.window
62 64 val file = fileChooser.showOpenDialog(window)
  65 +
63 66 try {
64 67 if (file.extension != "csv") {
65 68 val alert = Alert(Alert.AlertType.WARNING)
66 69  
67 70  
... ... @@ -68,13 +71,34 @@
68 71 alert.contentText = "Please choose à .csv file."
69 72 alert.showAndWait()
70 73 }
71   - val vessels = createVesselCollection(file)
72 74 observableVessel.vessels.clear()
73   - observableVessel.vessels = vessels
  75 + if(toMuchVessel(file)){
  76 + observableVessel.vessels = mutableMapOf()
  77 + }else {
  78 + val vessels = createVesselCollection(file)
  79 + observableVessel.vessels = vessels
  80 + }
74 81 } catch (ignore: IllegalStateException) {
75 82  
76 83 }
77 84 }
  85 + }
  86 +
  87 + private fun toMuchVessel(file: File): Boolean {
  88 + val nbLine = file.readLines().size
  89 + if (nbLine > 50000) {
  90 + val alert = Alert(Alert.AlertType.CONFIRMATION)
  91 + alert.title = "Warning!!"
  92 + alert.headerText = "Warning: This file contain a lot of messages."
  93 + alert.contentText = "Are you sure you want to continue."
  94 + val buttonTypeYes = ButtonType("Yes")
  95 + val buttonTypeNo = ButtonType("No ")
  96 + alert.buttonTypes.setAll(buttonTypeYes, buttonTypeNo)
  97 + val result = alert.showAndWait()
  98 +
  99 + return result.get() != buttonTypeYes
  100 + }
  101 + return false
78 102 }
79 103  
80 104 private fun setOnActionAllMessageButton() {