/** @see java.lang.Runnable#run() */
  public void run() {

    Task actualTask = wrappedTask.getActualTask();

    logger.finest("Starting processing of task: " + actualTask.getTaskDescription());

    try {

      // Process the actual task
      actualTask.run();

      // Check if task finished with an error
      if (actualTask.getStatus() == TaskStatus.ERROR) {
        logger.severe("Task error: " + actualTask.getErrorMessage());

        String errorMsg = actualTask.getErrorMessage();
        if (errorMsg == null) errorMsg = "Unspecified error";

        MZmineCore.getDesktop()
            .displayErrorMessage("Error of task " + actualTask.getTaskDescription(), errorMsg);
      }

      /*
       * This is important to allow the garbage collector to remove the
       * task, while keeping the task description in the
       * "Tasks in progress" window
       */
      wrappedTask.removeTaskReference();

    } catch (Throwable e) {

      /*
       * This should never happen, it means the task did not handle its
       * exception properly, or there was some severe error, like
       * OutOfMemoryError
       */

      logger.log(
          Level.SEVERE,
          "Unhandled exception " + e + " while processing task " + actualTask.getTaskDescription(),
          e);

      e.printStackTrace();

      MZmineCore.getDesktop()
          .displayErrorMessage(
              "Unhandled exception in task "
                  + actualTask.getTaskDescription()
                  + ": "
                  + ExceptionUtils.exceptionToString(e));
    }

    /*
     * Mark this thread as finished
     */
    finished = true;
  }
  @Override
  @Nonnull
  public ExitCode runModule(@Nonnull ParameterSet parameters, @Nonnull Collection<Task> tasks) {
    final RawDataFile[] dataFiles =
        parameters.getParameter(TICVisualizerParameters.DATA_FILES).getValue();
    final int msLevel = parameters.getParameter(TICVisualizerParameters.MS_LEVEL).getValue();
    final Range rtRange = parameters.getParameter(TICVisualizerParameters.RT_RANGE).getValue();
    final Range mzRange = parameters.getParameter(TICVisualizerParameters.MZ_RANGE).getValue();
    final PlotType plotType = parameters.getParameter(TICVisualizerParameters.PLOT_TYPE).getValue();
    final ChromatographicPeak[] selectionPeaks =
        parameters.getParameter(TICVisualizerParameters.PEAKS).getValue();

    if (dataFiles == null || dataFiles.length == 0) {

      MZmineCore.getDesktop().displayErrorMessage("Please select raw data file(s)");

    } else {

      // Add the window to the desktop only if we actually have any raw
      // data to show.
      boolean weHaveData = false;
      for (int i = 0, dataFilesLength = dataFiles.length; !weHaveData && i < dataFilesLength; i++) {

        weHaveData = dataFiles[i].getScanNumbers(msLevel, rtRange).length > 0;
      }

      if (weHaveData) {

        MZmineCore.getDesktop()
            .addInternalFrame(
                new TICVisualizerWindow(
                    dataFiles,
                    plotType,
                    msLevel,
                    rtRange,
                    mzRange,
                    selectionPeaks,
                    ((TICVisualizerParameters) parameters).getPeakLabelMap()));

      } else {

        MZmineCore.getDesktop()
            .displayErrorMessage(
                "No scans found at MS level " + msLevel + " within given retention time range.");
      }
    }

    return ExitCode.OK;
  }
  public ExitCode showSetupDialog() {

    JFileChooser chooser = new JFileChooser();

    for (FileFilter filter : filters) chooser.setFileFilter(filter);
    chooser.setFileFilter(filters[0]);

    File lastFiles[] = getParameter(fileNames).getValue();
    if ((lastFiles != null) && (lastFiles.length > 0)) {
      File currentDir = lastFiles[0].getParentFile();
      if ((currentDir != null) && (currentDir.exists())) chooser.setCurrentDirectory(currentDir);
    }

    chooser.setMultiSelectionEnabled(true);

    int returnVal = chooser.showOpenDialog(MZmineCore.getDesktop().getMainWindow());

    if (returnVal != JFileChooser.APPROVE_OPTION) return ExitCode.CANCEL;

    File selectedFiles[] = chooser.getSelectedFiles();

    getParameter(fileNames).setValue(selectedFiles);

    return ExitCode.OK;
  }
  public MsMsVisualizerWindow(
      RawDataFile dataFile,
      Range<Double> rtRange,
      Range<Double> mzRange,
      IntensityType intensityType,
      NormalizationType normalizationType,
      Double minPeakInt,
      ParameterSet parameters) {

    super("MS/MS visualizer: [" + dataFile.getName() + "]");

    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    setBackground(Color.white);

    this.dataFile = dataFile;
    this.tooltipMode = true;

    dataset =
        new MsMsDataSet(
            dataFile, rtRange, mzRange, intensityType, normalizationType, minPeakInt, this);

    toolBar = new MsMsToolBar(this);
    add(toolBar, BorderLayout.EAST);

    IDAPlot = new MsMsPlot(this, dataFile, this, dataset, rtRange, mzRange);
    add(IDAPlot, BorderLayout.CENTER);

    bottomPanel = new MsMsBottomPanel(this, dataFile, parameters);
    add(bottomPanel, BorderLayout.SOUTH);

    updateTitle();

    // After we have constructed everything, load the peak lists into the
    // bottom panel
    bottomPanel.rebuildPeakListSelector();

    MZmineCore.getDesktop().addPeakListTreeListener(bottomPanel);

    // Add the Windows menu
    JMenuBar menuBar = new JMenuBar();
    menuBar.add(new WindowsMenu());
    setJMenuBar(menuBar);

    pack();

    // get the window settings parameter
    ParameterSet paramSet =
        MZmineCore.getConfiguration().getModuleParameters(MsMsVisualizerModule.class);
    WindowSettingsParameter settings = paramSet.getParameter(MsMsParameters.windowSettings);

    // update the window and listen for changes
    settings.applySettingsToWindow(this);
    this.addComponentListener(settings);
  }
  public static void showNewTICVisualizerWindow(
      final RawDataFile[] dataFiles,
      final ChromatographicPeak[] selectionPeaks,
      final Map<ChromatographicPeak, String> peakLabels,
      final int msLevel,
      final PlotType plotType,
      final Range rtRange,
      final Range mzRange) {

    MZmineCore.getDesktop()
        .addInternalFrame(
            new TICVisualizerWindow(
                dataFiles, plotType, msLevel, rtRange, mzRange, selectionPeaks, peakLabels));
  }
 public void dispose() {
   super.dispose();
   MZmineCore.getDesktop().removePeakListTreeListener(bottomPanel);
 }