001package jmri.jmrit.operations.rollingstock.engines.tools;
002
003import java.awt.event.ActionEvent;
004import java.util.List;
005
006import javax.swing.AbstractAction;
007
008import jmri.InstanceManager;
009import jmri.jmrix.nce.NceSystemConnectionMemo;
010import jmri.jmrix.nce.NceTrafficController;
011
012/**
013 * Starts the NceConsistEngine thread
014 *
015 * @author Dan Boudreau Copyright (C) 2008
016 */
017public class NceConsistEngineAction extends AbstractAction {
018
019    NceTrafficController tc;
020
021    public NceConsistEngineAction() {
022        super(Bundle.getMessage("MenuItemNceSync"));
023        // only enable if connected to an NCE system
024        setEnabled(false);
025        // disable if NCE USB selected
026        // get NceTrafficContoller if there's one
027        List<NceSystemConnectionMemo> memos = InstanceManager.getList(NceSystemConnectionMemo.class);
028
029        // find NceConnection that is serial
030        for (NceSystemConnectionMemo memo : memos) {
031            if (memo.getNceUsbSystem() == NceTrafficController.USB_SYSTEM_NONE) {
032                tc = memo.getNceTrafficController();
033                if (!memo.getDisabled()) {
034                    setEnabled(true);
035                }
036            }
037        }
038    }
039
040    @Override
041    public void actionPerformed(ActionEvent ae) {
042        Thread mb = new NceConsistEngines(tc);
043        mb.setName("Nce Consist Sync Engines"); // NOI18N
044        mb.start();
045    }
046
047//    private final static Logger log = LoggerFactory.getLogger(NceConsistEngineAction.class);
048}