001package jmri.util.table; 002 003import jmri.swing.NamedBeanComboBox; 004 005/** 006 * Basic cell editor for JComboBox with optional callback. 007 * @author Steve Young Copyright (c) 2024 008 */ 009public class JComboBoxEditor extends javax.swing.DefaultCellEditor { 010 011 private final transient Runnable onChangeCallback; 012 013 public JComboBoxEditor(javax.swing.JComboBox<?> comboBox, @javax.annotation.CheckForNull final Runnable callback) { 014 super(comboBox); 015 onChangeCallback = callback; 016 jmri.util.swing.JComboBoxUtil.setupComboBoxMaxRows(comboBox); 017 if ( comboBox instanceof NamedBeanComboBox<?> ) { 018 ((NamedBeanComboBox<?>)comboBox).setAllowNull(true); 019 } 020 } 021 022 @Override 023 protected void fireEditingStopped() { 024 if ( onChangeCallback != null ) { 025 onChangeCallback.run(); 026 } 027 super.fireEditingStopped(); 028 } 029 030}