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