Search in sources :

Example 1 with PeptideShakerGUI

use of eu.isas.peptideshaker.gui.PeptideShakerGUI in project peptide-shaker by compomics.

the class InclusionListExportDialog method okButtonActionPerformed.

// GEN-LAST:event_cancelButtonActionPerformed
/**
 * Open a file chooser and when file is selected start the export.
 *
 * @param evt
 */
private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {
    if (validateInput()) {
        LastSelectedFolder lastSelectedFolder = followupPreferencesDialog.getPeptideShakerGUI().getLastSelectedFolder();
        String folder = lastSelectedFolder.getLastSelectedFolder(ExportWriter.LAST_FOLDER_KEY);
        if (folder == null) {
            folder = lastSelectedFolder.getLastSelectedFolder();
        }
        final JFileChooser fileChooser = new JFileChooser(folder);
        fileChooser.setDialogTitle("Select Destination File");
        fileChooser.setMultiSelectionEnabled(false);
        FileFilter filter = new FileFilter() {

            @Override
            public boolean accept(File myFile) {
                return myFile.isDirectory() || myFile.getName().endsWith(exportFormat.extension);
            }

            @Override
            public String getDescription() {
                switch(exportFormat) {
                    case Thermo:
                        return "(Thermo inclusion list) .txt";
                    case ABI:
                        return "(ABI inclusion list) .txt";
                    case Bruker:
                        return "(Bruker inclusion list) .csv";
                    case MassLynx:
                        return "(MassLynx inclusion list) .txt";
                    default:
                        return "(unknown format) .txt";
                }
            }
        };
        fileChooser.setFileFilter(filter);
        int returnVal = fileChooser.showSaveDialog(this);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File tempOutputFile = fileChooser.getSelectedFile();
            tempOutputFile = ExportFormat.verifyFileExtension(tempOutputFile, exportFormat);
            int outcome = JOptionPane.YES_OPTION;
            if (tempOutputFile.exists()) {
                outcome = JOptionPane.showConfirmDialog(this, "Should " + tempOutputFile + " be overwritten?", "Selected File Already Exists", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
            }
            if (outcome == JOptionPane.YES_OPTION) {
                dispose();
                progressDialog = new ProgressDialogX(this, followupPreferencesDialog.getPeptideShakerGUI(), Toolkit.getDefaultToolkit().getImage(getClass().getResource("/icons/peptide-shaker.gif")), Toolkit.getDefaultToolkit().getImage(getClass().getResource("/icons/peptide-shaker-orange.gif")), true);
                progressDialog.setPrimaryProgressCounterIndeterminate(true);
                progressDialog.setTitle("Exporting. Please Wait...");
                // needed due to threading issues
                final File outputFile = tempOutputFile;
                new Thread(new Runnable() {

                    public void run() {
                        progressDialog.setVisible(true);
                    }
                }, "ProgressDialog").start();
                new Thread("SaveThread") {

                    @Override
                    public void run() {
                        try {
                            PeptideShakerGUI peptideShakerGUI = followupPreferencesDialog.getPeptideShakerGUI();
                            double rtWindowDouble = Double.parseDouble(rtWindow.getText());
                            InclusionListExport.exportInclusionList(outputFile, peptideShakerGUI.getIdentification(), peptideShakerGUI.getIdentificationFeaturesGenerator(), peptideShakerGUI.getSpectrumProvider(), getProteinFilters(), getPeptideFilters(), exportFormat, peptideShakerGUI.getIdentificationParameters().getSearchParameters(), rtWindowDouble, progressDialog, peptideShakerGUI.getFilterParameters());
                            boolean processCancelled = progressDialog.isRunCanceled();
                            progressDialog.setRunFinished();
                            if (!processCancelled) {
                                JOptionPane.showMessageDialog(followupPreferencesDialog, "Inclusion list saved to " + fileChooser.getSelectedFile().getName() + ".", "Save Complete", JOptionPane.INFORMATION_MESSAGE);
                            }
                        } catch (Exception e) {
                            progressDialog.setRunFinished();
                            e.printStackTrace();
                            JOptionPane.showMessageDialog(followupPreferencesDialog, "An error occurred when saving the file.", "Saving Failed", JOptionPane.ERROR_MESSAGE);
                        }
                    }
                }.start();
            }
        }
    }
}
Also used : ProgressDialogX(com.compomics.util.gui.waiting.waitinghandlers.ProgressDialogX) JFileChooser(javax.swing.JFileChooser) PeptideShakerGUI(eu.isas.peptideshaker.gui.PeptideShakerGUI) LastSelectedFolder(com.compomics.util.io.file.LastSelectedFolder) FileFilter(javax.swing.filechooser.FileFilter) File(java.io.File)

Aggregations

ProgressDialogX (com.compomics.util.gui.waiting.waitinghandlers.ProgressDialogX)1 LastSelectedFolder (com.compomics.util.io.file.LastSelectedFolder)1 PeptideShakerGUI (eu.isas.peptideshaker.gui.PeptideShakerGUI)1 File (java.io.File)1 JFileChooser (javax.swing.JFileChooser)1 FileFilter (javax.swing.filechooser.FileFilter)1