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