diff --git a/chemclipse/plugins/org.eclipse.chemclipse.xxd.model/META-INF/MANIFEST.MF b/chemclipse/plugins/org.eclipse.chemclipse.xxd.model/META-INF/MANIFEST.MF index 36a497a5c0..441d66da3a 100644 --- a/chemclipse/plugins/org.eclipse.chemclipse.xxd.model/META-INF/MANIFEST.MF +++ b/chemclipse/plugins/org.eclipse.chemclipse.xxd.model/META-INF/MANIFEST.MF @@ -65,4 +65,5 @@ Service-Component: OSGI-INF/org.eclipse.chemclipse.xxd.model.filter.peaks.Asymme OSGI-INF/org.eclipse.chemclipse.xxd.model.filter.peaks.LowPassPeaksFilter.xml, OSGI-INF/org.eclipse.chemclipse.xxd.model.filter.peaks.DeletePeaksByTargetFilter.xml, OSGI-INF/org.eclipse.chemclipse.xxd.model.filter.peaks.ClassifierAssignFilter.xml, - OSGI-INF/org.eclipse.chemclipse.xxd.model.filter.peaks.ClassifierRemoveFilter.xml + OSGI-INF/org.eclipse.chemclipse.xxd.model.filter.peaks.ClassifierRemoveFilter.xml, + OSGI-INF/org.eclipse.chemclipse.xxd.model.filter.peaks.ClassifierAddFilter.xml diff --git a/chemclipse/plugins/org.eclipse.chemclipse.xxd.model/OSGI-INF/org.eclipse.chemclipse.xxd.model.filter.peaks.ClassifierAddFilter.xml b/chemclipse/plugins/org.eclipse.chemclipse.xxd.model/OSGI-INF/org.eclipse.chemclipse.xxd.model.filter.peaks.ClassifierAddFilter.xml new file mode 100644 index 0000000000..1459bfafa1 --- /dev/null +++ b/chemclipse/plugins/org.eclipse.chemclipse.xxd.model/OSGI-INF/org.eclipse.chemclipse.xxd.model.filter.peaks.ClassifierAddFilter.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/chemclipse/plugins/org.eclipse.chemclipse.xxd.model/src/org/eclipse/chemclipse/xxd/model/filter/peaks/ClassifierAddFilter.java b/chemclipse/plugins/org.eclipse.chemclipse.xxd.model/src/org/eclipse/chemclipse/xxd/model/filter/peaks/ClassifierAddFilter.java new file mode 100644 index 0000000000..2c11b489b4 --- /dev/null +++ b/chemclipse/plugins/org.eclipse.chemclipse.xxd.model/src/org/eclipse/chemclipse/xxd/model/filter/peaks/ClassifierAddFilter.java @@ -0,0 +1,84 @@ +/******************************************************************************* + * 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.xxd.model.filter.peaks; + +import java.util.Collection; + +import org.eclipse.chemclipse.model.core.IPeak; +import org.eclipse.chemclipse.model.core.IPeakModel; +import org.eclipse.chemclipse.model.filter.IPeakFilter; +import org.eclipse.chemclipse.processing.Processor; +import org.eclipse.chemclipse.processing.core.MessageConsumer; +import org.eclipse.chemclipse.processing.filter.CRUDListener; +import org.eclipse.chemclipse.processing.filter.Filter; +import org.eclipse.chemclipse.xxd.model.settings.peaks.ClassifierAddFilterSettings; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.SubMonitor; +import org.osgi.service.component.annotations.Component; + +@Component(service = {IPeakFilter.class, Filter.class, Processor.class}) +public class ClassifierAddFilter implements IPeakFilter { + + @Override + public String getName() { + + return "Peak Classifier (Add)"; + } + + @Override + public String getDescription() { + + return "Adds the given classifier."; + } + + @Override + public Class getConfigClass() { + + return ClassifierAddFilterSettings.class; + } + + @Override + public boolean acceptsIPeaks(Collection items) { + + return true; + } + + @Override + public void filterIPeaks(CRUDListener listener, ClassifierAddFilterSettings configuration, MessageConsumer messageConsumer, IProgressMonitor monitor) throws IllegalArgumentException { + + Collection peaks = listener.read(); + if(configuration == null) { + configuration = createConfiguration(peaks); + } + // + String classification = configuration.getClassification(); + boolean skipClassifiedPeak = configuration.isSkipClassifiedPeak(); + SubMonitor subMonitor = SubMonitor.convert(monitor, peaks.size()); + for(X peak : peaks) { + /* + * Peak Classifier + */ + boolean classify = true; + if(peak.getClassifier().size() > 0) { + if(skipClassifiedPeak) { + classify = false; + } + } + // + if(classify) { + peak.addClassifier(classification); + } + // + subMonitor.worked(1); + } + } +} \ No newline at end of file diff --git a/chemclipse/plugins/org.eclipse.chemclipse.xxd.model/src/org/eclipse/chemclipse/xxd/model/settings/peaks/ClassifierAddFilterSettings.java b/chemclipse/plugins/org.eclipse.chemclipse.xxd.model/src/org/eclipse/chemclipse/xxd/model/settings/peaks/ClassifierAddFilterSettings.java new file mode 100644 index 0000000000..208e808a47 --- /dev/null +++ b/chemclipse/plugins/org.eclipse.chemclipse.xxd.model/src/org/eclipse/chemclipse/xxd/model/settings/peaks/ClassifierAddFilterSettings.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * 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.xxd.model.settings.peaks; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyDescription; + +public class ClassifierAddFilterSettings { + + @JsonProperty(value = "Classification", defaultValue = "") + @JsonPropertyDescription(value = "This is the classification that shall be set.") + private String classification = ""; + @JsonProperty(value = "Skip Classified Peaks", defaultValue = "true") + @JsonPropertyDescription(value = "Skip peaks that have been classified already.") + private boolean skipClassifiedPeak = true; + + public String getClassification() { + + return classification; + } + + public void setClassification(String classification) { + + this.classification = classification; + } + + public boolean isSkipClassifiedPeak() { + + return skipClassifiedPeak; + } + + public void setSkipClassifiedPeak(boolean skipClassifiedPeak) { + + this.skipClassifiedPeak = skipClassifiedPeak; + } +} \ No newline at end of file