import javax.swing.JComboBox; //导入方法依赖的package包/类
public void actionPerformed(ActionEvent e) {
JComboBox databasesCombo = getSelectedDatabaseViewer().getCombo();
JCheckBox dropOnDbmsCheckBox = new JCheckBox("Drop database on DBMS too", true);
// There must be at least one database
if (databasesCombo.getItemCount() > 1) {
Database databaseToRemove = (Database)
getSelectedDatabaseViewer().getCombo().getSelectedItem();
String message = "Are you sure you want to drop the database '" +
databaseToRemove.getName() + "'?\n\n";
Object[] params = { message, dropOnDbmsCheckBox };
// Confirm deletion
int dialogResult = JOptionPane.showConfirmDialog (null,
params,
"Confirm Deletion",
JOptionPane.YES_NO_OPTION);
if(dialogResult == JOptionPane.YES_OPTION){
databasesCombo.removeItem((Database) databaseToRemove);
System.out.println("> Database '" + databaseToRemove.getName() + "' was dropped.");
// Drop it from DBMS?
if (dropOnDbmsCheckBox.isSelected()) {
try {
// Switch to an existing database
String existingDatabaseName = getSelectedDatabaseViewer()
.getSelectedDatabase().getName();
getSelectedDatabaseViewer().getSelectedDatabase().getDbmsDriver()
.switchDatabase(existingDatabaseName);
getSelectedDatabaseViewer().getSelectedDatabase().getDbmsDriver()
.dropDatabase(databaseToRemove.getName());
} catch (SQLException e1) {
e1.printStackTrace();
}
}
}
}
else {
JOptionPane.showMessageDialog(DatabaseViewer.this.getParent(),
"There must be at least one database.",
"Warning",
JOptionPane.INFORMATION_MESSAGE);
}
}