001package jmri.jmrit.operations.automation.actions;
002
003import jmri.jmrit.operations.trains.Train;
004
005public class BuildTrainAction extends Action {
006
007    private static final int _code = ActionCodes.BUILD_TRAIN;
008
009    @Override
010    public int getCode() {
011        return _code;
012    }
013
014    @Override
015    public String getName() {
016        return Bundle.getMessage("BuildTrain");
017    }
018
019    @Override
020    public void doAction() {
021        if (getAutomationItem() != null) {
022            Train train = getAutomationItem().getTrain();
023            if (train == null || train.isBuilt() || train.getRoute() == null) {
024                finishAction(false); // failed to build train
025            } else {
026                setRunning(true);
027                finishAction(train.build());
028            }
029        }
030    }
031
032    @Override
033    public void cancelAction() {
034        // no cancel for this action
035    }
036
037}