001package apps.startup; 002 003import jmri.util.startup.StartupModelFactory; 004import jmri.util.startup.StartupModel; 005import jmri.util.startup.StartupActionsManager; 006import java.awt.Component; 007import javax.swing.DefaultCellEditor; 008import javax.swing.JButton; 009import javax.swing.JTable; 010import javax.swing.JTextField; 011import javax.swing.SwingConstants; 012import javax.swing.SwingUtilities; 013import jmri.InstanceManager; 014 015/** 016 * 017 * @author Randall Wood 018 */ 019class StartupModelCellEditor extends DefaultCellEditor { 020 021 private StartupModel model; 022 private final JButton button; 023 024 public StartupModelCellEditor() { 025 super(new JTextField()); 026 this.model = null; 027 this.button = new JButton(); 028 this.button.setHorizontalAlignment(SwingConstants.LEADING); 029 this.button.setBorderPainted(false); 030 this.button.setFocusable(false); 031 this.button.setContentAreaFilled(false); 032 } 033 034 @Override 035 public Object getCellEditorValue() { 036 return this.model; 037 } 038 039 @Override 040 public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { 041 this.model = InstanceManager.getDefault(StartupActionsManager.class).getActions(row); 042 if (this.model != null) { 043 SwingUtilities.invokeLater(() -> { 044 StartupModelFactory factory = InstanceManager.getDefault(StartupActionsManager.class).getFactories(this.model.getClass()); 045 factory.editModel(this.model, table.getRootPane()); 046 //Make the renderer reappear. 047 fireEditingStopped(); 048 }); 049 } 050 return table.getCellRenderer(row, column).getTableCellRendererComponent(table, value, isSelected, true, row, column); 051 } 052}