public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
boolean cellHasFocus) {
JLabel result = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (value instanceof DatabaseDriverDescriptor) {
DatabaseDriverDescriptor databaseDriver = (DatabaseDriverDescriptor) value;
String iconImagePath = DatabaseDriverCatalog.getIconImagePath(databaseDriver);
Icon driverIcon = imageManager.getImageIcon(iconImagePath, IconUtils.ICON_SIZE_SMALL);
result.setText(databaseDriver.getDisplayName());
result.setIcon(driverIcon);
} else if (MANAGE_DATABASE_DRIVERS.equals(value)) {
result.setIcon(imageManager.getImageIcon("images/menu/options.png", IconUtils.ICON_SIZE_SMALL));
} else if (value instanceof Component) {
return (Component) value;
}
return result;
}
});
_databaseDriverComboBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Object value = _databaseDriverComboBox.getSelectedItem();
if (value instanceof DatabaseDriverDescriptor) {
DatabaseDriverDescriptor driver = (DatabaseDriverDescriptor) value;
_driverClassNameTextField.setText(driver.getDriverClassName());
String[] connectionUrls = driver.getConnectionUrlTemplates();
setConnectionUrlTemplates(connectionUrls);
} else if (MANAGE_DATABASE_DRIVERS.equals(value)) {
OptionsDialog optionsDialog = _optionsDialogProvider.get();
optionsDialog.selectDatabaseDriversTab();
JdbcDatastoreDialog.this.dispose();
optionsDialog.setVisible(true);
optionsDialog.toFront();
}
}
});
_usernameTextField = WidgetFactory.createTextField("Username");
_passwordField = new JPasswordField(17);
if (_originalDatastore != null) {
// the database driver has to be set as the first thing, because the
// combobox's action listener will set other field's values as well.
DatabaseDriverDescriptor databaseDriver = DatabaseDriverCatalog
.getDatabaseDriverByDriverClassName(_originalDatastore.getDriverClass());
_databaseDriverComboBox.setSelectedItem(databaseDriver);
_datastoreNameTextField.setText(_originalDatastore.getName());
_datastoreNameTextField.setEnabled(false);