@Override
public void actionPerformed(final ActionEvent e) {
// Parent component.
final AdductsComponent parent = (AdductsComponent) SwingUtilities
.getAncestorOfClass(AdductsComponent.class,
(Component) e.getSource());
if (parent != null) {
// Create the chooser if necessary.
if (chooser == null) {
chooser = new LoadSaveFileChooser("Select Adducts File");
chooser.addChoosableFileFilter(new FileNameExtensionFilter(
"Comma-separated values files", FILENAME_EXTENSION));
}
// Select a file.
final File file = chooser.getLoadFile(parent);
if (file != null) {
// Read the CSV file into a string array.
String[][] csvLines = null;
try {
csvLines = CSVParser.parse(new FileReader(file));
} catch (IOException ex) {
final String msg = "There was a problem reading the adducts file.";
MZmineCore.getDesktop().displayErrorMessage("I/O Error",
msg + "\n(" + ex.getMessage() + ')');
LOG.log(Level.SEVERE, msg, ex);
}
// Read the adducts data.
if (csvLines != null) {
// Load adducts from CSV data into parent choices.
parent.setChoices(loadAdductsIntoChoices(csvLines,
(AdductType[]) parent.getChoices()));
}
}
}
}