You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

109 lines
3.5 KiB

package controllers;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.*;
import javafx.scene.paint.Color;
import model.*;
import java.net.URL;
import java.util.Comparator;
import java.util.Optional;
import java.util.ResourceBundle;
/**
* Created by Gondr on 2/06/2017.
*/
public class MyBookingsController extends Controller {
@FXML
private Label rideLabel;
@FXML
private Label directionLabel;
@FXML
private Label mondayLabel;
@FXML
private Label tuesdayLabel;
@FXML
private Label wednesdayLabel;
@FXML
private Label thursdayLabel;
@FXML
private Label fridayLabel;
@FXML
private Label saturdayLabel;
@FXML
private Label sundayLabel;
@FXML
private Label reoccuringLabel;
@FXML
private Label endDateLabel;
@FXML
private TableView<TripStop> stopsList;
@FXML
private ListView<SharedTrip> tripsList;
private ObservableList<SharedTrip> trips;
@FXML
private TableColumn<TripStop, String> stopTimeColumn;
@FXML
private TableColumn<TripStop, String> stopNameColumn;
private Trip selectedTrip;
private void setRideDays(Label day, boolean travelling){
if (travelling){
day.setTextFill(Color.GREEN);
}else{
day.setTextFill(Color.RED);
}
}
public void cancelRide(){
}
@Override
public void runLater(){
//fill tables etc;
Session.session.getUser().populateBookings();
trips = FXCollections.observableArrayList(Session.session.getUser().getBookings());
Comparator<? super SharedTrip> comparatorByStartDate = new Comparator<SharedTrip>() {
@Override
public int compare(SharedTrip o1, SharedTrip o2) {
return (int)(o1.getStartDate().toEpochDay() - o2.getStartDate().toEpochDay());
}
};
FXCollections.sort(trips, comparatorByStartDate);
tripsList.setItems(trips);
stopTimeColumn.setCellValueFactory(p -> p.getValue().nameProperty());
stopNameColumn.setCellValueFactory(p -> p.getValue().nameProperty());
tripsList.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
selectedTrip = tripsList.getSelectionModel().getSelectedItem();
stopsList.setItems(selectedTrip.route);
rideLabel.setText(selectedTrip.ride.toString());
directionLabel.setText(selectedTrip.direction);
setRideDays(mondayLabel, selectedTrip.days[Trip.MONDAY]);
setRideDays(tuesdayLabel, selectedTrip.days[Trip.TUESDAY]);
setRideDays(wednesdayLabel, selectedTrip.days[Trip.WEDNESDAY]);
setRideDays(thursdayLabel, selectedTrip.days[Trip.THURSDAY]);
setRideDays(fridayLabel, selectedTrip.days[Trip.FRIDAY]);
setRideDays(saturdayLabel, selectedTrip.days[Trip.SATURDAY]);
setRideDays(sundayLabel, selectedTrip.days[Trip.SUNDAY]);
if (selectedTrip.reoccur){
reoccuringLabel.setText("Yes");
endDateLabel.setText(selectedTrip.endDate.toString());
}else{
reoccuringLabel.setText("No");
endDateLabel.setText("-");
}
});
}
@Override
public void initialize(URL location, ResourceBundle resources) {
rideLabel.setText("-");
directionLabel.setText("-");
reoccuringLabel.setText("-");
endDateLabel.setText("-");
}
}