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