001package jmri.jmrit.operations.automation.actions;
002
003import javax.swing.JComboBox;
004import jmri.InstanceManager;
005import jmri.jmrit.operations.trains.schedules.TrainSchedule;
006import jmri.jmrit.operations.trains.schedules.TrainScheduleManager;
007
008public class ActivateTrainScheduleAction extends Action {
009
010    private static final int _code = ActionCodes.ACTIVATE_TRAIN_SCHEDULE;
011
012    @Override
013    public int getCode() {
014        return _code;
015    }
016
017    @Override
018    public String getName() {
019        return Bundle.getMessage("ActivateTrainSchedule");
020    }
021
022    @Override
023    public void doAction() {
024        if (getAutomationItem() != null) {
025            InstanceManager.getDefault(TrainScheduleManager.class)
026                    .setTrainScheduleActiveId(getAutomationItem().getTrainScheduleId());
027            finishAction(true);
028        }
029    }
030
031    @Override
032    public void cancelAction() {
033        // no cancel for this action
034    }
035
036    @Override
037    public JComboBox<TrainSchedule> getComboBox() {
038        JComboBox<TrainSchedule> cb = InstanceManager.getDefault(TrainScheduleManager.class).getSelectComboBox();
039        if (getAutomationItem() != null) {
040            cb.setSelectedItem(getAutomationItem().getTrainSchedule());
041        }
042        return cb;
043    }
044}