001package jmri.jmrit.operations.logixng.swing; 002 003import java.util.List; 004 005import javax.annotation.CheckForNull; 006import javax.annotation.Nonnull; 007import javax.swing.*; 008 009import jmri.InstanceManager; 010import jmri.jmrit.logixng.*; 011import jmri.jmrit.logixng.actions.swing.AbstractDigitalActionSwing; 012import jmri.jmrit.operations.logixng.OperationsProStartAutomation; 013import jmri.jmrit.logixng.swing.SwingConfiguratorInterface; 014import jmri.jmrit.logixng.util.LogixNG_SelectComboBox.Item; 015import jmri.jmrit.logixng.util.swing.LogixNG_SelectComboBoxSwing; 016 017/** 018 * Configures an OperationsPro_StartAutomation object with a Swing JPanel. 019 * 020 * @author Daniel Bergqvist Copyright 2025 021 */ 022public class OperationsProStartAutomationSwing extends AbstractDigitalActionSwing { 023 024 private LogixNG_SelectComboBoxSwing _selectAutomationsSwing; 025 026 027 public OperationsProStartAutomationSwing() { 028 } 029 030 public OperationsProStartAutomationSwing(JDialog dialog) { 031 super.setJDialog(dialog); 032 } 033 034 @Override 035 protected void createPanel(@CheckForNull Base object, @Nonnull JPanel buttonPanel) { 036 OperationsProStartAutomation action = (OperationsProStartAutomation)object; 037 if (action == null) { 038 // Create a temporary action 039 action = new OperationsProStartAutomation("IQDA1", null); 040 } 041 042 _selectAutomationsSwing = new LogixNG_SelectComboBoxSwing(getJDialog(), this); 043 044 panel = new JPanel(); 045 046 JPanel _tabbedPaneEnum; 047 048 var selectAutomations = action.getSelectAutomations(); 049 Item[] items = selectAutomations.getValues(); 050 Item item = items.length > 0 ? selectAutomations.getValue() : null; 051 _tabbedPaneEnum = _selectAutomationsSwing.createPanel(selectAutomations, item); 052 053 JComponent[] components = new JComponent[]{_tabbedPaneEnum}; 054 055 List<JComponent> componentList = SwingConfiguratorInterface.parseMessage( 056 Bundle.getMessage("OperationsProStartAutomation_Components"), components); 057 058 for (JComponent c : componentList) panel.add(c); 059 } 060 061 /** {@inheritDoc} */ 062 @Override 063 public boolean validate(@Nonnull List<String> errorMessages) { 064 // Create a temporary action to test formula 065 OperationsProStartAutomation action = new OperationsProStartAutomation("IQDA1", null); 066 _selectAutomationsSwing.validate(action.getSelectAutomations(), errorMessages); 067 return errorMessages.isEmpty(); 068 } 069 070 /** {@inheritDoc} */ 071 @Override 072 public String getAutoSystemName() { 073 return InstanceManager.getDefault(DigitalActionManager.class).getAutoSystemName(); 074 } 075 076 /** {@inheritDoc} */ 077 @Override 078 public MaleSocket createNewObject(@Nonnull String systemName, @CheckForNull String userName) { 079 OperationsProStartAutomation action = new OperationsProStartAutomation(systemName, userName); 080 updateObject(action); 081 return InstanceManager.getDefault(DigitalActionManager.class).registerAction(action); 082 } 083 084 /** {@inheritDoc} */ 085 @Override 086 public void updateObject(@Nonnull Base object) { 087 if (! (object instanceof OperationsProStartAutomation)) { 088 throw new IllegalArgumentException("object must be an OperationsPro_StartAutomation but is a: "+object.getClass().getName()); 089 } 090 OperationsProStartAutomation action = (OperationsProStartAutomation)object; 091 _selectAutomationsSwing.updateObject(action.getSelectAutomations()); 092 } 093 094 /** {@inheritDoc} */ 095 @Override 096 public String toString() { 097 return Bundle.getMessage("OperationsProStartAutomation_Short"); 098 } 099 100 @Override 101 public void dispose() { 102 _selectAutomationsSwing.dispose(); 103 } 104 105 106// private final static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(OperationsPro_StartAutomationSwing.class); 107 108}