MenuBarController.kt 1.04 KB
package application.controller

import application.App
import application.model.createVesselCollection
import application.model.observableMessages
import javafx.event.EventHandler
import javafx.fxml.FXML
import javafx.fxml.FXMLLoader
import javafx.fxml.Initializable
import javafx.scene.Parent
import javafx.scene.control.MenuBar
import javafx.scene.control.MenuItem
import javafx.stage.FileChooser
import java.net.URL
import java.util.*

class MenuBarController : Initializable {

    @FXML
    var menuBar: MenuBar = MenuBar()

    @FXML
    var import: MenuItem = MenuItem()

    override fun initialize(location: URL?, resources: ResourceBundle?) {

        import.onAction = EventHandler {
            val fileChooser = FileChooser()
            fileChooser.title = "Choose a file to import"
            val window = menuBar.scene.window
            val file = fileChooser.showOpenDialog(window)
            val vessels = createVesselCollection(file)
            observableMessages.vessels.clear()
            observableMessages.vessels = vessels
        }
    }
}