001package jmri.jmrit.operations.automation.actions;
002
003import jmri.InstanceManager;
004import jmri.jmrit.operations.trains.Train;
005import jmri.jmrit.operations.trains.TrainManager;
006import jmri.jmrit.operations.trains.schedules.TrainSchedule;
007import jmri.jmrit.operations.trains.schedules.TrainScheduleManager;
008
009public class ApplyTrainScheduleAction extends Action {
010
011    private static final int _code = ActionCodes.APPLY_TRAIN_SCHEDULE;
012
013    @Override
014    public int getCode() {
015        return _code;
016    }
017
018    @Override
019    public String getName() {
020        return Bundle.getMessage("ApplyTrainSchedule");
021    }
022
023    @Override
024    public void doAction() {
025        if (getAutomationItem() != null) {
026            TrainSchedule ts = InstanceManager.getDefault(TrainScheduleManager.class).getActiveSchedule();
027            if (ts != null) {
028                for (Train train : InstanceManager.getDefault(TrainManager.class).getTrainsByIdList()) {
029                    train.setBuildEnabled(ts.containsTrainId(train.getId()));
030                }
031            }
032            finishAction(ts != null);
033        }
034    }
035
036    @Override
037    public void cancelAction() {
038        // no cancel for this action
039    }
040}