Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit bfaf0d3
Author: Christoph Läubrich <[email protected]>
Date:   Mon Sep 30 10:19:05 2019 +0200

    Fix #42

commit a6a2a59
Author: Christoph Läubrich <[email protected]>
Date:   Sun Sep 29 19:19:43 2019 +0200

    #39 add option to use a preference page instead of a button

commit f92601d
Author: Christoph Läubrich <[email protected]>
Date:   Sun Sep 29 18:13:05 2019 +0200

    Fix #36

commit 97ac273
Author: Christoph Läubrich <[email protected]>
Date:   Sun Sep 29 14:49:03 2019 +0200

    Fix #39

commit 8f3aa74
Author: Christoph Läubrich <[email protected]>
Date:   Fri Sep 27 15:14:28 2019 +0200

    Fix #33

commit 5b0845d
Author: Christoph Läubrich <[email protected]>
Date:   Fri Sep 27 15:00:11 2019 +0200

    Fix #32

commit 7e18420
Author: Christoph Läubrich <[email protected]>
Date:   Fri Sep 27 08:31:32 2019 +0200

    Fix #31

commit 8a26934
Author: Christoph Läubrich <[email protected]>
Date:   Fri Sep 27 07:51:44 2019 +0200

    Refactoring to support #31

commit b8aad6a
Author: Christoph Läubrich <[email protected]>
Date:   Thu Sep 26 19:40:47 2019 +0200

    Refactoring to support #31
  • Loading branch information
kerner1000 committed Sep 30, 2019
1 parent b8919e7 commit b9788db
Show file tree
Hide file tree
Showing 44 changed files with 1,630 additions and 853 deletions.
5 changes: 5 additions & 0 deletions chemclipse/plugins/org.eclipse.chemclipse.converter/.project
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ds.core.builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
eclipse.preferences.version=1
enabled=true
generateBundleActivationPolicyLazy=true
path=OSGI-INF
validationErrorLevel=error
validationErrorLevel.missingImplicitUnbindMethod=error
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,7 @@ Export-Package: org.eclipse.chemclipse.converter.chromatogram,
org.eclipse.chemclipse.converter.scan,
org.eclipse.chemclipse.converter.sequence,
org.eclipse.chemclipse.converter.support
Import-Package: com.fasterxml.jackson.annotation;version="2.9.2"
Import-Package: com.fasterxml.jackson.annotation;version="2.9.2",
org.osgi.service.component.annotations;version="1.2.0"
Service-Component: OSGI-INF/org.eclipse.chemclipse.converter.methods.MethodProcessTypeSupplier.xml

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="org.eclipse.chemclipse.converter.methods.MethodProcessTypeSupplier">
<service>
<provide interface="org.eclipse.chemclipse.processing.supplier.IProcessTypeSupplier"/>
</service>
<implementation class="org.eclipse.chemclipse.converter.methods.MethodProcessTypeSupplier"/>
</scr:component>
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*******************************************************************************
* Copyright (c) 2019 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:
* Christoph Läubrich - initial API and implementation
*******************************************************************************/
package org.eclipse.chemclipse.converter.methods;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.eclipse.chemclipse.model.core.IMeasurement;
import org.eclipse.chemclipse.model.methods.IProcessEntry;
import org.eclipse.chemclipse.model.methods.IProcessMethod;
import org.eclipse.chemclipse.model.selection.IChromatogramSelection;
import org.eclipse.chemclipse.model.supplier.IChromatogramSelectionProcessSupplier;
import org.eclipse.chemclipse.model.supplier.IMeasurementProcessSupplier;
import org.eclipse.chemclipse.model.types.DataType;
import org.eclipse.chemclipse.processing.DataCategory;
import org.eclipse.chemclipse.processing.supplier.AbstractProcessSupplier;
import org.eclipse.chemclipse.processing.supplier.IProcessSupplier;
import org.eclipse.chemclipse.processing.supplier.IProcessTypeSupplier;
import org.eclipse.chemclipse.processing.supplier.ProcessExecutionContext;
import org.osgi.service.component.annotations.Component;

