package controllers;

import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.fxml.FXML;
import javafx.scene.control.ListView;
import model.Route;
import model.Stop;

import java.net.URL;
import java.util.ResourceBundle;

/**
 * Created by Gondr on 5/04/2017.
 */
public class MyRoutesController extends Controller {

    @FXML
    ListView<Route> routesList;
    @FXML
    ListView<Stop> stopsList;



    @Override
    public void runLater(){
        routesList.setItems(parent.getSession().getDataManager().getRoutes());
        routesList.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Route>(){
            @Override
            public void changed(ObservableValue<? extends Route> observable, Route oldValue, Route newValue) {
                stopsList.setItems(FXCollections.observableArrayList(newValue.getStops()));
            }
        });
    }

    @Override
    public void initialize(URL location, ResourceBundle resources) {

    }
}
