001package jmri.jmrix.loconet.logixng;
002
003import jmri.jmrit.logixng.actions.*;
004
005import java.util.Locale;
006import java.util.Map;
007
008import jmri.InstanceManager;
009import jmri.JmriException;
010import jmri.jmrit.logixng.*;
011import jmri.jmrix.loconet.LocoNetSystemConnectionMemo;
012
013/**
014 * Request an update of the LocoNet slots
015 *
016 * @author Daniel Bergqvist Copyright 2020
017 */
018public class ActionUpdateSlots extends AbstractDigitalAction {
019
020    private LocoNetSystemConnectionMemo _memo;
021
022    public ActionUpdateSlots(String sys, String user, LocoNetSystemConnectionMemo memo) {
023        super(sys, user);
024        _memo = memo;
025    }
026
027    @Override
028    public Base getDeepCopy(Map<String, String> systemNames, Map<String, String> userNames) throws JmriException {
029        DigitalActionManager manager = InstanceManager.getDefault(DigitalActionManager.class);
030        String sysName = systemNames.get(getSystemName());
031        String userName = userNames.get(getSystemName());
032        if (sysName == null) sysName = manager.getAutoSystemName();
033        ActionUpdateSlots copy = new ActionUpdateSlots(sysName, userName, _memo);
034        copy.setComment(getComment());
035        return manager.registerAction(copy).deepCopyChildren(this, systemNames, userNames);
036    }
037
038    /** {@inheritDoc} */
039    @Override
040    public Category getCategory() {
041        return CategoryLocoNet.LOCONET;
042    }
043
044    public void setMemo(LocoNetSystemConnectionMemo memo) {
045        assertListenersAreNotRegistered(log, "setMemo");
046        _memo = memo;
047    }
048
049    public LocoNetSystemConnectionMemo getMemo() {
050        return _memo;
051    }
052
053    /** {@inheritDoc} */
054    @Override
055    public void execute() {
056        if (_memo != null) _memo.getSlotManager().update();
057    }
058
059    @Override
060    public FemaleSocket getChild(int index) throws IllegalArgumentException, UnsupportedOperationException {
061        throw new UnsupportedOperationException("Not supported.");
062    }
063
064    @Override
065    public int getChildCount() {
066        return 0;
067    }
068
069    @Override
070    public String getShortDescription(Locale locale) {
071        return Bundle.getMessage(locale, "ActionUpdateSlots_Short");
072    }
073
074    @Override
075    public String getLongDescription(Locale locale) {
076        return Bundle.getMessage(locale, "ActionUpdateSlots_Long",
077                _memo != null ? _memo.getUserName() : Bundle.getMessage("MemoNotSet"));
078    }
079
080    /** {@inheritDoc} */
081    @Override
082    public void setup() {
083        // Do nothing
084    }
085
086    /** {@inheritDoc} */
087    @Override
088    public void registerListenersForThisClass() {
089        if (!_listenersAreRegistered) {
090            _listenersAreRegistered = true;
091        }
092    }
093
094    /** {@inheritDoc} */
095    @Override
096    public void unregisterListenersForThisClass() {
097        _listenersAreRegistered = false;
098    }
099
100    /** {@inheritDoc} */
101    @Override
102    public void disposeMe() {
103    }
104
105
106    private final static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(ActionUpdateSlots.class);
107
108}