001package jmri.jmrit.logixng.actions.swing; 002 003import java.util.List; 004 005import javax.annotation.CheckForNull; 006import javax.annotation.Nonnull; 007import javax.swing.JLabel; 008import javax.swing.JPanel; 009 010import jmri.InstanceManager; 011import jmri.Memory; 012import jmri.MemoryManager; 013import jmri.jmrit.logixng.Base; 014import jmri.jmrit.logixng.StringActionManager; 015import jmri.jmrit.logixng.MaleSocket; 016import jmri.jmrit.logixng.actions.StringActionMemory; 017import jmri.jmrit.logixng.util.swing.LogixNG_SelectNamedBeanSwing; 018 019/** 020 * Configures an ActionMemory object with a Swing JPanel. 021 * 022 * @author Daniel Bergqvist Copyright 2021 023 */ 024public class StringActionMemorySwing extends AbstractStringActionSwing { 025 026 private LogixNG_SelectNamedBeanSwing<Memory> _selectNamedBeanSwing; 027 028 029 @Override 030 protected void createPanel(@CheckForNull Base object, @Nonnull JPanel buttonPanel) { 031 StringActionMemory action = (StringActionMemory)object; 032 033 _selectNamedBeanSwing = new LogixNG_SelectNamedBeanSwing<>( 034 InstanceManager.getDefault(MemoryManager.class), getJDialog(), this); 035 036 panel = new JPanel(); 037 JPanel _tabbedPaneNamedBean; 038 if (action != null) { 039 _tabbedPaneNamedBean = _selectNamedBeanSwing.createPanel(action.getSelectNamedBean()); 040 } else { 041 _tabbedPaneNamedBean = _selectNamedBeanSwing.createPanel(null); 042 } 043 044 panel.add(new JLabel(Bundle.getMessage("BeanNameMemory"))); 045 panel.add(_tabbedPaneNamedBean); 046 } 047 048 /** {@inheritDoc} */ 049 @Override 050 public boolean validate(@Nonnull List<String> errorMessages) { 051 StringActionMemory action = new StringActionMemory("IQSA1", null); 052 _selectNamedBeanSwing.validate(action.getSelectNamedBean(), errorMessages); 053 return errorMessages.isEmpty(); 054 } 055 056 /** {@inheritDoc} */ 057 @Override 058 public MaleSocket createNewObject(@Nonnull String systemName, @CheckForNull String userName) { 059 StringActionMemory action = new StringActionMemory(systemName, userName); 060 updateObject(action); 061 return InstanceManager.getDefault(StringActionManager.class).registerAction(action); 062 } 063 064 /** {@inheritDoc} */ 065 @Override 066 public void updateObject(@Nonnull Base object) { 067 if (! (object instanceof StringActionMemory)) { 068 throw new IllegalArgumentException("object must be an ActionMemory but is a: "+object.getClass().getName()); 069 } 070 StringActionMemory action = (StringActionMemory)object; 071 _selectNamedBeanSwing.updateObject(action.getSelectNamedBean()); 072 } 073 074 /** {@inheritDoc} */ 075 @Override 076 public String toString() { 077 return Bundle.getMessage("StringActionMemory_Short"); 078 } 079 080 @Override 081 public void dispose() { 082 // Do nothing 083 } 084 085 086// private final static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(StringActionMemorySwing.class); 087 088}