VesselListPanelController.kt 1.09 KB
package application.controller

import application.model.MessageListener
import application.model.Vessel
import application.model.observableVessel
import application.model.observableSelectedVessel
import javafx.collections.FXCollections
import javafx.collections.ObservableList
import javafx.fxml.FXML
import javafx.fxml.Initializable
import javafx.scene.control.ListView
import java.net.URL
import java.util.*

class VesselListPanelController : Initializable, MessageListener {
    @FXML
    var shipListView: ListView<Int> = ListView()


    private var shipList: ObservableList<Int> = FXCollections.observableArrayList()

    override fun initialize(location: URL?, resources: ResourceBundle?) {
        shipListView.items = shipList
        observableVessel.listeners.add(this)
        shipListView.selectionModel.selectedItemProperty().addListener { _, _, newValue ->
            observableSelectedVessel.vessel = observableVessel.vessels[newValue]!!
        }
    }

    override fun onValueChanged(newValue: MutableMap<Int?, Vessel>) {
        shipList.clear()
        shipList.addAll(newValue.keys)
    }

}