Skip to content

Commit da1b5d7

Browse files
committed
Add named wavelengths for the DAD chromatogram overlay
1 parent 96beeca commit da1b5d7

26 files changed

Lines changed: 2305 additions & 6 deletions

File tree

chemclipse/plugins/org.eclipse.chemclipse.model/META-INF/MANIFEST.MF

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ Export-Package: org.eclipse.chemclipse.model.baseline,
5353
org.eclipse.chemclipse.model.traces,
5454
org.eclipse.chemclipse.model.types,
5555
org.eclipse.chemclipse.model.updates,
56-
org.eclipse.chemclipse.model.versioning
56+
org.eclipse.chemclipse.model.versioning,
57+
org.eclipse.chemclipse.model.wavelengths
5758
Import-Package: org.osgi.service.component.annotations;version="1.2.0"
5859
Service-Component: OSGI-INF/org.eclipse.chemclipse.model.supplier.IMeasurementFilterProcessTypeSupplier.xml,
5960
OSGI-INF/org.eclipse.chemclipse.model.supplier.IPeakFilterProcessTypeSupplier.xml
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2020, 2021 Lablicate GmbH.
3+
*
4+
* All rights reserved. This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License v1.0
6+
* which accompanies this distribution, and is available at
7+
* http://www.eclipse.org/legal/epl-v10.html
8+
*
9+
* Contributors:
10+
* Matthias Mailänder - initial API and implementation
11+
*******************************************************************************/
12+
package org.eclipse.chemclipse.model.wavelengths;
13+
14+
public class NamedWavelength {
15+
16+
private String identifier = "";
17+
private String wavelength = "";
18+
19+
public NamedWavelength(String identifier, String wavelength) {
20+
21+
this.identifier = identifier;
22+
this.wavelength = wavelength;
23+
}
24+
25+
public String getIdentifier() {
26+
27+
return identifier;
28+
}
29+
30+
public void setIdentifier(String identifier) {
31+
32+
this.identifier = identifier;
33+
}
34+
35+
public String getWavelengths() {
36+
37+
return wavelength;
38+
}
39+
40+
public void setWavelengths(String wavelength) {
41+
42+
this.wavelength = wavelength;
43+
}
44+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2021 Lablicate GmbH.
3+
*
4+
* All rights reserved. This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License v1.0
6+
* which accompanies this distribution, and is available at
7+
* http://www.eclipse.org/legal/epl-v10.html
8+
*
9+
* Contributors:
10+
* Matthias Mailänder - initial API and implementation
11+
*******************************************************************************/
12+
package org.eclipse.chemclipse.model.wavelengths;
13+
14+
public class NamedWavelengthUtil {
15+
16+
private static final String TRADITIONAL = "Traditional Wavelengths";
17+
private static final String MERCURY_LAMP = "Low Pressure Mercury Lamp";
18+
private static final String ZINC_LAMP = "Zinc Lamp";
19+
//
20+
21+
public static final String getDefaultWavelengths() {
22+
23+
NamedWavelengths namedWavelengths = new NamedWavelengths();
24+
//
25+
namedWavelengths.add(new NamedWavelength(TRADITIONAL, "214 254 280 365"));
26+
namedWavelengths.add(new NamedWavelength(MERCURY_LAMP, "254")); // 253.7 nm
27+
namedWavelengths.add(new NamedWavelength(ZINC_LAMP, "214"));
28+
//
29+
return namedWavelengths.save();
30+
}
31+
}
Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2020, 2021 Lablicate GmbH.
3+
*
4+
* All rights reserved. This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License v1.0
6+
* which accompanies this distribution, and is available at
7+
* http://www.eclipse.org/legal/epl-v10.html
8+
*
9+
* Contributors:
10+
* Philip Wenig - initial API and implementation
11+
* Matthias Mailänder - adapted for DAD
12+
*******************************************************************************/
13+
package org.eclipse.chemclipse.model.wavelengths;
14+
15+
import java.io.BufferedReader;
16+
import java.io.File;
17+
import java.io.FileNotFoundException;
18+
import java.io.FileReader;
19+
import java.io.IOException;
20+
import java.io.PrintWriter;
21+
import java.util.ArrayList;
22+
import java.util.Collection;
23+
import java.util.Collections;
24+
import java.util.HashMap;
25+
import java.util.Iterator;
26+
import java.util.List;
27+
import java.util.Map;
28+
import java.util.Set;
29+
30+
import org.eclipse.chemclipse.logging.core.Logger;
31+
import org.eclipse.chemclipse.support.util.NamedWavelengthListUtil;
32+
33+
public class NamedWavelengths {
34+
35+
private static final Logger logger = Logger.getLogger(NamedWavelengths.class);
36+
//
37+
private NamedWavelengthListUtil namedWavelengthListUtil = new NamedWavelengthListUtil();
38+
private final Map<String, NamedWavelength> namedWavelengthMap = new HashMap<>();
39+
40+
public NamedWavelengths() {
41+
42+
}
43+
44+
/**
45+
* Initializes this named Wavelengths from the given settings.
46+
*
47+
* @param namedWavelengths
48+
*/
49+
public NamedWavelengths(String namedWavelengths) {
50+
51+
load(namedWavelengths);
52+
}
53+
54+
public void addAll(Collection<NamedWavelength> namedWavelengths) {
55+
56+
for(NamedWavelength namedWavelength : namedWavelengths) {
57+
add(namedWavelength);
58+
}
59+
}
60+
61+
public void add(NamedWavelength namedWavelength) {
62+
63+
namedWavelengthMap.put(namedWavelength.getIdentifier(), namedWavelength);
64+
}
65+
66+
public void remove(String identifier) {
67+
68+
namedWavelengthMap.remove(identifier);
69+
}
70+
71+
public void remove(List<NamedWavelength> namedWavelengths) {
72+
73+
for(NamedWavelength namedWavelength : namedWavelengths) {
74+
remove(namedWavelength);
75+
}
76+
}
77+
78+
public void remove(NamedWavelength namedWavelength) {
79+
80+
if(namedWavelength != null) {
81+
namedWavelengthMap.remove(namedWavelength.getIdentifier());
82+
}
83+
}
84+
85+
public NamedWavelength get(String identifier) {
86+
87+
return namedWavelengthMap.get(identifier);
88+
}
89+
90+
public Set<String> keySet() {
91+
92+
return namedWavelengthMap.keySet();
93+
}
94+
95+
public Collection<NamedWavelength> values() {
96+
97+
return namedWavelengthMap.values();
98+
}
99+
100+
public void clear() {
101+
102+
namedWavelengthMap.clear();
103+
}
104+
105+
public String extractNamedWavelength(NamedWavelength namedWavelength) {
106+
107+
StringBuilder builder = new StringBuilder();
108+
extractNamedWavelength(namedWavelength, builder);
109+
return builder.toString();
110+
}
111+
112+
public NamedWavelength extractNamedWavelength(String item) {
113+
114+
NamedWavelength namedWavelength = null;
115+
//
116+
if(!"".equals(item)) {
117+
String[] values = item.split("\\" + NamedWavelengthListUtil.SEPARATOR_ENTRY);
118+
String identifier = ((values.length > 0) ? values[0].trim() : "");
119+
String Wavelengths = ((values.length > 1) ? values[1].trim() : "");
120+
namedWavelength = new NamedWavelength(identifier, Wavelengths);
121+
}
122+
//
123+
return namedWavelength;
124+
}
125+
126+
public void load(String timeRanges) {
127+
128+
loadSettings(timeRanges);
129+
}
130+
131+
public void loadDefault(String timeRanges) {
132+
133+
loadSettings(timeRanges);
134+
}
135+
136+
public String save() {
137+
138+
StringBuilder builder = new StringBuilder();
139+
Iterator<NamedWavelength> iterator = values().iterator();
140+
while(iterator.hasNext()) {
141+
NamedWavelength namedWavelength = iterator.next();
142+
extractNamedWavelength(namedWavelength, builder);
143+
if(iterator.hasNext()) {
144+
builder.append(NamedWavelengthListUtil.SEPARATOR_TOKEN);
145+
}
146+
}
147+
return builder.toString().trim();
148+
}
149+
150+
public void importItems(File file) {
151+
152+
try (BufferedReader bufferedReader = new BufferedReader(new FileReader(file))) {
153+
String line;
154+
while((line = bufferedReader.readLine()) != null) {
155+
NamedWavelength template = extractNamedWavelength(line);
156+
if(template != null) {
157+
add(template);
158+
}
159+
}
160+
} catch(FileNotFoundException e) {
161+
logger.warn(e);
162+
} catch(IOException e) {
163+
logger.warn(e);
164+
}
165+
}
166+
167+
public boolean exportItems(File file) {
168+
169+
try (PrintWriter printWriter = new PrintWriter(file)) {
170+
/*
171+
* Sort the items.
172+
*/
173+
List<NamedWavelength> namedWavelengths = new ArrayList<>(values());
174+
Collections.sort(namedWavelengths, (r1, r2) -> r1.getIdentifier().compareTo(r2.getIdentifier()));
175+
//
176+
Iterator<NamedWavelength> iterator = namedWavelengths.iterator();
177+
while(iterator.hasNext()) {
178+
StringBuilder builder = new StringBuilder();
179+
NamedWavelength template = iterator.next();
180+
extractNamedWavelength(template, builder);
181+
printWriter.println(builder.toString());
182+
}
183+
printWriter.flush();
184+
return true;
185+
} catch(FileNotFoundException e) {
186+
logger.warn(e);
187+
return false;
188+
}
189+
}
190+
191+
private void loadSettings(String timeRanges) {
192+
193+
if(!"".equals(timeRanges)) {
194+
String[] items = namedWavelengthListUtil.parseString(timeRanges);
195+
if(items.length > 0) {
196+
for(String item : items) {
197+
NamedWavelength namedWavelength = extractNamedWavelength(item);
198+
if(namedWavelength != null) {
199+
add(namedWavelength);
200+
}
201+
}
202+
}
203+
}
204+
}
205+
206+
private void extractNamedWavelength(NamedWavelength namedWavelength, StringBuilder builder) {
207+
208+
builder.append(namedWavelength.getIdentifier());
209+
builder.append(" ");
210+
builder.append(NamedWavelengthListUtil.SEPARATOR_ENTRY);
211+
builder.append(" ");
212+
builder.append(namedWavelength.getWavelengths());
213+
}
214+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2020 Lablicate GmbH.
3+
*
4+
* All rights reserved.
5+
* This program and the accompanying materials are made available under the
6+
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
7+
* and is available at http://www.eclipse.org/legal/epl-v10.html
8+
*
9+
* Contributors:
10+
* Philip Wenig - initial API and implementation
11+
*******************************************************************************/
12+
package org.eclipse.chemclipse.support.util;
13+
14+
import java.util.ArrayList;
15+
import java.util.Collections;
16+
import java.util.List;
17+
18+
public class NamedWavelengthListUtil {
19+
20+
public static final String SEPARATOR_TOKEN = ";";
21+
public static final String SEPARATOR_ENTRY = "|";
22+
public static final String SEPARATOR_TRACE = " ";
23+
24+
public String createList(String[] items) {
25+
26+
List<String> list = getValues(items);
27+
String values = "";
28+
for(String value : list) {
29+
values = values.concat(value + SEPARATOR_TOKEN);
30+
}
31+
return values;
32+
}
33+
34+
public String[] parseString(String stringList) {
35+
36+
String[] decodedArray;
37+
if(stringList.contains(SEPARATOR_TOKEN)) {
38+
decodedArray = stringList.split(SEPARATOR_TOKEN);
39+
} else {
40+
decodedArray = new String[]{stringList};
41+
}
42+
return decodedArray;
43+
}
44+
45+
public List<String> getList(String preferenceEntry) {
46+
47+
List<String> values = new ArrayList<String>();
48+
if(preferenceEntry != "") {
49+
String[] items = parseString(preferenceEntry);
50+
if(items.length > 0) {
51+
for(String item : items) {
52+
values.add(item);
53+
}
54+
}
55+
}
56+
Collections.sort(values);
57+
return values;
58+
}
59+
60+
private List<String> getValues(String[] items) {
61+
62+
List<String> values = new ArrayList<String>();
63+
if(items != null) {
64+
int size = items.length;
65+
for(int i = 0; i < size; i++) {
66+
values.add(items[i]);
67+
}
68+
}
69+
return values;
70+
}
71+
}

0 commit comments

Comments
 (0)