MenuBarController.kt 983 Bytes
package application.controller

import application.model.createVesselCollection
import application.model.observableVessel
import javafx.event.EventHandler
import javafx.fxml.FXML
import javafx.fxml.Initializable
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)
            observableVessel.vessels.clear()
            observableVessel.vessels = vessels
        }
    }
}