@Component(service = {IProcessTypeSupplier.class})
public class MethodProcessTypeSupplier implements IProcessTypeSupplier {

@Override
public String getCategory() {

return "User Methods";
}

@Override
public Collection<IProcessSupplier<?>> getProcessorSuppliers() {

List<IProcessSupplier<?>> list = new ArrayList<>();
Collection<IProcessMethod> userMethods = MethodConverter.getUserMethods();
for(IProcessMethod processMethod : userMethods) {
list.add(new MethodProcessSupplier(processMethod, this));
}
return list;
}

private static final class MethodProcessSupplier extends AbstractProcessSupplier<Void> implements IMeasurementProcessSupplier<Void>, IChromatogramSelectionProcessSupplier<Void> {

private IProcessMethod method;

public MethodProcessSupplier(IProcessMethod method, IProcessTypeSupplier parent) {
super("ProcessMethod." + method.getUUID(), method.getName(), method.getDescription(), null, parent, getDataTypes(method));
this.method = method;
}

@Override
public IChromatogramSelection<?, ?> apply(IChromatogramSelection<?, ?> chromatogramSelection, Void processSettings, ProcessExecutionContext context) {

return IChromatogramSelectionProcessSupplier.applyProcessMethod(chromatogramSelection, method, context);
}

@Override
public Collection<? extends IMeasurement> applyProcessor(Collection<? extends IMeasurement> measurements, Void processSettings, ProcessExecutionContext context) {

return IMeasurementProcessSupplier.applyProcessMethod(measurements, method, context);
}
}

private static DataCategory[] getDataTypes(IProcessMethod method) {

Set<DataCategory> categories = new HashSet<>();
for(IProcessEntry entry : method) {
List<DataType> dataTypes = entry.getSupportedDataTypes();
for(DataType dataType : dataTypes) {
categories.add(dataType.toDataCategory());
}
}
return categories.toArray(new DataCategory[0]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
*******************************************************************************/
package org.eclipse.chemclipse.model;

import org.eclipse.chemclipse.model.methods.IProcessEntry;
import org.eclipse.chemclipse.model.methods.IProcessMethod;
import org.eclipse.chemclipse.model.methods.ProcessEntry;
import org.eclipse.chemclipse.model.methods.ProcessMethod;
import org.eclipse.chemclipse.support.settings.serialization.JSONSerialization;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;

Expand All @@ -27,17 +32,23 @@ public static BundleContext getContext() {
* (non-Javadoc)
* @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
*/
@Override
public void start(BundleContext bundleContext) throws Exception {

JSONSerialization.addMapping(IProcessMethod.class, ProcessMethod.class);
JSONSerialization.addMapping(IProcessEntry.class, ProcessEntry.class);
Activator.context = bundleContext;
}

/*
* (non-Javadoc)
* @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
*/
@Override
public void stop(BundleContext bundleContext) throws Exception {

JSONSerialization.removeMapping(IProcessMethod.class, ProcessMethod.class);
JSONSerialization.removeMapping(IProcessEntry.class, ProcessEntry.class);
Activator.context = null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ public abstract class AbstractChromatogram<T extends IPeak> extends AbstractMeas
/*
* Some vendors store several chromatograms in one file.
*/
@SuppressWarnings("rawtypes")
private List<IChromatogram> referencedChromatograms;
private List<IChromatogram<?>> referencedChromatograms;
/*
* Integration entries.
*/
Expand Down Expand Up @@ -125,7 +124,7 @@ public AbstractChromatogram() {
editHistory = new EditHistory();
baselineModel = new BaselineModel(this);
scans = new ArrayList<IScan>();
referencedChromatograms = new ArrayList<IChromatogram>();
referencedChromatograms = new ArrayList<IChromatogram<?>>();
chromatogramIntegrationEntries = new ArrayList<IIntegrationEntry>();
backgroundIntegrationEntries = new ArrayList<IIntegrationEntry>();
method = new TripleQuadMethod();
Expand Down Expand Up @@ -701,9 +700,8 @@ public String extractNameFromFile(String nameDefault) {
return nameDefault;
}

@SuppressWarnings("rawtypes")
@Override
public List<IChromatogram> getReferencedChromatograms() {
public List<IChromatogram<?>> getReferencedChromatograms() {

return referencedChromatograms;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,24 +149,21 @@ public interface IChromatogram<T extends IPeak> extends IMeasurement, IChromatog
*
* @return {@link IChromatogram}
*/
@SuppressWarnings("rawtypes")
List<IChromatogram> getReferencedChromatograms();
List<IChromatogram<?>> getReferencedChromatograms();

/**
* Add a referenced chromatogram.
*
* @param chromatogram
*/
@SuppressWarnings("rawtypes")
void addReferencedChromatogram(IChromatogram chromatogram);
void addReferencedChromatogram(IChromatogram<?> chromatogram);

/**
* Removes a referenced chromatogram.
*
* @param chromatogram
*/
@SuppressWarnings("rawtypes")
void removeReferencedChromatogram(IChromatogram chromatogram);
void removeReferencedChromatogram(IChromatogram<?> chromatogram);

void removeAllReferencedChromatograms();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
import java.util.List;

import org.eclipse.chemclipse.model.types.DataType;
import org.eclipse.chemclipse.processing.supplier.IProcessSupplier;
import org.eclipse.chemclipse.processing.supplier.ProcessSupplierContext;
import org.eclipse.chemclipse.processing.supplier.ProcessorPreferences;

public interface IProcessEntry {

Expand All @@ -36,4 +39,13 @@ public interface IProcessEntry {
void setJsonSettings(String jsonSettings);

List<DataType> getSupportedDataTypes();

public static <T> ProcessorPreferences<T> getProcessEntryPreferences(IProcessEntry entry, ProcessSupplierContext context) {

IProcessSupplier<T> supplier = context.getSupplier(entry.getProcessorId());
if(supplier == null) {
return null;
}
return new ProcessEntryProcessorPreferences<>(supplier, entry);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@
*******************************************************************************/
package org.eclipse.chemclipse.model.methods;

import java.io.IOException;
import java.util.Iterator;
import java.util.function.BiConsumer;

import org.eclipse.chemclipse.processing.supplier.IProcessSupplier;
import org.eclipse.chemclipse.processing.supplier.ProcessExecutionContext;
import org.eclipse.chemclipse.processing.supplier.ProcessorPreferences;

public interface IProcessMethod extends Iterable<IProcessEntry> {

Expand Down Expand Up @@ -116,6 +122,25 @@ default boolean isReadOnly() {

int getNumberOfEntries();

static <X> void applyProcessors(IProcessMethod processMethod, ProcessExecutionContext context, BiConsumer<IProcessSupplier<X>, X> consumer) {

for(IProcessEntry processEntry : processMethod) {
ProcessorPreferences<X> preferences = IProcessEntry.getProcessEntryPreferences(processEntry, context);
if(preferences == null) {
context.addWarnMessage(processEntry.getName(), "processor not found, will be skipped");
continue;
}
try {
X settings = preferences.getSettings();
consumer.accept(preferences.getSupplier(), settings);
} catch(IOException e) {
context.addWarnMessage(processEntry.getName(), "the settings can't be read, will be skipped", e);
} catch(RuntimeException e) {
context.addErrorMessage(processEntry.getName(), "internal error", e);
}
}
}

static IProcessMethod unmodifiable(IProcessMethod delegate) {

return new IProcessMethod() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*******************************************************************************
* Copyright (c) 2019 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:
* Christoph Läubrich - initial API and implementation
*******************************************************************************/
package org.eclipse.chemclipse.model.methods;

import org.eclipse.chemclipse.processing.supplier.IProcessSupplier;
import org.eclipse.chemclipse.processing.supplier.ProcessorPreferences;

public final class ProcessEntryProcessorPreferences<T> implements ProcessorPreferences<T> {

private IProcessEntry processEntry;
private IProcessSupplier<T> supplier;

public ProcessEntryProcessorPreferences(IProcessSupplier<T> supplier, IProcessEntry processEntry) {
this.supplier = supplier;
this.processEntry = processEntry;
}

@Override
public DialogBehavior getDialogBehaviour() {

return DialogBehavior.NONE;
}

@Override
public void setAskForSettings(boolean askForSettings) {

// no-op
}

@Override
public void setUserSettings(String settings) {

processEntry.setJsonSettings(settings);
}

@Override
public boolean isUseSystemDefaults() {

if(supplier.getSettingsClass() == null) {
return true;
}
String jsonSettings = processEntry.getJsonSettings();
return jsonSettings == null || jsonSettings.isEmpty() || ProcessEntry.EMPTY_JSON_SETTINGS.equals(jsonSettings);
}

@Override
public void setUseSystemDefaults(boolean useSystemDefaults) {

if(useSystemDefaults) {
processEntry.setJsonSettings(ProcessEntry.EMPTY_JSON_SETTINGS);
}
}

@Override
public void reset() {

throw new UnsupportedOperationException();
}

@Override
public IProcessSupplier<T> getSupplier() {

return supplier;
}

@Override
public String getUserSettingsAsString() {

return processEntry.getJsonSettings();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@
import java.util.HashSet;
import java.util.Set;

import org.eclipse.chemclipse.model.selection.IChromatogramSelection;
import org.eclipse.chemclipse.model.types.DataType;
import org.eclipse.chemclipse.processing.DataCategory;
import org.eclipse.chemclipse.processing.core.MessageConsumer;
import org.eclipse.chemclipse.processing.supplier.AbstractProcessSupplier;
import org.eclipse.chemclipse.processing.supplier.IProcessTypeSupplier;
import org.eclipse.chemclipse.processing.supplier.ProcessExecutionContext;
import org.eclipse.core.runtime.IProgressMonitor;

public abstract class ChromatogramSelectionProcessorSupplier<SettingsClass> extends AbstractProcessSupplier<SettingsClass> implements IChromatogramSelectionProcessSupplier<SettingsClass> {

Expand All @@ -29,6 +33,14 @@ public ChromatogramSelectionProcessorSupplier(String id, String name, String des
super(id, name, description, settingsClass, parent, dataTypes);
}

@Override
public IChromatogramSelection<?, ?> apply(IChromatogramSelection<?, ?> chromatogramSelection, SettingsClass processSettings, ProcessExecutionContext context) {

return apply(chromatogramSelection, processSettings, context, context.getProgressMonitor());
}

protected abstract IChromatogramSelection<?, ?> apply(IChromatogramSelection<?, ?> chromatogramSelection, SettingsClass processSettings, MessageConsumer messageConsumer, IProgressMonitor monitor);

private static DataCategory[] convert(DataType[] dataTypes) {

Set<DataCategory> converted = new HashSet<>();
Expand Down
Loading

0 comments on commit b9788db

Please sign in to comment.