diff --git a/chemclipse/plugins/org.eclipse.chemclipse.model/META-INF/MANIFEST.MF b/chemclipse/plugins/org.eclipse.chemclipse.model/META-INF/MANIFEST.MF index 96edbc7bf1..3847eeaa31 100644 --- a/chemclipse/plugins/org.eclipse.chemclipse.model/META-INF/MANIFEST.MF +++ b/chemclipse/plugins/org.eclipse.chemclipse.model/META-INF/MANIFEST.MF @@ -53,7 +53,8 @@ Export-Package: org.eclipse.chemclipse.model.baseline, org.eclipse.chemclipse.model.traces, org.eclipse.chemclipse.model.types, org.eclipse.chemclipse.model.updates, - org.eclipse.chemclipse.model.versioning + org.eclipse.chemclipse.model.versioning, + org.eclipse.chemclipse.model.wavelengths Import-Package: org.osgi.service.component.annotations;version="1.2.0" Service-Component: OSGI-INF/org.eclipse.chemclipse.model.supplier.IMeasurementFilterProcessTypeSupplier.xml, OSGI-INF/org.eclipse.chemclipse.model.supplier.IPeakFilterProcessTypeSupplier.xml diff --git a/chemclipse/plugins/org.eclipse.chemclipse.model/src/org/eclipse/chemclipse/model/wavelengths/NamedWavelength.java b/chemclipse/plugins/org.eclipse.chemclipse.model/src/org/eclipse/chemclipse/model/wavelengths/NamedWavelength.java new file mode 100644 index 0000000000..4dc45e7e9e --- /dev/null +++ b/chemclipse/plugins/org.eclipse.chemclipse.model/src/org/eclipse/chemclipse/model/wavelengths/NamedWavelength.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * Copyright (c) 2020, 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: + * Matthias Mailänder - initial API and implementation + *******************************************************************************/ +package org.eclipse.chemclipse.model.wavelengths; + +public class NamedWavelength { + + private String identifier = ""; + private String wavelength = ""; + + public NamedWavelength(String identifier, String wavelength) { + + this.identifier = identifier; + this.wavelength = wavelength; + } + + public String getIdentifier() { + + return identifier; + } + + public void setIdentifier(String identifier) { + + this.identifier = identifier; + } + + public String getWavelengths() { + + return wavelength; + } + + public void setWavelengths(String wavelength) { + + this.wavelength = wavelength; + } +} diff --git a/chemclipse/plugins/org.eclipse.chemclipse.model/src/org/eclipse/chemclipse/model/wavelengths/NamedWavelengthUtil.java b/chemclipse/plugins/org.eclipse.chemclipse.model/src/org/eclipse/chemclipse/model/wavelengths/NamedWavelengthUtil.java new file mode 100644 index 0000000000..53df391dbd --- /dev/null +++ b/chemclipse/plugins/org.eclipse.chemclipse.model/src/org/eclipse/chemclipse/model/wavelengths/NamedWavelengthUtil.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * 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: + * Matthias Mailänder - initial API and implementation + *******************************************************************************/ +package org.eclipse.chemclipse.model.wavelengths; + +public class NamedWavelengthUtil { + + private static final String TRADITIONAL = "Traditional Wavelengths"; + private static final String MERCURY_LAMP = "Low Pressure Mercury Lamp"; + private static final String ZINC_LAMP = "Zinc Lamp"; + // + + public static final String getDefaultWavelengths() { + + NamedWavelengths namedWavelengths = new NamedWavelengths(); + // + namedWavelengths.add(new NamedWavelength(TRADITIONAL, "214 254 280 365")); + namedWavelengths.add(new NamedWavelength(MERCURY_LAMP, "254")); // 253.7 nm + namedWavelengths.add(new NamedWavelength(ZINC_LAMP, "214")); + // + return namedWavelengths.save(); + } +} diff --git a/chemclipse/plugins/org.eclipse.chemclipse.model/src/org/eclipse/chemclipse/model/wavelengths/NamedWavelengths.java b/chemclipse/plugins/org.eclipse.chemclipse.model/src/org/eclipse/chemclipse/model/wavelengths/NamedWavelengths.java new file mode 100644 index 0000000000..40ae10c4d0 --- /dev/null +++ b/chemclipse/plugins/org.eclipse.chemclipse.model/src/org/eclipse/chemclipse/model/wavelengths/NamedWavelengths.java @@ -0,0 +1,214 @@ +/******************************************************************************* + * Copyright (c) 2020, 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 + * Matthias Mailänder - adapted for DAD + *******************************************************************************/ +package org.eclipse.chemclipse.model.wavelengths; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.eclipse.chemclipse.logging.core.Logger; +import org.eclipse.chemclipse.support.util.NamedWavelengthListUtil; + +public class NamedWavelengths { + + private static final Logger logger = Logger.getLogger(NamedWavelengths.class); + // + private NamedWavelengthListUtil namedWavelengthListUtil = new NamedWavelengthListUtil(); + private final Map namedWavelengthMap = new HashMap<>(); + + public NamedWavelengths() { + + } + + /** + * Initializes this named Wavelengths from the given settings. + * + * @param namedWavelengths + */ + public NamedWavelengths(String namedWavelengths) { + + load(namedWavelengths); + } + + public void addAll(Collection namedWavelengths) { + + for(NamedWavelength namedWavelength : namedWavelengths) { + add(namedWavelength); + } + } + + public void add(NamedWavelength namedWavelength) { + + namedWavelengthMap.put(namedWavelength.getIdentifier(), namedWavelength); + } + + public void remove(String identifier) { + + namedWavelengthMap.remove(identifier); + } + + public void remove(List namedWavelengths) { + + for(NamedWavelength namedWavelength : namedWavelengths) { + remove(namedWavelength); + } + } + + public void remove(NamedWavelength namedWavelength) { + + if(namedWavelength != null) { + namedWavelengthMap.remove(namedWavelength.getIdentifier()); + } + } + + public NamedWavelength get(String identifier) { + + return namedWavelengthMap.get(identifier); + } + + public Set keySet() { + + return namedWavelengthMap.keySet(); + } + + public Collection values() { + + return namedWavelengthMap.values(); + } + + public void clear() { + + namedWavelengthMap.clear(); + } + + public String extractNamedWavelength(NamedWavelength namedWavelength) { + + StringBuilder builder = new StringBuilder(); + extractNamedWavelength(namedWavelength, builder); + return builder.toString(); + } + + public NamedWavelength extractNamedWavelength(String item) { + + NamedWavelength namedWavelength = null; + // + if(!"".equals(item)) { + String[] values = item.split("\\" + NamedWavelengthListUtil.SEPARATOR_ENTRY); + String identifier = ((values.length > 0) ? values[0].trim() : ""); + String Wavelengths = ((values.length > 1) ? values[1].trim() : ""); + namedWavelength = new NamedWavelength(identifier, Wavelengths); + } + // + return namedWavelength; + } + + public void load(String timeRanges) { + + loadSettings(timeRanges); + } + + public void loadDefault(String timeRanges) { + + loadSettings(timeRanges); + } + + public String save() { + + StringBuilder builder = new StringBuilder(); + Iterator iterator = values().iterator(); + while(iterator.hasNext()) { + NamedWavelength namedWavelength = iterator.next(); + extractNamedWavelength(namedWavelength, builder); + if(iterator.hasNext()) { + builder.append(NamedWavelengthListUtil.SEPARATOR_TOKEN); + } + } + return builder.toString().trim(); + } + + public void importItems(File file) { + + try (BufferedReader bufferedReader = new BufferedReader(new FileReader(file))) { + String line; + while((line = bufferedReader.readLine()) != null) { + NamedWavelength template = extractNamedWavelength(line); + if(template != null) { + add(template); + } + } + } catch(FileNotFoundException e) { + logger.warn(e); + } catch(IOException e) { + logger.warn(e); + } + } + + public boolean exportItems(File file) { + + try (PrintWriter printWriter = new PrintWriter(file)) { + /* + * Sort the items. + */ + List namedWavelengths = new ArrayList<>(values()); + Collections.sort(namedWavelengths, (r1, r2) -> r1.getIdentifier().compareTo(r2.getIdentifier())); + // + Iterator iterator = namedWavelengths.iterator(); + while(iterator.hasNext()) { + StringBuilder builder = new StringBuilder(); + NamedWavelength template = iterator.next(); + extractNamedWavelength(template, builder); + printWriter.println(builder.toString()); + } + printWriter.flush(); + return true; + } catch(FileNotFoundException e) { + logger.warn(e); + return false; + } + } + + private void loadSettings(String timeRanges) { + + if(!"".equals(timeRanges)) { + String[] items = namedWavelengthListUtil.parseString(timeRanges); + if(items.length > 0) { + for(String item : items) { + NamedWavelength namedWavelength = extractNamedWavelength(item); + if(namedWavelength != null) { + add(namedWavelength); + } + } + } + } + } + + private void extractNamedWavelength(NamedWavelength namedWavelength, StringBuilder builder) { + + builder.append(namedWavelength.getIdentifier()); + builder.append(" "); + builder.append(NamedWavelengthListUtil.SEPARATOR_ENTRY); + builder.append(" "); + builder.append(namedWavelength.getWavelengths()); + } +} diff --git a/chemclipse/plugins/org.eclipse.chemclipse.support/src/org/eclipse/chemclipse/support/util/NamedWavelengthListUtil.java b/chemclipse/plugins/org.eclipse.chemclipse.support/src/org/eclipse/chemclipse/support/util/NamedWavelengthListUtil.java new file mode 100644 index 0000000000..49c450736e --- /dev/null +++ b/chemclipse/plugins/org.eclipse.chemclipse.support/src/org/eclipse/chemclipse/support/util/NamedWavelengthListUtil.java @@ -0,0 +1,71 @@ +/******************************************************************************* + * Copyright (c) 2020 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.support.util; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class NamedWavelengthListUtil { + + public static final String SEPARATOR_TOKEN = ";"; + public static final String SEPARATOR_ENTRY = "|"; + public static final String SEPARATOR_TRACE = " "; + + public String createList(String[] items) { + + List list = getValues(items); + String values = ""; + for(String value : list) { + values = values.concat(value + SEPARATOR_TOKEN); + } + return values; + } + + public String[] parseString(String stringList) { + + String[] decodedArray; + if(stringList.contains(SEPARATOR_TOKEN)) { + decodedArray = stringList.split(SEPARATOR_TOKEN); + } else { + decodedArray = new String[]{stringList}; + } + return decodedArray; + } + + public List getList(String preferenceEntry) { + + List values = new ArrayList(); + if(preferenceEntry != "") { + String[] items = parseString(preferenceEntry); + if(items.length > 0) { + for(String item : items) { + values.add(item); + } + } + } + Collections.sort(values); + return values; + } + + private List getValues(String[] items) { + + List values = new ArrayList(); + if(items != null) { + int size = items.length; + for(int i = 0; i < size; i++) { + values.add(items[i]); + } + } + return values; + } +} diff --git a/chemclipse/plugins/org.eclipse.chemclipse.support/src/org/eclipse/chemclipse/support/validators/WavelengthValidator.java b/chemclipse/plugins/org.eclipse.chemclipse.support/src/org/eclipse/chemclipse/support/validators/WavelengthValidator.java new file mode 100644 index 0000000000..4eff6ea122 --- /dev/null +++ b/chemclipse/plugins/org.eclipse.chemclipse.support/src/org/eclipse/chemclipse/support/validators/WavelengthValidator.java @@ -0,0 +1,96 @@ +/******************************************************************************* + * Copyright (c) 2020, 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 + * Matthias Mailänder - adapted for DAD + *******************************************************************************/ +package org.eclipse.chemclipse.support.validators; + +import java.text.DecimalFormat; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; +import java.util.TreeSet; + +import org.eclipse.chemclipse.support.text.ValueFormat; +import org.eclipse.chemclipse.support.util.NamedTraceListUtil; +import org.eclipse.chemclipse.support.util.NamedWavelengthListUtil; +import org.eclipse.core.databinding.validation.IValidator; +import org.eclipse.core.databinding.validation.ValidationStatus; +import org.eclipse.core.runtime.IStatus; + +public class WavelengthValidator implements IValidator { + + private static final String ERROR = "Please enter valid wavelength in nm, e.g.: 253.7"; + private static final String ERROR_VALUE = "The wavelength value can't be parsed: "; + // + private DecimalFormat decimalFormat = ValueFormat.getDecimalFormatEnglish("0.#"); + private Set wavelengths = new TreeSet(); + + @Override + public IStatus validate(Object value) { + + wavelengths.clear(); + String message = null; + if(value == null) { + message = ERROR; + } else { + if(value instanceof String) { + String text = (String)value; + String[] values = text.split(NamedWavelengthListUtil.SEPARATOR_TRACE); + exitloop: + for(String val : values) { + try { + wavelengths.add(Double.parseDouble(val)); + } catch(NumberFormatException e) { + message = ERROR_VALUE + val; + break exitloop; + } + } + } else { + message = ERROR; + } + } + // + if(message != null) { + return ValidationStatus.error(message); + } else { + return ValidationStatus.ok(); + } + } + + public List getWavelengthsAsDouble() { + + return new ArrayList(wavelengths); + } + + public List getWavelengthsAsInteger() { + + Set trazes = new HashSet<>(); + for(double wavelength : wavelengths) { + trazes.add(Math.round((float)wavelength)); + } + return new ArrayList<>(trazes); + } + + public String getWavelengthsAsString() { + + StringBuilder builder = new StringBuilder(); + Iterator iterator = wavelengths.iterator(); + while(iterator.hasNext()) { + builder.append(decimalFormat.format(iterator.next())); + if(iterator.hasNext()) { + builder.append(NamedTraceListUtil.SEPARATOR_TRACE); + } + } + return builder.toString(); + } +} diff --git a/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/plugin.xml b/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/plugin.xml index 085a16bc18..1977fe4652 100644 --- a/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/plugin.xml +++ b/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/plugin.xml @@ -215,6 +215,12 @@ id="org.eclipse.chemclipse.ux.extension.xxd.ui.preferences.preferencePageNamedTraces" name="Named Trace(s)"> + + = 2) ? numColumns - 1 : 1; + } +} diff --git a/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/internal/provider/NamedWavelengthEditingSupport.java b/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/internal/provider/NamedWavelengthEditingSupport.java new file mode 100644 index 0000000000..014f700a48 --- /dev/null +++ b/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/internal/provider/NamedWavelengthEditingSupport.java @@ -0,0 +1,80 @@ +/******************************************************************************* + * Copyright (c) 2020, 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 + * Matthias Mailänder - adapted for DAD + *******************************************************************************/ +package org.eclipse.chemclipse.ux.extension.xxd.ui.internal.provider; + +import org.eclipse.chemclipse.model.wavelengths.NamedWavelength; +import org.eclipse.chemclipse.support.ui.swt.ExtendedTableViewer; +import org.eclipse.chemclipse.support.validators.TraceValidator; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.jface.viewers.CellEditor; +import org.eclipse.jface.viewers.EditingSupport; +import org.eclipse.jface.viewers.TextCellEditor; + +public class NamedWavelengthEditingSupport extends EditingSupport { + + private CellEditor cellEditor; + private ExtendedTableViewer tableViewer; + private String column; + // + private TraceValidator traceValidator = new TraceValidator(); + + public NamedWavelengthEditingSupport(ExtendedTableViewer tableViewer, String column) { + + super(tableViewer); + this.column = column; + this.cellEditor = new TextCellEditor(tableViewer.getTable()); + this.tableViewer = tableViewer; + } + + @Override + protected CellEditor getCellEditor(Object element) { + + return cellEditor; + } + + @Override + protected boolean canEdit(Object element) { + + return tableViewer.isEditEnabled(); + } + + @Override + protected Object getValue(Object element) { + + if(element instanceof NamedWavelength) { + NamedWavelength namedWavelength = (NamedWavelength)element; + switch(column) { + case NamedWavelengthsLabelProvider.WAVELENGTHS: + return namedWavelength.getWavelengths(); + } + } + return false; + } + + @Override + protected void setValue(Object element, Object value) { + + if(element instanceof NamedWavelength) { + NamedWavelength namedWavelength = (NamedWavelength)element; + switch(column) { + case NamedWavelengthsLabelProvider.WAVELENGTHS: + IStatus status = traceValidator.validate(value); + if(status.isOK()) { + namedWavelength.setWavelengths(traceValidator.getTracesAsString()); + } + break; + } + tableViewer.refresh(); + } + } +} diff --git a/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/internal/provider/NamedWavelengthsComparator.java b/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/internal/provider/NamedWavelengthsComparator.java new file mode 100644 index 0000000000..b2a3187d2a --- /dev/null +++ b/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/internal/provider/NamedWavelengthsComparator.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (c) 2019, 2020 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 + * Matthias Mailänder - adapted for DAD + *******************************************************************************/ +package org.eclipse.chemclipse.ux.extension.xxd.ui.internal.provider; + +import org.eclipse.chemclipse.model.wavelengths.NamedWavelength; +import org.eclipse.chemclipse.support.ui.swt.AbstractRecordTableComparator; +import org.eclipse.chemclipse.support.ui.swt.IRecordTableComparator; +import org.eclipse.jface.viewers.Viewer; + +public class NamedWavelengthsComparator extends AbstractRecordTableComparator implements IRecordTableComparator { + + @Override + public int compare(Viewer viewer, Object e1, Object e2) { + + int sortOrder = 0; + if(e1 instanceof NamedWavelength && e2 instanceof NamedWavelength) { + // + NamedWavelength namedWavelength1 = (NamedWavelength)e1; + NamedWavelength namedWavelength2 = (NamedWavelength)e2; + // + switch(getPropertyIndex()) { + case 0: + sortOrder = namedWavelength2.getIdentifier().compareTo(namedWavelength1.getIdentifier()); + break; + case 1: + sortOrder = namedWavelength2.getWavelengths().compareTo(namedWavelength1.getWavelengths()); + break; + } + } + if(getDirection() == ASCENDING) { + sortOrder = -sortOrder; + } + return sortOrder; + } +} diff --git a/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/internal/provider/NamedWavelengthsEditingSupport.java b/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/internal/provider/NamedWavelengthsEditingSupport.java new file mode 100644 index 0000000000..3cb9afb16e --- /dev/null +++ b/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/internal/provider/NamedWavelengthsEditingSupport.java @@ -0,0 +1,80 @@ +/******************************************************************************* + * Copyright (c) 2020, 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 + * Matthias Mailänder - adapted for DAD + *******************************************************************************/ +package org.eclipse.chemclipse.ux.extension.xxd.ui.internal.provider; + +import org.eclipse.chemclipse.model.wavelengths.NamedWavelength; +import org.eclipse.chemclipse.support.ui.swt.ExtendedTableViewer; +import org.eclipse.chemclipse.support.validators.WavelengthValidator; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.jface.viewers.CellEditor; +import org.eclipse.jface.viewers.EditingSupport; +import org.eclipse.jface.viewers.TextCellEditor; + +public class NamedWavelengthsEditingSupport extends EditingSupport { + + private CellEditor cellEditor; + private ExtendedTableViewer tableViewer; + private String column; + // + private WavelengthValidator wavelengthValidator = new WavelengthValidator(); + + public NamedWavelengthsEditingSupport(ExtendedTableViewer tableViewer, String column) { + + super(tableViewer); + this.column = column; + this.cellEditor = new TextCellEditor(tableViewer.getTable()); + this.tableViewer = tableViewer; + } + + @Override + protected CellEditor getCellEditor(Object element) { + + return cellEditor; + } + + @Override + protected boolean canEdit(Object element) { + + return tableViewer.isEditEnabled(); + } + + @Override + protected Object getValue(Object element) { + + if(element instanceof NamedWavelength) { + NamedWavelength namedTrace = (NamedWavelength)element; + switch(column) { + case NamedWavelengthsLabelProvider.WAVELENGTHS: + return namedTrace.getWavelengths(); + } + } + return false; + } + + @Override + protected void setValue(Object element, Object value) { + + if(element instanceof NamedWavelength) { + org.eclipse.chemclipse.model.wavelengths.NamedWavelength namedWavelength = (NamedWavelength)element; + switch(column) { + case NamedWavelengthsLabelProvider.WAVELENGTHS: + IStatus status = wavelengthValidator.validate(value); + if(status.isOK()) { + namedWavelength.setWavelengths(wavelengthValidator.getWavelengthsAsString()); + } + break; + } + tableViewer.refresh(); + } + } +} diff --git a/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/internal/provider/NamedWavelengthsFilter.java b/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/internal/provider/NamedWavelengthsFilter.java new file mode 100644 index 0000000000..5c7ee3c2bd --- /dev/null +++ b/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/internal/provider/NamedWavelengthsFilter.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (c) 2020, 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 + * Matthias Mailänder - adapted for DAD + *******************************************************************************/ +package org.eclipse.chemclipse.ux.extension.xxd.ui.internal.provider; + +import org.eclipse.chemclipse.model.wavelengths.NamedWavelength; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerFilter; + +public class NamedWavelengthsFilter extends ViewerFilter { + + private String searchText; + private boolean caseSensitive; + + public void setSearchText(String searchText, boolean caseSensitive) { + + this.searchText = searchText; + this.caseSensitive = caseSensitive; + } + + @Override + public boolean select(Viewer viewer, Object parentElement, Object element) { + + /* + * Pre-Condition + */ + if(searchText == null || searchText.equals("")) { + return true; + } + // + if(element instanceof NamedWavelength) { + NamedWavelength namedWavelength = (NamedWavelength)element; + String identifier = namedWavelength.getIdentifier(); + String wavelengths = namedWavelength.getWavelengths(); + // + if(!caseSensitive) { + searchText = searchText.toLowerCase(); + identifier = identifier.toLowerCase(); + wavelengths = wavelengths.toLowerCase(); + } + // + if(identifier.contains(searchText)) { + return true; + } + // + if(wavelengths.contains(searchText)) { + return true; + } + } + // + return false; + } +} diff --git a/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/internal/provider/NamedWavelengthsLabelProvider.java b/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/internal/provider/NamedWavelengthsLabelProvider.java new file mode 100644 index 0000000000..b95c2675fd --- /dev/null +++ b/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/internal/provider/NamedWavelengthsLabelProvider.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * Copyright (c) 2019, 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 + * Matthias Mailänder - adapted for DAD + *******************************************************************************/ +package org.eclipse.chemclipse.ux.extension.xxd.ui.internal.provider; + +import org.eclipse.chemclipse.model.wavelengths.NamedWavelength; +import org.eclipse.chemclipse.support.ui.provider.AbstractChemClipseLabelProvider; +import org.eclipse.swt.graphics.Image; + +public class NamedWavelengthsLabelProvider extends AbstractChemClipseLabelProvider { + + public static final String IDENTIFIER = "Identifier"; + public static final String WAVELENGTHS = "Wavelengths"; + // + public static final String[] TITLES = { // + IDENTIFIER, // + WAVELENGTHS // + }; + public static final int[] BOUNDS = { // + 300, // + 250 // + }; + + @Override + public Image getColumnImage(Object element, int columnIndex) { + + if(columnIndex == 0) { + return getImage(element); + } + return null; + } + + @Override + public String getColumnText(Object element, int columnIndex) { + + String text = ""; + if(element instanceof NamedWavelength) { + NamedWavelength namedWavelength = (NamedWavelength)element; + switch(columnIndex) { + case 0: + text = namedWavelength.getIdentifier(); + break; + case 1: + text = namedWavelength.getWavelengths(); + break; + } + } + return text; + } +} diff --git a/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/internal/support/OverlayChartSupport.java b/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/internal/support/OverlayChartSupport.java index 3059a764f2..40647f6bf4 100644 --- a/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/internal/support/OverlayChartSupport.java +++ b/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/internal/support/OverlayChartSupport.java @@ -25,6 +25,7 @@ public class OverlayChartSupport { private String[] overlayTypes; public OverlayChartSupport() { + initialize(); } @@ -42,6 +43,7 @@ private void initialize() { DisplayType.toShortcut(DisplayType.SIC), // DisplayType.toShortcut(DisplayType.XWC), // DisplayType.toShortcut(DisplayType.SWC), // + DisplayType.toShortcut(DisplayType.MPC), // DisplayType.toShortcut(DisplayType.TSC), // DisplayType.toShortcut(DisplayType.TIC, DisplayType.BPC), // DisplayType.toShortcut(DisplayType.TIC, DisplayType.XIC), // diff --git a/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/internal/validation/NamedWavelengthInputValidator.java b/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/internal/validation/NamedWavelengthInputValidator.java new file mode 100644 index 0000000000..c6b89e6f67 --- /dev/null +++ b/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/internal/validation/NamedWavelengthInputValidator.java @@ -0,0 +1,48 @@ +/******************************************************************************* + * Copyright (c) 2020, 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 + * Matthias Mailänder - adapted for DAD + *******************************************************************************/ +package org.eclipse.chemclipse.ux.extension.xxd.ui.internal.validation; + +import java.util.HashSet; +import java.util.Set; + +import org.eclipse.chemclipse.ux.extension.xxd.ui.wavelengths.NamedWavelengthValidator; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.jface.dialogs.IInputValidator; + +public class NamedWavelengthInputValidator implements IInputValidator { + + private NamedWavelengthValidator validator = new NamedWavelengthValidator(); + private Set identifier = new HashSet<>(); + + public NamedWavelengthInputValidator(Set identifier) { + + if(identifier != null) { + this.identifier = identifier; + } + } + + @Override + public String isValid(String target) { + + IStatus status = validator.validate(target); + if(status.isOK()) { + String name = validator.getIdentifier(); + if(identifier.contains(name)) { + return "The named wavelength already exists."; + } + } else { + return status.getMessage(); + } + return null; + } +} diff --git a/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/preferences/PreferenceConstants.java b/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/preferences/PreferenceConstants.java index d296a2975e..c50929f6df 100644 --- a/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/preferences/PreferenceConstants.java +++ b/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/preferences/PreferenceConstants.java @@ -14,6 +14,7 @@ import org.eclipse.chemclipse.model.core.support.HeaderField; import org.eclipse.chemclipse.model.traces.NamedTraceUtil; +import org.eclipse.chemclipse.model.wavelengths.NamedWavelengthUtil; import org.eclipse.chemclipse.msd.model.support.CalculationType; import org.eclipse.chemclipse.pcr.model.core.support.LabelSetting; import org.eclipse.chemclipse.swt.ui.support.Colors; @@ -165,6 +166,8 @@ public class PreferenceConstants extends ChartOptions { public static final int DEF_PEAK_TRACES_OFFSET_RETENTION_TIME = DEF_OFFSET_RETENTION_TIME; public static final String P_CHROMATOGRAM_OVERLAY_NAMED_TRACES = "chromatogramOverlayNamedTraces"; public static final String DEF_CHROMATOGRAM_OVERLAY_NAMED_TRACES = NamedTraceUtil.getDefaultTraces(); + public static final String P_CHROMATOGRAM_OVERLAY_NAMED_WAVELENGTHS = "chromatogramOverlayNamedWavelengths"; + public static final String DEF_CHROMATOGRAM_OVERLAY_NAMED_WAVELENGTHS = NamedWavelengthUtil.getDefaultWavelengths(); // public static final String P_OVERLAY_SHIFT_X = "overlayShiftX"; public static final double DEF_OVERLAY_SHIFT_X = 0.0d; @@ -397,6 +400,11 @@ public class PreferenceConstants extends ChartOptions { */ public static final String P_NAMED_TRACES_TEMPLATE_FOLDER = "namedTracesTemplateFolder"; public static final String DEF_NAMED_TRACES_TEMPLATE_FOLDER = ""; + /* + * Named Wavelengths + */ + public static final String P_NAMED_WAVELENGTHS_TEMPLATE_FOLDER = "namedWavelengthsTemplateFolder"; + public static final String DEF_NAMED_WAVELENGTHS_TEMPLATE_FOLDER = ""; /* * Target Templates */ diff --git a/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/preferences/PreferenceInitializer.java b/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/preferences/PreferenceInitializer.java index 3f3400305c..dce62bb783 100644 --- a/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/preferences/PreferenceInitializer.java +++ b/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/preferences/PreferenceInitializer.java @@ -432,6 +432,7 @@ public static IPreferenceStore initializeOverlayDefaults(IPreferenceStore store) store.setDefault(PreferenceConstants.P_LINE_STYLE_DISPLAY_OVERLAY, PreferenceConstants.DEF_LINE_STYLE_DISPLAY_OVERLAY); // store.setDefault(PreferenceConstants.P_CHROMATOGRAM_OVERLAY_NAMED_TRACES, PreferenceConstants.DEF_CHROMATOGRAM_OVERLAY_NAMED_TRACES); + store.setDefault(PreferenceConstants.P_CHROMATOGRAM_OVERLAY_NAMED_WAVELENGTHS, PreferenceConstants.DEF_CHROMATOGRAM_OVERLAY_NAMED_WAVELENGTHS); // store.setDefault(PreferenceConstants.P_OVERLAY_SHIFT_X, PreferenceConstants.DEF_OVERLAY_SHIFT_X); store.setDefault(PreferenceConstants.P_INDEX_SHIFT_X, PreferenceConstants.DEF_INDEX_SHIFT_X); diff --git a/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/preferences/PreferencePageNamedWavelengths.java b/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/preferences/PreferencePageNamedWavelengths.java new file mode 100644 index 0000000000..0a590d0a15 --- /dev/null +++ b/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/preferences/PreferencePageNamedWavelengths.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * Copyright (c) 2020, 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: + * Dr. Philip Wenig - initial API and implementation + * Matthias Mailänder - adapted for DAD + *******************************************************************************/ +package org.eclipse.chemclipse.ux.extension.xxd.ui.preferences; + +import org.eclipse.chemclipse.ux.extension.xxd.ui.Activator; +import org.eclipse.chemclipse.ux.extension.xxd.ui.fieldeditors.NamedWavelengthsFieldEditor; +import org.eclipse.jface.preference.FieldEditorPreferencePage; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPreferencePage; + +public class PreferencePageNamedWavelengths extends FieldEditorPreferencePage implements IWorkbenchPreferencePage { + + public PreferencePageNamedWavelengths() { + + super(GRID); + setPreferenceStore(Activator.getDefault().getPreferenceStore()); + setTitle("Named Wavelength(s)"); + setDescription(""); + } + + @Override + public void createFieldEditors() { + + addField(new NamedWavelengthsFieldEditor(PreferenceConstants.P_CHROMATOGRAM_OVERLAY_NAMED_WAVELENGTHS, "Named Wavelengths", getFieldEditorParent())); + } + + @Override + public void init(IWorkbench workbench) { + + } +} diff --git a/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/support/DisplayType.java b/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/support/DisplayType.java index 6cf72b1ada..80eb89cffe 100644 --- a/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/support/DisplayType.java +++ b/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/support/DisplayType.java @@ -25,6 +25,7 @@ public enum DisplayType { SIC("SIC", "Selected Ion Chromatogram"), // XWC("XWC", "Extracted Wavelength Chromatogram"), // SWC("SWC", "Selected Wavelength Chromatogram"), // + MPC("MPC", "Max Plot Chromatogram"), // TSC("TSC", "Total Subtracted Chromatogram"), // SRM("SRM", "Single Reaction Monitoring"), // MRM("MRM", "Multiple Reaction Monitoring"); @@ -40,6 +41,7 @@ public enum DisplayType { private String description; private DisplayType(String shortcut, String description) { + this.shortucut = shortcut; this.description = description; } diff --git a/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/support/charts/ChromatogramChartSupport.java b/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/support/charts/ChromatogramChartSupport.java index da429f851e..06401fe3cb 100644 --- a/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/support/charts/ChromatogramChartSupport.java +++ b/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/support/charts/ChromatogramChartSupport.java @@ -18,6 +18,7 @@ import java.util.HashSet; import java.util.Iterator; import java.util.Map; +import java.util.Optional; import java.util.Set; import org.eclipse.chemclipse.csd.model.core.selection.IChromatogramSelectionCSD; @@ -43,6 +44,7 @@ import org.eclipse.chemclipse.ux.extension.xxd.ui.preferences.PreferenceConstants; import org.eclipse.chemclipse.ux.extension.xxd.ui.support.DisplayType; import org.eclipse.chemclipse.wsd.model.core.IChromatogramWSD; +import org.eclipse.chemclipse.wsd.model.core.IScanSignalWSD; import org.eclipse.chemclipse.wsd.model.core.IScanWSD; import org.eclipse.chemclipse.wsd.model.core.selection.IChromatogramSelectionWSD; import org.eclipse.chemclipse.wsd.model.core.support.IMarkedWavelengths; @@ -413,6 +415,10 @@ public ILineSeriesData getLineSeriesData(IChromatogramSelection chromatogr /* * TIC */ + } else if(dataType.equals(DisplayType.MPC)) { + /* + * Max Plot + */ } else { throw new IllegalArgumentException("Type " + dataType + " is not supported"); } @@ -523,6 +529,25 @@ private double getIntensity(IScan scan, DisplayType dataType, IMarkedSignals scanSignal = scanWSD.getScanSignal(wavelength); + if(scanSignal.isPresent()) { + float abundance = scanSignal.get().getAbundance(); + if(abundance > maxIntensity) { + maxIntensity = abundance; + } + } + } + intensity = maxIntensity; + } } // return intensity; diff --git a/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/swt/ExtendedChromatogramOverlayUI.java b/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/swt/ExtendedChromatogramOverlayUI.java index 8666db9720..0cf482759f 100644 --- a/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/swt/ExtendedChromatogramOverlayUI.java +++ b/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/swt/ExtendedChromatogramOverlayUI.java @@ -28,6 +28,8 @@ import org.eclipse.chemclipse.model.traces.NamedTrace; import org.eclipse.chemclipse.model.traces.NamedTraces; import org.eclipse.chemclipse.model.updates.IUpdateListener; +import org.eclipse.chemclipse.model.wavelengths.NamedWavelength; +import org.eclipse.chemclipse.model.wavelengths.NamedWavelengths; import org.eclipse.chemclipse.msd.model.core.IChromatogramMSD; import org.eclipse.chemclipse.msd.model.core.support.IMarkedIons; import org.eclipse.chemclipse.msd.model.core.support.MarkedIons; @@ -35,6 +37,7 @@ import org.eclipse.chemclipse.rcp.ui.icons.core.IApplicationImage; import org.eclipse.chemclipse.support.ui.provider.AbstractLabelProvider; import org.eclipse.chemclipse.support.validators.TraceValidator; +import org.eclipse.chemclipse.support.validators.WavelengthValidator; import org.eclipse.chemclipse.swt.ui.support.Colors; import org.eclipse.chemclipse.ux.extension.ui.support.PartSupport; import org.eclipse.chemclipse.ux.extension.xxd.ui.Activator; @@ -46,12 +49,14 @@ import org.eclipse.chemclipse.ux.extension.xxd.ui.preferences.PreferenceConstants; import org.eclipse.chemclipse.ux.extension.xxd.ui.preferences.PreferencePageChromatogram; import org.eclipse.chemclipse.ux.extension.xxd.ui.preferences.PreferencePageNamedTraces; +import org.eclipse.chemclipse.ux.extension.xxd.ui.preferences.PreferencePageNamedWavelengths; import org.eclipse.chemclipse.ux.extension.xxd.ui.preferences.PreferencePageOverlay; import org.eclipse.chemclipse.ux.extension.xxd.ui.support.DisplayType; import org.eclipse.chemclipse.ux.extension.xxd.ui.support.charts.ChromatogramChartSupport; import org.eclipse.chemclipse.ux.extension.xxd.ui.support.charts.ChromatogramDataSupport; import org.eclipse.chemclipse.ux.extension.xxd.ui.support.charts.Derivative; import org.eclipse.chemclipse.ux.extension.xxd.ui.traces.NamedTracesUI; +import org.eclipse.chemclipse.ux.extension.xxd.ui.wavelengths.NamedWavelengthsUI; import org.eclipse.chemclipse.wsd.model.core.IChromatogramWSD; import org.eclipse.chemclipse.wsd.model.core.support.IMarkedWavelengths; import org.eclipse.chemclipse.wsd.model.core.support.MarkedWavelengths; @@ -98,6 +103,7 @@ public class ExtendedChromatogramOverlayUI extends Composite implements IExtende // The traces toolbar is controlled by the combo overlay type. // private AtomicReference toolbarNamedTraces = new AtomicReference<>(); + private AtomicReference toolbarNamedWavelengths = new AtomicReference<>(); private Button buttonToolbarDataShift; private AtomicReference toolbarDataShift = new AtomicReference<>(); private Button buttonToolbarRulerDetails; @@ -141,6 +147,7 @@ private void createControl() { // createToolbarMain(this); createNamedTraces(this); + createNamedWavelengths(this); createDataShiftControllerUI(this); createRulerDetailsUI(this); createOverlayChart(this); @@ -151,6 +158,7 @@ private void createControl() { private void initialize() { enableToolbar(toolbarNamedTraces, false); + enableToolbar(toolbarNamedWavelengths, false); enableToolbar(toolbarDataShift, buttonToolbarDataShift, IMAGE_SHIFT, TOOLTIP_SHIFT, false); enableToolbar(toolbarRulerDetails, buttonToolbarRulerDetails, IMAGE_RULER, TOOLTIP_RULER, false); enableChartGrid(chartControl, buttonChartGrid, IMAGE_CHART_GRID, chartGridSupport); @@ -207,6 +215,28 @@ public void update() { toolbarNamedTraces.set(namedTracesUI); } + private void createNamedWavelengths(Composite parent) { + + NamedWavelengthsUI namedWavelengthsUI = new NamedWavelengthsUI(parent, SWT.NONE); + namedWavelengthsUI.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + namedWavelengthsUI.setInput(new NamedWavelengths(preferenceStore.getString(PreferenceConstants.P_CHROMATOGRAM_OVERLAY_NAMED_WAVELENGTHS))); + namedWavelengthsUI.setUpdateListener(new IUpdateListener() { + + @Override + public void update() { + + NamedWavelengths namedWavelengths = namedWavelengthsUI.getNamedWavelengths(); + if(namedWavelengths != null) { + preferenceStore.putValue(PreferenceConstants.DEF_CHROMATOGRAM_OVERLAY_NAMED_WAVELENGTHS, namedWavelengths.save()); + chartControl.get().deleteSeries(); + refreshUpdateOverlayChart(); + } + } + }); + // + toolbarNamedWavelengths.set(namedWavelengthsUI); + } + private void createDataShiftControllerUI(Composite parent) { DataShiftControllerUI dataShiftControllerUI = new DataShiftControllerUI(parent, SWT.NONE); @@ -362,6 +392,7 @@ private void createSettingsButton(Composite parent) { createSettingsButton(parent, Arrays.asList( // PreferencePageOverlay.class, // PreferencePageNamedTraces.class, // + PreferencePageNamedWavelengths.class, // PreferencePageChromatogram.class, // PreferencePage.class // ), new ISettingsHandler() { @@ -393,21 +424,30 @@ private void modifyWidgetStatus() { Set types = getDisplayType(); comboOverlayType.setToolTipText(DisplayType.toDescription(types)); if(preferenceStore.getBoolean(PreferenceConstants.P_OVERLAY_AUTOFOCUS_PROFILE_SETTINGS)) { - if(isExtractedIonsModusEnabled() || isExtractedWavelengthsModusEnabled()) { + if(isExtractedIonsModusEnabled()) { enableToolbar(toolbarNamedTraces, true); } else { enableToolbar(toolbarNamedTraces, false); } + if(isExtractedWavelengthsModusEnabled()) { + enableToolbar(toolbarNamedWavelengths, true); + } else { + enableToolbar(toolbarNamedWavelengths, false); + } } // NamedTracesUI namedTracesUI = toolbarNamedTraces.get(); if(isExtractedIonsModusEnabled()) { namedTracesUI.setEnabled(true); - } else if(isExtractedWavelengthsModusEnabled()) { - namedTracesUI.setEnabled(true); } else { namedTracesUI.setEnabled(false); } + NamedWavelengthsUI namedWavelengthsUI = toolbarNamedWavelengths.get(); + if(isExtractedWavelengthsModusEnabled()) { + namedWavelengthsUI.setEnabled(true); + } else { + namedWavelengthsUI.setEnabled(false); + } // toolbarDataShift.get().update(); } @@ -424,6 +464,7 @@ private void setDerivatives() { private void applySettings() { updateNamedTraces(); + updateNamedWavelengths(); chromatogramChartSupport.loadUserSettings(); chartControl.get().deleteSeries(); refreshUpdateOverlayChart(); @@ -436,6 +477,11 @@ private void updateNamedTraces() { toolbarNamedTraces.get().setInput(new NamedTraces(preferenceStore.getString(PreferenceConstants.P_CHROMATOGRAM_OVERLAY_NAMED_TRACES))); } + private void updateNamedWavelengths() { + + toolbarNamedWavelengths.get().setInput(new NamedWavelengths(preferenceStore.getString(PreferenceConstants.P_CHROMATOGRAM_OVERLAY_NAMED_WAVELENGTHS))); + } + private void createOverlayChart(Composite parent) { ChromatogramRulerChart chromatogramRulerChart = new ChromatogramRulerChart(parent, SWT.BORDER); @@ -618,7 +664,7 @@ private void appendSWC(Set availableSeriesIds, List selectionSer /* * SWC */ - List wavelengths = getSelectedTraces(false); + List wavelengths = getSelectedWavelengths(false); if(chromatogram instanceof IChromatogramWSD) { String description = ChromatogramDataSupport.getReferenceLabel(chromatogram, 0, false); for(Number number : wavelengths) { @@ -851,6 +897,25 @@ private List getSelectedTraces(boolean isNominal) { return traceList; } + private List getSelectedWavelengths(boolean rounded) { + + List wavelengthsList = new ArrayList<>(); + NamedWavelength namedWavelength = toolbarNamedWavelengths.get().getNamedWavelength(); + if(namedWavelength != null) { + WavelengthValidator wavelengthValidator = new WavelengthValidator(); + IStatus status = wavelengthValidator.validate(namedWavelength.getWavelengths()); + if(status.isOK()) { + if(rounded) { + wavelengthsList.addAll(wavelengthValidator.getWavelengthsAsInteger()); + } else { + wavelengthsList.addAll(wavelengthValidator.getWavelengthsAsDouble()); + } + } + } + // + return wavelengthsList; + } + private Set getDisplayType() { return DisplayType.toDisplayTypes(comboOverlayType.getText().trim()); diff --git a/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/wavelengths/NamedWavelengthValidator.java b/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/wavelengths/NamedWavelengthValidator.java new file mode 100644 index 0000000000..810141ced9 --- /dev/null +++ b/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/wavelengths/NamedWavelengthValidator.java @@ -0,0 +1,74 @@ +/******************************************************************************* + * Copyright (c) 2020, 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.ux.extension.xxd.ui.wavelengths; + +import org.eclipse.chemclipse.support.util.NamedTraceListUtil; +import org.eclipse.chemclipse.support.validators.WavelengthValidator; +import org.eclipse.core.databinding.validation.IValidator; +import org.eclipse.core.databinding.validation.ValidationStatus; +import org.eclipse.core.runtime.IStatus; + +public class NamedWavelengthValidator implements IValidator { + + private static final String ERROR = "Please enter a correct identifier."; + // + private WavelengthValidator wavelengthValidator = new WavelengthValidator(); + // + private String identifier = ""; + private String traces = ""; + + @Override + public IStatus validate(Object value) { + + String message = null; + // + if(value == null) { + message = ERROR; + } else { + if(value instanceof String) { + String[] values = value.toString().trim().split("\\" + NamedTraceListUtil.SEPARATOR_ENTRY); + String identifier = values.length > 0 ? values[0].trim() : ""; + String wavelengths = values.length > 1 ? values[1].trim() : ""; + // + if("".equals(identifier)) { + message = ERROR; + } else { + this.identifier = identifier; + IStatus status = wavelengthValidator.validate(wavelengths); + if(status.isOK()) { + this.traces = wavelengths; + } else { + message = status.getMessage(); + } + } + } else { + message = ERROR; + } + } + // + if(message != null) { + return ValidationStatus.error(message); + } else { + return ValidationStatus.ok(); + } + } + + public String getIdentifier() { + + return identifier; + } + + public String getTraces() { + + return traces; + } +} diff --git a/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/wavelengths/NamedWavelengthsEditor.java b/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/wavelengths/NamedWavelengthsEditor.java new file mode 100644 index 0000000000..a7aa46cc2e --- /dev/null +++ b/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/wavelengths/NamedWavelengthsEditor.java @@ -0,0 +1,203 @@ +/******************************************************************************* + * Copyright (c) 2020, 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.ux.extension.xxd.ui.wavelengths; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.eclipse.chemclipse.model.updates.IUpdateListener; +import org.eclipse.chemclipse.model.wavelengths.NamedWavelength; +import org.eclipse.chemclipse.model.wavelengths.NamedWavelengths; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.KeyAdapter; +import org.eclipse.swt.events.KeyEvent; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.MessageBox; +import org.eclipse.swt.widgets.Table; + +public class NamedWavelengthsEditor extends Composite { + + private NamedWavelengthsUI namedWavelengthsUI; + private NamedWavelengthsListUI namedWavelengthsListUI; + // + private NamedWavelengths namedWavelengths; + // + private IUpdateListener updateListener = null; + + public NamedWavelengthsEditor(Composite parent, int style) { + + super(parent, style); + createControl(); + } + + public void setInput(NamedWavelengths namedWavelengths) { + + this.namedWavelengths = namedWavelengths; + updateNamedWavelengthsUI(); + updateNamedWavelengthsTable(); + fireUpdate(); + } + + public void setUpdateListener(IUpdateListener updateListener) { + + this.updateListener = updateListener; + } + + public NamedWavelength getNamedWavelength() { + + return namedWavelengthsUI.getNamedWavelength(); + } + + private void createControl() { + + GridLayout gridLayout = new GridLayout(1, true); + gridLayout.marginWidth = 0; + gridLayout.marginLeft = 0; + gridLayout.marginRight = 0; + setLayout(gridLayout); + // + namedWavelengthsUI = createNamedWavelengthsUI(this); + namedWavelengthsListUI = createNamedWavelengthsListUI(this); + } + + private NamedWavelengthsUI createNamedWavelengthsUI(Composite parent) { + + NamedWavelengthsUI namedWavelengthsUI = new NamedWavelengthsUI(parent, SWT.NONE); + namedWavelengthsUI.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + namedWavelengthsUI.setUpdateListener(new IUpdateListener() { + + @Override + public void update() { + + updateNamedWavelengthsTable(); + fireUpdate(); + } + }); + return namedWavelengthsUI; + } + + private NamedWavelengthsListUI createNamedWavelengthsListUI(Composite parent) { + + NamedWavelengthsListUI namedWavelengthsListUI = new NamedWavelengthsListUI(parent, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION); + Table table = namedWavelengthsListUI.getTable(); + table.setLayoutData(new GridData(GridData.FILL_BOTH)); + namedWavelengthsListUI.setEditEnabled(false); + namedWavelengthsListUI.setSortEnabled(true); + /* + * Selection + */ + table.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(SelectionEvent e) { + + Object object = namedWavelengthsListUI.getStructuredSelection().getFirstElement(); + if(object instanceof NamedWavelength) { + NamedWavelength NamedWavelength = (NamedWavelength)object; + String[] items = namedWavelengthsUI.getItems(); + exitloop: + for(int i = 0; i < items.length; i++) { + if(items[i].equals(NamedWavelength.getIdentifier())) { + namedWavelengthsUI.select(i); + break exitloop; + } + } + } + } + }); + /* + * Delete item(s) + */ + table.addKeyListener(new KeyAdapter() { + + @Override + public void keyReleased(KeyEvent e) { + + if(namedWavelengths != null) { + if(e.keyCode == SWT.DEL) { + MessageBox messageBox = new MessageBox(e.display.getActiveShell(), SWT.ICON_QUESTION | SWT.YES | SWT.NO); + messageBox.setText("Delete trace compound(s)"); + messageBox.setMessage("Would you like to delete the selected trace compound(s)?"); + if(messageBox.open() == SWT.YES) { + /* + * Collect + */ + List deleteItems = new ArrayList<>(); + for(Object object : namedWavelengthsListUI.getStructuredSelection().toList()) { + if(object instanceof NamedWavelength) { + NamedWavelength NamedWavelength = (NamedWavelength)object; + deleteItems.add(NamedWavelength); + } + } + /* + * Delete + */ + delete(deleteItems); + /* + * Update + */ + updateNamedWavelengthsUI(); + updateNamedWavelengthsTable(); + fireUpdate(); + } + } + } + } + }); + // + return namedWavelengthsListUI; + } + + private void delete(List deleteItems) { + + if(namedWavelengths != null) { + for(NamedWavelength deleteItem : deleteItems) { + namedWavelengths.remove(deleteItem.getIdentifier()); + } + } + } + + private void updateNamedWavelengthsUI() { + + namedWavelengthsUI.setInput(namedWavelengths); + } + + private void updateNamedWavelengthsTable() { + + if(namedWavelengths != null) { + List list = new ArrayList<>(namedWavelengths.values()); + Collections.sort(list, (t1, t2) -> t1.getIdentifier().compareTo(t2.getIdentifier())); + namedWavelengthsListUI.setInput(list); + } else { + namedWavelengthsListUI.setInput(null); + } + } + + private void fireUpdate() { + + if(updateListener != null) { + getDisplay().asyncExec(new Runnable() { + + @Override + public void run() { + + updateListener.update(); + } + }); + } + } +} diff --git a/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/wavelengths/NamedWavelengthsListUI.java b/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/wavelengths/NamedWavelengthsListUI.java new file mode 100644 index 0000000000..1aa7bd8057 --- /dev/null +++ b/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/wavelengths/NamedWavelengthsListUI.java @@ -0,0 +1,81 @@ +/******************************************************************************* + * Copyright (c) 2020, 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 + * Matthias Mailänder - adapted for DAD + *******************************************************************************/ +package org.eclipse.chemclipse.ux.extension.xxd.ui.wavelengths; + +import java.util.List; + +import org.eclipse.chemclipse.support.ui.provider.ListContentProvider; +import org.eclipse.chemclipse.support.ui.swt.ExtendedTableViewer; +import org.eclipse.chemclipse.ux.extension.xxd.ui.internal.provider.NamedWavelengthsComparator; +import org.eclipse.chemclipse.ux.extension.xxd.ui.internal.provider.NamedWavelengthsEditingSupport; +import org.eclipse.chemclipse.ux.extension.xxd.ui.internal.provider.NamedWavelengthsFilter; +import org.eclipse.chemclipse.ux.extension.xxd.ui.internal.provider.NamedWavelengthsLabelProvider; +import org.eclipse.jface.viewers.ITableLabelProvider; +import org.eclipse.jface.viewers.TableViewerColumn; +import org.eclipse.jface.viewers.ViewerComparator; +import org.eclipse.jface.viewers.ViewerFilter; +import org.eclipse.swt.widgets.Composite; + +public class NamedWavelengthsListUI extends ExtendedTableViewer { + + private static final String[] TITLES = NamedWavelengthsLabelProvider.TITLES; + private static final int[] BOUNDS = NamedWavelengthsLabelProvider.BOUNDS; + // + private ITableLabelProvider labelProvider = new NamedWavelengthsLabelProvider(); + private ViewerComparator tableComparator = new NamedWavelengthsComparator(); + private NamedWavelengthsFilter listFilter = new NamedWavelengthsFilter(); + + public NamedWavelengthsListUI(Composite parent, int style) { + + super(parent, style); + createColumns(); + } + + public void setSearchText(String searchText, boolean caseSensitive) { + + listFilter.setSearchText(searchText, caseSensitive); + refresh(); + } + + public void setSortEnabled(boolean sortEnabled) { + + setComparator((sortEnabled) ? tableComparator : null); + } + + public void clear() { + + setInput(null); + } + + private void createColumns() { + + createColumns(TITLES, BOUNDS); + setLabelProvider(labelProvider); + setContentProvider(new ListContentProvider()); + setComparator(tableComparator); + setFilters(new ViewerFilter[]{listFilter}); + setEditingSupport(); + } + + private void setEditingSupport() { + + List tableViewerColumns = getTableViewerColumns(); + for(int i = 0; i < tableViewerColumns.size(); i++) { + TableViewerColumn tableViewerColumn = tableViewerColumns.get(i); + String label = tableViewerColumn.getColumn().getText(); + if(!label.equals(NamedWavelengthsLabelProvider.IDENTIFIER)) { + tableViewerColumn.setEditingSupport(new NamedWavelengthsEditingSupport(this, label)); + } + } + } +} diff --git a/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/wavelengths/NamedWavelengthsSettingsEditor.java b/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/wavelengths/NamedWavelengthsSettingsEditor.java new file mode 100644 index 0000000000..db9895cef1 --- /dev/null +++ b/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/wavelengths/NamedWavelengthsSettingsEditor.java @@ -0,0 +1,471 @@ +/******************************************************************************* + * Copyright (c) 2020, 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 + * Matthias Mailänder - adapted for DAD + *******************************************************************************/ +package org.eclipse.chemclipse.ux.extension.xxd.ui.wavelengths; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.concurrent.atomic.AtomicReference; + +import org.eclipse.chemclipse.model.wavelengths.NamedWavelength; +import org.eclipse.chemclipse.model.wavelengths.NamedWavelengths; +import org.eclipse.chemclipse.processing.supplier.ProcessorPreferences; +import org.eclipse.chemclipse.rcp.ui.icons.core.ApplicationImageFactory; +import org.eclipse.chemclipse.rcp.ui.icons.core.IApplicationImage; +import org.eclipse.chemclipse.support.ui.events.IKeyEventProcessor; +import org.eclipse.chemclipse.support.ui.menu.ITableMenuEntry; +import org.eclipse.chemclipse.support.ui.swt.ExtendedTableViewer; +import org.eclipse.chemclipse.support.ui.swt.ITableSettings; +import org.eclipse.chemclipse.swt.ui.components.ISearchListener; +import org.eclipse.chemclipse.swt.ui.components.SearchSupportUI; +import org.eclipse.chemclipse.ux.extension.xxd.ui.Activator; +import org.eclipse.chemclipse.ux.extension.xxd.ui.internal.validation.NamedWavelengthInputValidator; +import org.eclipse.chemclipse.ux.extension.xxd.ui.methods.SettingsUIProvider; +import org.eclipse.chemclipse.ux.extension.xxd.ui.preferences.PreferenceConstants; +import org.eclipse.chemclipse.ux.extension.xxd.ui.swt.IExtendedPartUI; +import org.eclipse.core.databinding.validation.ValidationStatus; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.dialogs.InputDialog; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.KeyEvent; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Table; + +public class NamedWavelengthsSettingsEditor implements SettingsUIProvider.SettingsUIControl, IExtendedPartUI { + + private static final String FILTER_EXTENSION = "*.txt"; + private static final String FILTER_NAME = "Named Wavelengths (*.txt)"; + private static final String FILE_NAME = "NamedWavelengths.txt"; + // + private static final String DIALOG_TITLE = "Named Wavelength(s)"; + private static final String MESSAGE_REMOVE = "Do you want to delete the selected named wavelength(s)?"; + private static final String CATEGORY = "Named Wavelengths"; + private static final String DELETE = "Delete"; + // + private Composite control; + // + private Button buttonToolbarSearch; + private AtomicReference toolbarSearch = new AtomicReference<>(); + // + private NamedWavelengths settings = new NamedWavelengths(); + private NamedWavelengthsListUI listUI; + // + private List listeners = new ArrayList<>(); + private List