use of ctc.model.Schedule in project on-track by michaelplazek.
the class CentralTrafficControlController method addTrainToQueue.
private void addTrainToQueue() {
if (trackSelect.getSelectionModel().getSelectedItem().equals("Select track")) {
AlertWindow alert = new AlertWindow();
alert.setTitle("Error Submitting");
alert.setHeader("No Track Selected");
alert.setContent("Please select a track from the " + "Select Track dropdown menu before submitting.");
alert.show();
} else {
// get train stop info
List<String> stopData = new ArrayList<>();
for (ScheduleRow item : addScheduleTable.getItems()) {
stopData.add(stopColumn.getCellData(item));
}
// get train dwell info
List<String> dwellData = new ArrayList<>();
for (ScheduleRow item : addScheduleTable.getItems()) {
dwellData.add(dwellColumn.getCellObservableValue(item).getValue());
}
// get line
String line = trackSelect.getSelectionModel().getSelectedItem();
// create schedule
Schedule schedule = new Schedule(line);
for (int i = 0; i < addScheduleTable.getItems().size(); i++) {
schedule.addStop(new ScheduleRow(stopData.get(i), dwellData.get(i), ""));
}
String name = trainNameField.getText();
String departingTime = departingTimeField.getText();
if (!name.equals("") && departingTime.length() == 8) {
TrainTracker train = new TrainTracker(name, departingTime, line, schedule);
// set the track that is current set
train.setLine(ctc.getLine());
// create item in queue
trainQueueTable.setItems(ctc.getTrainQueueTable());
resetSchedule();
// create train
ctc.addTrain(train);
}
}
}
Aggregations