001package jmri.jmrit.operations.automation.actions;
002
003import jmri.InstanceManager;
004import jmri.jmrit.operations.setup.Setup;
005import jmri.jmrit.operations.trains.Train;
006import jmri.jmrit.operations.trains.TrainManager;
007
008public class PrintTrainBuildReportAction extends Action {
009
010    private static final int _code = ActionCodes.PRINT_TRAIN_BUILDREPORT;
011
012    @Override
013    public int getCode() {
014        return _code;
015    }
016
017    @Override
018    public String getName() {
019        if (InstanceManager.getDefault(TrainManager.class).isPrintPreviewEnabled() ||
020                Setup.isBuildReportAlwaysPreviewEnabled()) {
021            return Bundle.getMessage("PreviewTrainBuildReport");
022        } else {
023            return Bundle.getMessage("PrintTrainBuildReport");
024        }
025    }
026
027    @Override
028    public void doAction() {
029        if (getAutomationItem() != null) {
030            Train train = getAutomationItem().getTrain();
031            if (train != null && train.isBuilt()) {
032                setRunning(true);
033                finishAction(train.printBuildReport());
034            } else {
035                finishAction(false);
036            }
037        }
038    }
039
040    @Override
041    public void cancelAction() {
042        // no cancel for this action
043    }
044
045}