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