From 212f9a32d7f24e00f5eeffc17cdecf99b9923a16 Mon Sep 17 00:00:00 2001 From: Philip Wenig Date: Wed, 20 Oct 2021 11:39:18 +0200 Subject: [PATCH] Fixed #789 - Import *.msl, *.msp files - Support Charset --- .../META-INF/MANIFEST.MF | 2 +- .../amdis/ui/preferences/PreferencePage.java | 12 ++- .../.project | 5 ++ .../org.eclipse.pde.ds.annotations.prefs | 6 ++ .../META-INF/MANIFEST.MF | 7 +- ...pplier.amdis.system.ConverterProcessor.xml | 7 ++ .../supplier/amdis/io/ELUReader.java | 7 +- .../supplier/amdis/io/FINReader.java | 10 ++- .../supplier/amdis/io/MSLReader.java | 4 +- .../supplier/amdis/io/MSPReader.java | 54 ++++++------ .../amdis/preferences/PreferenceSupplier.java | 85 ++++++++++++++++++- .../amdis/system/ConverterProcessor.java | 58 +++++++++++++ .../amdis/system/ConverterSettings.java | 74 ++++++++++++++++ .../chemclipse/support/text/CharsetNIO.java | 57 +++++++++++++ 14 files changed, 344 insertions(+), 44 deletions(-) create mode 100644 chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.amdis/.settings/org.eclipse.pde.ds.annotations.prefs create mode 100644 chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.amdis/OSGI-INF/org.eclipse.chemclipse.msd.converter.supplier.amdis.system.ConverterProcessor.xml create mode 100644 chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.amdis/src/org/eclipse/chemclipse/msd/converter/supplier/amdis/system/ConverterProcessor.java create mode 100644 chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.amdis/src/org/eclipse/chemclipse/msd/converter/supplier/amdis/system/ConverterSettings.java create mode 100644 chemclipse/plugins/org.eclipse.chemclipse.support/src/org/eclipse/chemclipse/support/text/CharsetNIO.java diff --git a/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.amdis.ui/META-INF/MANIFEST.MF b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.amdis.ui/META-INF/MANIFEST.MF index a7815d141b..9ba07cccfe 100644 --- a/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.amdis.ui/META-INF/MANIFEST.MF +++ b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.amdis.ui/META-INF/MANIFEST.MF @@ -1,7 +1,7 @@ Manifest-Version: 1.0 Automatic-Module-Name: org.eclipse.chemclipse.msd.converter.supplier.amdis.ui Bundle-ManifestVersion: 2 -Bundle-Name: Ui +Bundle-Name: AMDIS Converter UI Bundle-SymbolicName: org.eclipse.chemclipse.msd.converter.supplier.amdis.ui;singleton:=true Bundle-Version: 0.9.0.qualifier Bundle-Activator: org.eclipse.chemclipse.msd.converter.supplier.amdis.ui.Activator diff --git a/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.amdis.ui/src/org/eclipse/chemclipse/msd/converter/supplier/amdis/ui/preferences/PreferencePage.java b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.amdis.ui/src/org/eclipse/chemclipse/msd/converter/supplier/amdis/ui/preferences/PreferencePage.java index 00b434d548..87c8e91c8f 100644 --- a/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.amdis.ui/src/org/eclipse/chemclipse/msd/converter/supplier/amdis/ui/preferences/PreferencePage.java +++ b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.amdis.ui/src/org/eclipse/chemclipse/msd/converter/supplier/amdis/ui/preferences/PreferencePage.java @@ -13,7 +13,10 @@ import org.eclipse.chemclipse.msd.converter.supplier.amdis.preferences.PreferenceSupplier; import org.eclipse.chemclipse.msd.converter.supplier.amdis.ui.Activator; +import org.eclipse.chemclipse.support.text.CharsetNIO; +import org.eclipse.chemclipse.support.ui.preferences.fieldeditors.SpacerFieldEditor; import org.eclipse.jface.preference.BooleanFieldEditor; +import org.eclipse.jface.preference.ComboFieldEditor; import org.eclipse.jface.preference.FieldEditorPreferencePage; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPreferencePage; @@ -24,7 +27,8 @@ public PreferencePage() { super(GRID); setPreferenceStore(Activator.getDefault().getPreferenceStore()); - setDescription("AMDIS Settings."); + setTitle("AMDIS Converter"); + setDescription(""); } /** @@ -42,6 +46,12 @@ public void createFieldEditors() { addField(new BooleanFieldEditor(PreferenceSupplier.P_EXPORT_INTENSITIES_AS_INTEGER, "Export intensities as Integer", getFieldEditorParent())); addField(new BooleanFieldEditor(PreferenceSupplier.P_PARSE_COMPOUND_INFORMATION, "Parse Compound Information (*.CID)", getFieldEditorParent())); addField(new BooleanFieldEditor(PreferenceSupplier.P_PARSE_MOL_INFORMATION, "Parse MOL Information (*.MOL)", getFieldEditorParent())); + // + addField(new SpacerFieldEditor(getFieldEditorParent())); + addField(new ComboFieldEditor(PreferenceSupplier.P_CHARSET_IMPORT_MSL, "Charset Import MSL", CharsetNIO.getOptions(), getFieldEditorParent())); + addField(new ComboFieldEditor(PreferenceSupplier.P_CHARSET_IMPORT_MSP, "Charset Import MSP", CharsetNIO.getOptions(), getFieldEditorParent())); + addField(new ComboFieldEditor(PreferenceSupplier.P_CHARSET_IMPORT_FIN, "Charset Import FIN", CharsetNIO.getOptions(), getFieldEditorParent())); + addField(new ComboFieldEditor(PreferenceSupplier.P_CHARSET_IMPORT_ELU, "Charset Import ELU", CharsetNIO.getOptions(), getFieldEditorParent())); } /* diff --git a/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.amdis/.project b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.amdis/.project index 37ec23862f..f643d1b03a 100644 --- a/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.amdis/.project +++ b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.amdis/.project @@ -20,6 +20,11 @@ + + org.eclipse.pde.ds.core.builder + + + org.eclipse.pde.PluginNature diff --git a/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.amdis/.settings/org.eclipse.pde.ds.annotations.prefs b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.amdis/.settings/org.eclipse.pde.ds.annotations.prefs new file mode 100644 index 0000000000..960a807c0b --- /dev/null +++ b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.amdis/.settings/org.eclipse.pde.ds.annotations.prefs @@ -0,0 +1,6 @@ +eclipse.preferences.version=1 +enabled=true +generateBundleActivationPolicyLazy=true +path=OSGI-INF +validationErrorLevel=error +validationErrorLevel.missingImplicitUnbindMethod=error diff --git a/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.amdis/META-INF/MANIFEST.MF b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.amdis/META-INF/MANIFEST.MF index d9657d2e7b..8b9c75b672 100644 --- a/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.amdis/META-INF/MANIFEST.MF +++ b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.amdis/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Automatic-Module-Name: org.eclipse.chemclipse.msd.converter.supplier.amdis Eclipse-RegisterBuddy: org.eclipse.chemclipse.model, org.eclipse.chemclipse.msd.model Bundle-ManifestVersion: 2 -Bundle-Name: Amdis Plug-in +Bundle-Name: AMDIS Converter Bundle-SymbolicName: org.eclipse.chemclipse.msd.converter.supplier.amdis;singleton:=true Bundle-Version: 0.9.0.qualifier Bundle-Activator: org.eclipse.chemclipse.msd.converter.supplier.amdis.Activator @@ -15,10 +15,13 @@ Require-Bundle: org.eclipse.core.runtime, org.eclipse.chemclipse.model;bundle-version="0.8.0", org.apache.commons.io;bundle-version="2.2.0", org.eclipse.chemclipse.support;bundle-version="0.8.0", - org.eclipse.chemclipse.numeric;bundle-version="0.8.0" + org.eclipse.chemclipse.numeric;bundle-version="0.8.0", + com.fasterxml.jackson.core.jackson-annotations;bundle-version="2.9.9" Bundle-ActivationPolicy: lazy +Import-Package: org.osgi.service.component.annotations;version="1.2.0" Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Bundle-Vendor: ChemClipse Export-Package: org.eclipse.chemclipse.msd.converter.supplier.amdis.converter.misc, org.eclipse.chemclipse.msd.converter.supplier.amdis.model, org.eclipse.chemclipse.msd.converter.supplier.amdis.preferences +Service-Component: OSGI-INF/org.eclipse.chemclipse.msd.converter.supplier.amdis.system.ConverterProcessor.xml diff --git a/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.amdis/OSGI-INF/org.eclipse.chemclipse.msd.converter.supplier.amdis.system.ConverterProcessor.xml b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.amdis/OSGI-INF/org.eclipse.chemclipse.msd.converter.supplier.amdis.system.ConverterProcessor.xml new file mode 100644 index 0000000000..414421bbeb --- /dev/null +++ b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.amdis/OSGI-INF/org.eclipse.chemclipse.msd.converter.supplier.amdis.system.ConverterProcessor.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.amdis/src/org/eclipse/chemclipse/msd/converter/supplier/amdis/io/ELUReader.java b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.amdis/src/org/eclipse/chemclipse/msd/converter/supplier/amdis/io/ELUReader.java index 14c67a4649..ea537d606a 100644 --- a/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.amdis/src/org/eclipse/chemclipse/msd/converter/supplier/amdis/io/ELUReader.java +++ b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.amdis/src/org/eclipse/chemclipse/msd/converter/supplier/amdis/io/ELUReader.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2014, 2020 Lablicate GmbH. + * Copyright (c) 2014, 2021 Lablicate GmbH. * * All rights reserved. * This program and the accompanying materials are made available under the @@ -15,7 +15,7 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; -import java.nio.charset.StandardCharsets; +import java.nio.charset.Charset; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -73,8 +73,9 @@ public class ELUReader implements IPeakReader { @Override public IProcessingInfo> read(File file, IProgressMonitor monitor) throws FileNotFoundException, FileIsNotReadableException, FileIsEmptyException, IOException { + Charset charset = PreferenceSupplier.getCharsetImportELU(); IProcessingInfo> processingInfo = new ProcessingInfo>(); - String content = FileUtils.readFileToString(file, StandardCharsets.US_ASCII); + String content = FileUtils.readFileToString(file, charset); int numberOfHits = getNumberOfHits(content); if(numberOfHits <= 0) { processingInfo.addErrorMessage("AMDIS ELU Parser", "There seems to be no peak in the file."); diff --git a/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.amdis/src/org/eclipse/chemclipse/msd/converter/supplier/amdis/io/FINReader.java b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.amdis/src/org/eclipse/chemclipse/msd/converter/supplier/amdis/io/FINReader.java index b3472d40ac..a7c5bb0846 100644 --- a/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.amdis/src/org/eclipse/chemclipse/msd/converter/supplier/amdis/io/FINReader.java +++ b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.amdis/src/org/eclipse/chemclipse/msd/converter/supplier/amdis/io/FINReader.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2020 Lablicate GmbH. + * Copyright (c) 2020, 2021 Lablicate GmbH. * * All rights reserved. * This program and the accompanying materials are made available under the @@ -13,15 +13,18 @@ import java.io.BufferedReader; import java.io.File; +import java.io.FileInputStream; import java.io.FileNotFoundException; -import java.io.FileReader; import java.io.IOException; +import java.io.InputStreamReader; +import java.nio.charset.Charset; import org.eclipse.chemclipse.converter.exceptions.FileIsEmptyException; import org.eclipse.chemclipse.converter.exceptions.FileIsNotReadableException; import org.eclipse.chemclipse.msd.converter.io.AbstractMassSpectraReader; import org.eclipse.chemclipse.msd.converter.io.IMassSpectraReader; import org.eclipse.chemclipse.msd.converter.supplier.amdis.model.IVendorLibraryMassSpectrum; +import org.eclipse.chemclipse.msd.converter.supplier.amdis.preferences.PreferenceSupplier; import org.eclipse.chemclipse.msd.model.core.IMassSpectra; import org.eclipse.chemclipse.msd.model.implementation.MassSpectra; import org.eclipse.core.runtime.IProgressMonitor; @@ -64,7 +67,8 @@ private void parse(IMassSpectra massSpectra, File file, IProgressMonitor monitor * ... */ if(file != null && file.exists()) { - try (BufferedReader bufferedReader = new BufferedReader(new FileReader(file))) { + Charset charset = PreferenceSupplier.getCharsetImportFIN(); + try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(file), charset))) { /* * Settings and builder. */ diff --git a/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.amdis/src/org/eclipse/chemclipse/msd/converter/supplier/amdis/io/MSLReader.java b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.amdis/src/org/eclipse/chemclipse/msd/converter/supplier/amdis/io/MSLReader.java index 3af6132b0e..9ca920cb81 100644 --- a/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.amdis/src/org/eclipse/chemclipse/msd/converter/supplier/amdis/io/MSLReader.java +++ b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.amdis/src/org/eclipse/chemclipse/msd/converter/supplier/amdis/io/MSLReader.java @@ -64,7 +64,6 @@ public class MSLReader extends AbstractMassSpectraReader implements IMassSpectra private static final Pattern DATA = Pattern.compile("(.*)(Num Peaks:)(\\s*)(\\d*)(.*)", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL); private static final Pattern IONS = Pattern.compile("([+]?\\d+\\.?\\d*)(\\s+)([+-]?\\d+\\.?\\d*([eE][+-]?\\d+)?)"); // "(\\d+)(\\s+)(\\d+)" or "(\\d+)(\\s+)([+-]?\\d+\\.?\\d*([eE][+-]?\\d+)?)" // - private static final String CHARSET_US = "US-ASCII"; private static final String RETENTION_INDICES_DELIMITER = ", "; private static final String LINE_DELIMITER = "\r\n"; @@ -160,7 +159,7 @@ protected IVendorLibraryMassSpectrum extractMassSpectrum(String massSpectrumData */ private List getMassSpectraData(File file) throws IOException { - Charset charset = Charset.forName(CHARSET_US); + Charset charset = PreferenceSupplier.getCharsetImportMSL(); List massSpectraData = new ArrayList(); // try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(file), charset))) { @@ -186,7 +185,6 @@ private List getMassSpectraData(File file) throws IOException { * Don't forget to add the last mass spectrum. */ addMassSpectrumData(builder, massSpectraData); - bufferedReader.close(); } // return massSpectraData; diff --git a/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.amdis/src/org/eclipse/chemclipse/msd/converter/supplier/amdis/io/MSPReader.java b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.amdis/src/org/eclipse/chemclipse/msd/converter/supplier/amdis/io/MSPReader.java index 80e8146c3a..0d678cf6dc 100644 --- a/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.amdis/src/org/eclipse/chemclipse/msd/converter/supplier/amdis/io/MSPReader.java +++ b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.amdis/src/org/eclipse/chemclipse/msd/converter/supplier/amdis/io/MSPReader.java @@ -11,7 +11,6 @@ *******************************************************************************/ package org.eclipse.chemclipse.msd.converter.supplier.amdis.io; -import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; @@ -114,39 +113,34 @@ public IMassSpectra read(File file, IProgressMonitor monitor) throws FileNotFoun */ private List getMassSpectraData(File file) throws IOException { - Charset charSet = Charset.forName("US-ASCII"); - BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(file)); - InputStreamReader inputStreamReader = new InputStreamReader(bufferedInputStream, charSet); - BufferedReader bufferedReader = new BufferedReader(inputStreamReader); + Charset charset = PreferenceSupplier.getCharsetImportMSP(); List massSpectraData = new ArrayList(); - StringBuilder builder = new StringBuilder(); - String line; - while((line = bufferedReader.readLine()) != null) { + // + try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(file), charset))) { + StringBuilder builder = new StringBuilder(); + String line; + while((line = bufferedReader.readLine()) != null) { + /* + * The mass spectra are divided by empty lines. If the builder has + * at least 1 char, then add a new potential mass spectrum to the + * mass spectra data list. Don't forget to build a new + * StringBuilder. In all other cases append the found lines to the + * StringBuilder. + */ + if(line.length() == 0) { + addMassSpectrumData(builder, massSpectraData); + builder = new StringBuilder(); + } else { + builder.append(line); + builder.append(LINE_END); + } + } /* - * The mass spectra are divided by empty lines. If the builder has - * at least 1 char, then add a new potential mass spectrum to the - * mass spectra data list. Don't forget to build a new - * StringBuilder. In all other cases append the found lines to the - * StringBuilder. + * Don't forget to add the last mass spectrum. */ - if(line.length() == 0) { - addMassSpectrumData(builder, massSpectraData); - builder = new StringBuilder(); - } else { - builder.append(line); - builder.append(LINE_END); - } + addMassSpectrumData(builder, massSpectraData); } - /* - * Don't forget to add the last mass spectrum. - */ - addMassSpectrumData(builder, massSpectraData); - /* - * Close the streams. - */ - bufferedReader.close(); - inputStreamReader.close(); - bufferedInputStream.close(); + // return massSpectraData; } diff --git a/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.amdis/src/org/eclipse/chemclipse/msd/converter/supplier/amdis/preferences/PreferenceSupplier.java b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.amdis/src/org/eclipse/chemclipse/msd/converter/supplier/amdis/preferences/PreferenceSupplier.java index 42ff11f777..0af53d90b1 100644 --- a/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.amdis/src/org/eclipse/chemclipse/msd/converter/supplier/amdis/preferences/PreferenceSupplier.java +++ b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.amdis/src/org/eclipse/chemclipse/msd/converter/supplier/amdis/preferences/PreferenceSupplier.java @@ -11,17 +11,23 @@ *******************************************************************************/ package org.eclipse.chemclipse.msd.converter.supplier.amdis.preferences; +import java.nio.charset.Charset; import java.util.HashMap; import java.util.Map; +import org.eclipse.chemclipse.logging.core.Logger; import org.eclipse.chemclipse.msd.converter.supplier.amdis.Activator; import org.eclipse.chemclipse.support.preferences.IPreferenceSupplier; +import org.eclipse.chemclipse.support.text.CharsetNIO; import org.eclipse.core.runtime.preferences.IEclipsePreferences; import org.eclipse.core.runtime.preferences.IScopeContext; import org.eclipse.core.runtime.preferences.InstanceScope; +import org.osgi.service.prefs.BackingStoreException; public class PreferenceSupplier implements IPreferenceSupplier { + private static final Logger logger = Logger.getLogger(PreferenceSupplier.class); + // public static final String P_SPLIT_LIBRARY = "splitLibrary"; public static final boolean DEF_SPLIT_LIBRARY = false; public static final String P_EXCLUDE_UNCERTAIN_IONS = "excludeUncertainIons"; @@ -39,6 +45,15 @@ public class PreferenceSupplier implements IPreferenceSupplier { public static final String P_PARSE_MOL_INFORMATION = "parseMolInformation"; public static final boolean DEF_PARSE_MOL_INFORMATION = true; // + public static final String P_CHARSET_IMPORT_MSL = "charsetImportMSL"; + public static final String DEF_CHARSET_IMPORT_MSL = CharsetNIO.US_ASCII.name(); + public static final String P_CHARSET_IMPORT_MSP = "charsetImportMSP"; + public static final String DEF_CHARSET_IMPORT_MSP = CharsetNIO.US_ASCII.name(); + public static final String P_CHARSET_IMPORT_FIN = "charsetImportFIN"; + public static final String DEF_CHARSET_IMPORT_FIN = CharsetNIO.US_ASCII.name(); + public static final String P_CHARSET_IMPORT_ELU = "charsetImportELU"; + public static final String DEF_CHARSET_IMPORT_ELU = CharsetNIO.US_ASCII.name(); + // private static IPreferenceSupplier preferenceSupplier; public static IPreferenceSupplier INSTANCE() { @@ -65,6 +80,7 @@ public String getPreferenceNode() { public Map getDefaultValues() { Map defaultValues = new HashMap(); + // defaultValues.put(P_SPLIT_LIBRARY, Boolean.toString(DEF_SPLIT_LIBRARY)); defaultValues.put(P_EXCLUDE_UNCERTAIN_IONS, Boolean.toString(DEF_EXCLUDE_UNCERTAIN_IONS)); defaultValues.put(P_USE_UNIT_MASS_RESOLUTION, Boolean.toString(DEF_USE_UNIT_MASS_RESOLUTION)); @@ -73,6 +89,12 @@ public Map getDefaultValues() { defaultValues.put(P_EXPORT_INTENSITIES_AS_INTEGER, Boolean.toString(DEF_EXPORT_INTENSITIES_AS_INTEGER)); defaultValues.put(P_PARSE_COMPOUND_INFORMATION, Boolean.toString(DEF_PARSE_COMPOUND_INFORMATION)); defaultValues.put(P_PARSE_MOL_INFORMATION, Boolean.toString(DEF_PARSE_MOL_INFORMATION)); + // + defaultValues.put(P_CHARSET_IMPORT_MSL, DEF_CHARSET_IMPORT_MSL); + defaultValues.put(P_CHARSET_IMPORT_MSP, DEF_CHARSET_IMPORT_MSP); + defaultValues.put(P_CHARSET_IMPORT_FIN, DEF_CHARSET_IMPORT_FIN); + defaultValues.put(P_CHARSET_IMPORT_ELU, DEF_CHARSET_IMPORT_ELU); + // return defaultValues; } @@ -129,4 +151,65 @@ public static boolean isParseMolInformation() { IEclipsePreferences preferences = INSTANCE().getPreferences(); return preferences.getBoolean(P_PARSE_MOL_INFORMATION, DEF_PARSE_MOL_INFORMATION); } -} + + public static Charset getCharsetImportMSL() { + + return getCharset(P_CHARSET_IMPORT_MSL, DEF_CHARSET_IMPORT_MSL); + } + + public static void setCharsetImportMSL(CharsetNIO charsetNIO) { + + setCharset(P_CHARSET_IMPORT_MSL, charsetNIO); + } + + public static Charset getCharsetImportMSP() { + + return getCharset(P_CHARSET_IMPORT_MSP, DEF_CHARSET_IMPORT_MSP); + } + + public static void setCharsetImportMSP(CharsetNIO charsetNIO) { + + setCharset(P_CHARSET_IMPORT_MSP, charsetNIO); + } + + public static Charset getCharsetImportFIN() { + + return getCharset(P_CHARSET_IMPORT_FIN, DEF_CHARSET_IMPORT_FIN); + } + + public static void setCharsetImportFIN(CharsetNIO charsetNIO) { + + setCharset(P_CHARSET_IMPORT_FIN, charsetNIO); + } + + public static Charset getCharsetImportELU() { + + return getCharset(P_CHARSET_IMPORT_ELU, DEF_CHARSET_IMPORT_ELU); + } + + public static void setCharsetImportELU(CharsetNIO charsetNIO) { + + setCharset(P_CHARSET_IMPORT_ELU, charsetNIO); + } + + private static Charset getCharset(String key, String def) { + + IEclipsePreferences preferences = INSTANCE().getPreferences(); + try { + return CharsetNIO.valueOf(preferences.get(key, def)).getCharset(); + } catch(Exception e) { + return CharsetNIO.US_ASCII.getCharset(); + } + } + + private static void setCharset(String key, CharsetNIO charsetNIO) { + + try { + IEclipsePreferences preferences = PreferenceSupplier.INSTANCE().getPreferences(); + preferences.put(key, charsetNIO.name()); + preferences.flush(); + } catch(BackingStoreException e) { + logger.warn(e); + } + } +} \ No newline at end of file diff --git a/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.amdis/src/org/eclipse/chemclipse/msd/converter/supplier/amdis/system/ConverterProcessor.java b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.amdis/src/org/eclipse/chemclipse/msd/converter/supplier/amdis/system/ConverterProcessor.java new file mode 100644 index 0000000000..bfa4ae9c09 --- /dev/null +++ b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.amdis/src/org/eclipse/chemclipse/msd/converter/supplier/amdis/system/ConverterProcessor.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * Copyright (c) 2021 Lablicate GmbH. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Philip Wenig - initial API and implementation + *******************************************************************************/ +package org.eclipse.chemclipse.msd.converter.supplier.amdis.system; + +import java.util.Collection; +import java.util.Collections; + +import org.eclipse.chemclipse.msd.converter.supplier.amdis.preferences.PreferenceSupplier; +import org.eclipse.chemclipse.processing.supplier.IProcessSupplier; +import org.eclipse.chemclipse.processing.supplier.IProcessTypeSupplier; +import org.eclipse.chemclipse.processing.supplier.ProcessExecutionContext; +import org.eclipse.chemclipse.processing.system.AbstractSystemProcessSettings; +import org.eclipse.chemclipse.processing.system.AbstractSystemProcessSupplier; +import org.eclipse.chemclipse.processing.system.ISystemProcessSettings; +import org.osgi.service.component.annotations.Component; + +@Component(service = {IProcessTypeSupplier.class}) +public class ConverterProcessor extends AbstractSystemProcessSettings { + + private static final String ID = "org.eclipse.chemclipse.msd.converter.supplier.amdis.system.converterProcessor"; + private static final String NAME = "AMDIS Converter"; + private static final String DESCRIPTION = "Define the AMDIS converter settings."; + + @Override + public Collection> getProcessorSuppliers() { + + return Collections.singleton(new ProcessSupplier(this)); + } + + private static final class ProcessSupplier extends AbstractSystemProcessSupplier { + + public ProcessSupplier(IProcessTypeSupplier parent) { + + super(ID, NAME, DESCRIPTION, ConverterSettings.class, parent); + } + + @Override + public void executeUserSettings(ISystemProcessSettings settings, ProcessExecutionContext context) throws Exception { + + if(settings instanceof ConverterSettings) { + ConverterSettings processSettings = (ConverterSettings)settings; + PreferenceSupplier.setCharsetImportMSL(processSettings.getCharsetImportMSL()); + PreferenceSupplier.setCharsetImportMSP(processSettings.getCharsetImportMSP()); + PreferenceSupplier.setCharsetImportFIN(processSettings.getCharsetImportFIN()); + PreferenceSupplier.setCharsetImportELU(processSettings.getCharsetImportELU()); + } + } + } +} \ No newline at end of file diff --git a/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.amdis/src/org/eclipse/chemclipse/msd/converter/supplier/amdis/system/ConverterSettings.java b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.amdis/src/org/eclipse/chemclipse/msd/converter/supplier/amdis/system/ConverterSettings.java new file mode 100644 index 0000000000..09fba94c4e --- /dev/null +++ b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.amdis/src/org/eclipse/chemclipse/msd/converter/supplier/amdis/system/ConverterSettings.java @@ -0,0 +1,74 @@ +/******************************************************************************* + * Copyright (c) 2021 Lablicate GmbH. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Philip Wenig - initial API and implementation + *******************************************************************************/ +package org.eclipse.chemclipse.msd.converter.supplier.amdis.system; + +import org.eclipse.chemclipse.processing.system.ISystemProcessSettings; +import org.eclipse.chemclipse.support.text.CharsetNIO; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyDescription; + +public class ConverterSettings implements ISystemProcessSettings { + + @JsonProperty(value = "Charset Import MSL", defaultValue = "US_ASCII") + @JsonPropertyDescription(value = "The following charset is used to import the *.msl files.") + private CharsetNIO charsetImportMSL = CharsetNIO.US_ASCII; + @JsonProperty(value = "Charset Import MSP", defaultValue = "US_ASCII") + @JsonPropertyDescription(value = "The following charset is used to import the *.msp files.") + private CharsetNIO charsetImportMSP = CharsetNIO.US_ASCII; + @JsonProperty(value = "Charset Import FIN", defaultValue = "US_ASCII") + @JsonPropertyDescription(value = "The following charset is used to import the *.fin files.") + private CharsetNIO charsetImportFIN = CharsetNIO.US_ASCII; + @JsonProperty(value = "Charset Import ELU", defaultValue = "US_ASCII") + @JsonPropertyDescription(value = "The following charset is used to import the *.elu files.") + private CharsetNIO charsetImportELU = CharsetNIO.US_ASCII; + + public CharsetNIO getCharsetImportMSL() { + + return charsetImportMSL; + } + + public void setCharsetImportMSL(CharsetNIO charsetImportMSL) { + + this.charsetImportMSL = charsetImportMSL; + } + + public CharsetNIO getCharsetImportMSP() { + + return charsetImportMSP; + } + + public void setCharsetImportMSP(CharsetNIO charsetImportMSP) { + + this.charsetImportMSP = charsetImportMSP; + } + + public CharsetNIO getCharsetImportFIN() { + + return charsetImportFIN; + } + + public void setCharsetImportFIN(CharsetNIO charsetImportFIN) { + + this.charsetImportFIN = charsetImportFIN; + } + + public CharsetNIO getCharsetImportELU() { + + return charsetImportELU; + } + + public void setCharsetImportELU(CharsetNIO charsetImportELU) { + + this.charsetImportELU = charsetImportELU; + } +} \ No newline at end of file diff --git a/chemclipse/plugins/org.eclipse.chemclipse.support/src/org/eclipse/chemclipse/support/text/CharsetNIO.java b/chemclipse/plugins/org.eclipse.chemclipse.support/src/org/eclipse/chemclipse/support/text/CharsetNIO.java new file mode 100644 index 0000000000..674368c1cb --- /dev/null +++ b/chemclipse/plugins/org.eclipse.chemclipse.support/src/org/eclipse/chemclipse/support/text/CharsetNIO.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2021 Labliate GmbH. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Philip Wenig - initial API and implementation + *******************************************************************************/ +package org.eclipse.chemclipse.support.text; + +import java.nio.charset.Charset; + +/** + * See: + * https://docs.oracle.com/javase/8/docs/technotes/guides/intl/encoding.doc.html + * + */ +public enum CharsetNIO implements ILabel { + US_ASCII("US-ASCII", "ASCII (American Standard Code for Information Interchange)"), // + UTF_8("UTF-8", "UTF-8"), // + UTF_16("UTF-16", "UTF-16"), // + UTF_16BE("UTF-16BE", "UTF-16 (Big-Endian)"), // + UTF_16LE("UTF-16LE", "UTF-16 (Little-Endian)"), // + ISO_8859_1("ISO-8859-1", "ISO-8859-1 (Latin Alphabet No. 1)"), /// + ISO_8859_7("ISO-8859-7", "ISO-8859-7 (Latin/Greek Alphabet)"), // + ISO_8859_15("ISO-8859-15", "ISO-8859-15 (Latin Alphabet No. 9)"), // + WINDOWS_1252("windows-1252", "CP1252 (Windows Latin-1)"), // + WINDOWS_1253("windows-1253", "CP1253 (Windows Greek)"); // + + private String canonicalName; + private String description; + + private CharsetNIO(String canonicalName, String description) { + + this.canonicalName = canonicalName; + this.description = description; + } + + @Override + public String label() { + + return description; + } + + public Charset getCharset() { + + return Charset.forName(canonicalName); + } + + public static String[][] getOptions() { + + return ILabel.getOptions(values()); + } +} \ No newline at end of file