Set the actual name after duplicate check to the file rename module
+/*
+ * Copyright 2006-2020 The MZmine Development Team
+ *
+ * This file is part of MZmine.
+ *
+ * MZmine is free software; you can redistribute it and/or modify it under the terms of the GNU
+ * General Public License as published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * MZmine is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
+ * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+ * Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with MZmine; if not,
+ * write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
package io.github.mzmine.modules.tools.rawfilerename;
import io.github.mzmine.datamodel.MZmineProject;
@@ -16,7 +33,6 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;
-import java.util.Optional;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -95,15 +111,11 @@ public class RawDataFileRenameModule implements MZmineProcessingModule {
}
RawDataFile file = matchingRawDataFiles[0];
- Optional<RawDataFile> any = project.getRawDataFiles().stream()
- .filter(f -> f.getName().equals(newName)).findAny();
- if (any.isPresent() && !any.get().equals(file)) {
- MZmineCore.getDesktop().displayErrorMessage("File with name " + newName + " already exists");
- return ExitCode.OK;
- }
+ // set name is now threadsafe and will return the set name after checking for duplicates etc
+ final String realName = file.setName(newName);
+ parameters.setParameter(RawDataFileRenameParameters.newName, realName);
- MZmineCore.runLater(() -> file.setName(newName));
file.getAppliedMethods()
.add(new SimpleFeatureListAppliedMethod(this, parameters, moduleCallDate));
