serverConfigurationCombobox.setModel(new DefaultComboBoxModel(mongoServers));
serverConfigurationCombobox.setRenderer(new ColoredListCellRenderer() {
@Override
protected void customizeCellRenderer(JList list, Object value, int index, boolean selected, boolean hasFocus) {
MongoServer serverConfiguration = (MongoServer) value;
append(serverConfiguration.getLabel());
}
});
databaseCombobox.setRenderer(new ColoredListCellRenderer() {
@Override
protected void customizeCellRenderer(JList list, Object value, int index, boolean selected, boolean hasFocus) {
MongoDatabase mongoDatabase = (MongoDatabase) value;
if (value == null) {
return;
}
append(mongoDatabase.getName());
}
});
serverConfigurationCombobox.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent itemEvent) {
MongoServer selectedServer = (MongoServer) serverConfigurationCombobox.getSelectedItem();
if (selectedServer == null) {
return;
}
databaseCombobox.removeAllItems();
for (MongoDatabase mongoDatabase: selectedServer.getDatabases()) {
databaseCombobox.addItem(mongoDatabase);
}
}
});