private void rebuild() { final JComponent component = getChildComponent(); final NamedScope[] model = createModel(); if (component instanceof JComboBox) { ((JComboBox)component).setModel(new DefaultComboBoxModel(model)); } else { ((JBComboBoxTableCellEditorComponent)component).setOptions(model); } }
@Nullable public NamedScope getSelectedScope() { final JComponent component = getChildComponent(); if (component instanceof JComboBox) { int idx = ((JComboBox)component).getSelectedIndex(); if (idx < 0) return null; return (NamedScope)((JComboBox)component).getSelectedItem(); } else { return (NamedScope)((JBComboBoxTableCellEditorComponent)component).getEditorValue(); } }
public TableCellEditor getEditor(final ScopeSetting scopeSetting) { return new AbstractTableCellEditor() { private final JBComboBoxTableCellEditorComponent myProfilesChooser = new JBComboBoxTableCellEditorComponent(); public Object getCellEditorValue() { return myProfilesChooser.getEditorValue(); } public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { final List<CopyrightProfile> copyrights = new ArrayList<CopyrightProfile>(myProfilesModel.getAllProfiles().values()); Collections.sort(copyrights, new Comparator<CopyrightProfile>() { @Override public int compare(CopyrightProfile o1, CopyrightProfile o2) { return o1.getName().compareToIgnoreCase(o2.getName()); } }); myProfilesChooser.setCell(table, row, column); myProfilesChooser.setOptions(copyrights.toArray()); myProfilesChooser.setDefaultValue(scopeSetting.getProfile()); myProfilesChooser.setToString(new Function<Object, String>() { @Override public String fun(Object o) { return ((CopyrightProfile)o).getName(); } }); return myProfilesChooser; } }; }