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