Search in sources :

Example 1 with ProjectManager

use of net.sf.mzmine.project.ProjectManager in project mzmine2 by mzmine.

the class ProjectCloseModule method runModule.

@Override
@Nonnull
public ExitCode runModule(@Nonnull MZmineProject project, @Nonnull ParameterSet parameters, @Nonnull Collection<Task> tasks) {
    int selectedValue = JOptionPane.showInternalConfirmDialog(MZmineCore.getDesktop().getMainWindow().getContentPane(), "Are you sure you want to close the current project?", "Close project", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
    if (selectedValue != JOptionPane.YES_OPTION)
        return ExitCode.CANCEL;
    // Close all windows related to previous project
    GUIUtils.closeAllWindows();
    // Create a new, empty project
    MZmineProject newProject = new MZmineProjectImpl();
    // Replace the current project with the new one
    ProjectManager projectManager = MZmineCore.getProjectManager();
    projectManager.setCurrentProject(newProject);
    // Ask the garbage collector to free the previously used memory
    System.gc();
    logger.info("Project closed.");
    return ExitCode.OK;
}
Also used : MZmineProject(net.sf.mzmine.datamodel.MZmineProject) MZmineProjectImpl(net.sf.mzmine.project.impl.MZmineProjectImpl) ProjectManager(net.sf.mzmine.project.ProjectManager) Nonnull(javax.annotation.Nonnull)

Example 2 with ProjectManager

use of net.sf.mzmine.project.ProjectManager in project mzmine2 by mzmine.

the class ProjectOpeningTask method run.

/**
 * @see java.lang.Runnable#run()
 */
@Override
public void run() {
    try {
        // Check if existing raw data files are present
        ProjectManager projectManager = MZmineCore.getProjectManager();
        if (projectManager.getCurrentProject().getDataFiles().length > 0) {
            int dialogResult = JOptionPane.showConfirmDialog(null, "Loading the project will replace the existing raw data files and feature lists. Do you want to proceed?", "Warning", JOptionPane.YES_NO_OPTION);
            if (dialogResult != JOptionPane.YES_OPTION) {
                cancel();
                return;
            }
        }
        logger.info("Started opening project " + openFile);
        setStatus(TaskStatus.PROCESSING);
        // Create a new project
        newProject = new MZmineProjectImpl();
        newProject.setProjectFile(openFile);
        // Close all windows related to previous project
        GUIUtils.closeAllWindows();
        // Replace the current project with the new one
        projectManager.setCurrentProject(newProject);
        // Open the ZIP file
        ZipFile zipFile = new ZipFile(openFile);
        // Get total uncompressed size
        Enumeration<? extends ZipEntry> entries = zipFile.entries();
        while (entries.hasMoreElements()) {
            ZipEntry entry = entries.nextElement();
            totalBytes += entry.getSize();
        }
        final Pattern rawFilePattern = Pattern.compile("Raw data file #([\\d]+) (.*)\\.xml$");
        final Pattern scansFilePattern = Pattern.compile("Raw data file #([\\d]+) (.*)\\.scans$");
        final Pattern peakListPattern = Pattern.compile("Peak list #([\\d]+) (.*)\\.xml$");
        boolean versionInformationLoaded = false;
        // Iterate over the entries and read them
        entries = zipFile.entries();
        while (entries.hasMoreElements()) {
            if (isCanceled()) {
                zipFile.close();
                return;
            }
            ZipEntry entry = entries.nextElement();
            String entryName = entry.getName();
            cis = new CountingInputStream(zipFile.getInputStream(entry));
            // Load version
            if (entryName.equals(ProjectSavingTask.VERSION_FILENAME)) {
                loadVersion(cis);
                versionInformationLoaded = true;
            }
            // Load configuration
            if (entryName.equals(ProjectSavingTask.CONFIG_FILENAME))
                loadConfiguration(cis);
            // Load user parameters
            if (entryName.equals(ProjectSavingTask.PARAMETERS_FILENAME)) {
                loadUserParameters(cis);
            }
            // Load a raw data file
            final Matcher rawFileMatcher = rawFilePattern.matcher(entryName);
            if (rawFileMatcher.matches()) {
                final String fileID = rawFileMatcher.group(1);
                final String fileName = rawFileMatcher.group(2);
                loadRawDataFile(cis, fileID, fileName);
            }
            // Load the scan data of a raw data file
            final Matcher scansFileMatcher = scansFilePattern.matcher(entryName);
            if (scansFileMatcher.matches()) {
                final String fileID = scansFileMatcher.group(1);
                final String fileName = scansFileMatcher.group(2);
                loadScansFile(cis, fileID, fileName);
            }
            // Load a feature list
            final Matcher peakListMatcher = peakListPattern.matcher(entryName);
            if (peakListMatcher.matches()) {
                final String peakListName = peakListMatcher.group(2);
                loadPeakList(cis, peakListName);
            }
            // Close the ZIP entry
            cis.close();
            // Add the uncompressed entry size finishedBytes
            synchronized (this) {
                finishedBytes += entry.getSize();
                cis = null;
            }
        }
        // Finish and close the project ZIP file
        zipFile.close();
        if (!versionInformationLoaded) {
            throw new IOException("This file is not valid MZmine 2 project. It does not contain version information.");
        }
        // Final check for cancel
        if (isCanceled())
            return;
        logger.info("Finished opening project " + openFile);
        setStatus(TaskStatus.FINISHED);
        // add to last loaded projects
        MZmineCore.getConfiguration().getLastProjectsParameter().addFile(openFile);
    } catch (Throwable e) {
        // SAXException which can be safely ignored
        if (isCanceled())
            return;
        setStatus(TaskStatus.ERROR);
        e.printStackTrace();
        setErrorMessage("Failed opening project: " + ExceptionUtils.exceptionToString(e));
    }
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) ZipEntry(java.util.zip.ZipEntry) CountingInputStream(com.google.common.io.CountingInputStream) IOException(java.io.IOException) ProjectManager(net.sf.mzmine.project.ProjectManager) ZipFile(java.util.zip.ZipFile) MZmineProjectImpl(net.sf.mzmine.project.impl.MZmineProjectImpl)

Aggregations

ProjectManager (net.sf.mzmine.project.ProjectManager)2 MZmineProjectImpl (net.sf.mzmine.project.impl.MZmineProjectImpl)2 CountingInputStream (com.google.common.io.CountingInputStream)1 IOException (java.io.IOException)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 ZipEntry (java.util.zip.ZipEntry)1 ZipFile (java.util.zip.ZipFile)1 Nonnull (javax.annotation.Nonnull)1 MZmineProject (net.sf.mzmine.datamodel.MZmineProject)1