use of net.sf.mzmine.parameters.parametertypes.LipidModificationChoiceComponent in project mzmine2 by mzmine.
the class AddLipidModificationAction method actionPerformed.
@Override
public void actionPerformed(final ActionEvent e) {
// Parent component.
final LipidModificationChoiceComponent parent = (LipidModificationChoiceComponent) SwingUtilities.getAncestorOfClass(LipidModificationChoiceComponent.class, (Component) e.getSource());
if (parent != null) {
// Show dialog.
final ParameterSet parameters = new AddLipidModificationParameters();
if (parameters.showSetupDialog(MZmineCore.getDesktop().getMainWindow(), true) == ExitCode.OK) {
// Create new lipid modification
lipidModification = new LipidModification(parameters.getParameter(AddLipidModificationParameters.lipidModification).getValue(), parameters.getParameter(AddLipidModificationParameters.lipidModificationLabel).getValue());
// Add to list of choices (if not already present).
final Collection<LipidModification> choices = new ArrayList<LipidModification>(Arrays.asList((LipidModification[]) parent.getChoices()));
if (!choices.contains(lipidModification)) {
choices.add(lipidModification);
parent.setChoices(choices.toArray(new LipidModification[choices.size()]));
}
}
}
}
use of net.sf.mzmine.parameters.parametertypes.LipidModificationChoiceComponent in project mzmine2 by mzmine.
the class ImportLipidModificationsAction method actionPerformed.
@Override
public void actionPerformed(final ActionEvent e) {
// Parent component.
final LipidModificationChoiceComponent parent = (LipidModificationChoiceComponent) SwingUtilities.getAncestorOfClass(LipidModificationChoiceComponent.class, (Component) e.getSource());
if (parent != null) {
// Create the chooser if necessary.
if (chooser == null) {
chooser = new LoadSaveFileChooser("Select lipid modification 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 Window window = (Window) SwingUtilities.getAncestorOfClass(Window.class, (Component) e.getSource());
final String msg = "There was a problem reading the lipid modification file.";
MZmineCore.getDesktop().displayErrorMessage(window, "I/O Error", msg + "\n(" + ex.getMessage() + ')');
LOG.log(Level.SEVERE, msg, ex);
}
// Read the lipid modifications data.
if (csvLines != null) {
// Load adducts from CSV data into parent choices.
parent.setChoices(loadLipidModificationsIntoChoices(csvLines, (LipidModification[]) parent.getChoices()));
}
}
}
}
use of net.sf.mzmine.parameters.parametertypes.LipidModificationChoiceComponent in project mzmine2 by mzmine.
the class ExportLipidModificationsAction method actionPerformed.
@Override
public void actionPerformed(final ActionEvent e) {
// Parent component.
final LipidModificationChoiceComponent parent = (LipidModificationChoiceComponent) SwingUtilities.getAncestorOfClass(LipidModificationChoiceComponent.class, (Component) e.getSource());
if (parent != null) {
// Create the chooser if necessary.
if (chooser == null) {
chooser = new LoadSaveFileChooser("Select lipid modifications File");
chooser.addChoosableFileFilter(new FileNameExtensionFilter("Comma-separated values files", FILENAME_EXTENSION));
}
// Choose the file.
final File file = chooser.getSaveFile(parent, FILENAME_EXTENSION);
if (file != null) {
// Export the modifications.
try {
exportLipidModificationsToFile(file, (LipidModification[]) parent.getChoices());
} catch (IOException ex) {
final Window window = (Window) SwingUtilities.getAncestorOfClass(Window.class, (Component) e.getSource());
final String msg = "There was a problem writing the lipid modifications file.";
MZmineCore.getDesktop().displayErrorMessage(window, "I/O Error", msg + "\n(" + ex.getMessage() + ')');
LOG.log(Level.SEVERE, msg, ex);
}
}
}
}
Aggregations