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 return manager.registerAction(copy).deepCopyChildren(this, systemNames, userNames); 035 } 036 037 /** {@inheritDoc} */ 038 @Override 039 public Category getCategory() { 040 return CategoryLocoNet.LOCONET; 041 } 042 043 public void setMemo(LocoNetSystemConnectionMemo memo) { 044 assertListenersAreNotRegistered(log, "setMemo"); 045 _memo = memo; 046 } 047 048 public LocoNetSystemConnectionMemo getMemo() { 049 return _memo; 050 } 051 052 /** {@inheritDoc} */ 053 @Override 054 public void execute() { 055 if (_memo != null) _memo.getSlotManager().update(); 056 } 057 058 @Override 059 public FemaleSocket getChild(int index) throws IllegalArgumentException, UnsupportedOperationException { 060 throw new UnsupportedOperationException("Not supported."); 061 } 062 063 @Override 064 public int getChildCount() { 065 return 0; 066 } 067 068 @Override 069 public String getShortDescription(Locale locale) { 070 return Bundle.getMessage(locale, "ActionUpdateSlots_Short"); 071 } 072 073 @Override 074 public String getLongDescription(Locale locale) { 075 return Bundle.getMessage(locale, "ActionUpdateSlots_Long", 076 _memo != null ? _memo.getUserName() : Bundle.getMessage("MemoNotSet")); 077 } 078 079 /** {@inheritDoc} */ 080 @Override 081 public void setup() { 082 // Do nothing 083 } 084 085 /** {@inheritDoc} */ 086 @Override 087 public void registerListenersForThisClass() { 088 if (!_listenersAreRegistered) { 089 _listenersAreRegistered = true; 090 } 091 } 092 093 /** {@inheritDoc} */ 094 @Override 095 public void unregisterListenersForThisClass() { 096 _listenersAreRegistered = false; 097 } 098 099 /** {@inheritDoc} */ 100 @Override 101 public void disposeMe() { 102 } 103 104 105 private final static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(ActionUpdateSlots.class); 106 107}