Skip to content

Commit 760349c

Browse files
committed
Add a generic convenience method to dynamically get process settings.
1 parent 0173c5d commit 760349c

File tree

3 files changed

+85
-55
lines changed

3 files changed

+85
-55
lines changed

chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/preferences/PreferenceSupplier.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,6 +1379,26 @@ public static boolean isMergePeaksDeleteOrigins() {
13791379
return INSTANCE().getBoolean(P_MERGE_PEAKS_DELETE_ORIGINS, DEF_MERGE_PEAKS_DELETE_ORIGINS);
13801380
}
13811381

1382+
public static String getScanIdentifierMSD() {
1383+
1384+
return INSTANCE().get(P_SCAN_IDENTIFER_MSD);
1385+
}
1386+
1387+
public static void setScanIdentifierMSD(String identifier) {
1388+
1389+
INSTANCE().set(P_SCAN_IDENTIFER_MSD, identifier);
1390+
}
1391+
1392+
public static String getScanIdentifierWSD() {
1393+
1394+
return INSTANCE().get(P_SCAN_IDENTIFER_WSD);
1395+
}
1396+
1397+
public static void setScanIdentifierWSD(String identifier) {
1398+
1399+
INSTANCE().set(P_SCAN_IDENTIFER_WSD, identifier);
1400+
}
1401+
13821402
public static String getListPathImport() {
13831403

13841404
return INSTANCE().get(P_LIST_PATH_IMPORT, DEF_LIST_PATH_IMPORT);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2026 Lablicate GmbH.
3+
*
4+
* This program and the accompanying materials are made
5+
* available under the terms of the Eclipse Public License 2.0
6+
* which is available at https://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*
10+
* Contributors:
11+
* Philip Wenig - initial API and implementation
12+
*******************************************************************************/
13+
package org.eclipse.chemclipse.ux.extension.xxd.ui.support;
14+
15+
import java.io.IOException;
16+
17+
import org.eclipse.chemclipse.logging.core.Logger;
18+
import org.eclipse.chemclipse.model.settings.IProcessSettings;
19+
import org.eclipse.chemclipse.processing.supplier.IProcessSupplier;
20+
import org.eclipse.chemclipse.processing.supplier.IProcessSupplierContext;
21+
import org.eclipse.chemclipse.processing.supplier.IProcessorPreferences;
22+
import org.eclipse.chemclipse.processing.system.ProcessSettingsSupport;
23+
import org.eclipse.chemclipse.ux.extension.ui.methods.SettingsWizard;
24+
import org.eclipse.chemclipse.ux.extension.xxd.ui.Activator;
25+
import org.eclipse.swt.widgets.Shell;
26+
27+
public class ProcessorSettingsSupport {
28+
29+
private static final Logger logger = Logger.getLogger(ProcessorSettingsSupport.class);
30+
31+
public static <S extends IProcessSettings> S getSettings(Shell shell, String identifier) {
32+
33+
S settings = null;
34+
IProcessSupplierContext supplierContext = Activator.getProcessSupplierContext();
35+
IProcessSupplier<S> processSupplier = supplierContext.getSupplier(identifier);
36+
if(processSupplier != null) {
37+
try {
38+
IProcessorPreferences<S> processorPreferences = SettingsWizard.getSettings(shell, ProcessSettingsSupport.getWorkspacePreferences(processSupplier), true);
39+
if(processorPreferences != null) {
40+
settings = processorPreferences.getSettings();
41+
}
42+
} catch(IOException e) {
43+
logger.warn(e);
44+
}
45+
}
46+
47+
return settings;
48+
}
49+
}

chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/swt/ScanIdentifierUI.java

Lines changed: 16 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
*******************************************************************************/
1313
package org.eclipse.chemclipse.ux.extension.xxd.ui.swt;
1414

15-
import java.io.IOException;
1615
import java.lang.reflect.InvocationTargetException;
1716
import java.util.ArrayList;
1817
import java.util.Arrays;
@@ -32,23 +31,17 @@
3231
import org.eclipse.chemclipse.msd.identifier.MassSpectrumIdentifier;
3332
import org.eclipse.chemclipse.msd.identifier.settings.IMassSpectrumIdentifierSettings;
3433
import org.eclipse.chemclipse.msd.model.core.IScanMSD;
35-
import org.eclipse.chemclipse.processing.supplier.IProcessSupplier;
36-
import org.eclipse.chemclipse.processing.supplier.IProcessSupplierContext;
37-
import org.eclipse.chemclipse.processing.supplier.IProcessorPreferences;
38-
import org.eclipse.chemclipse.processing.system.ProcessSettingsSupport;
3934
import org.eclipse.chemclipse.rcp.ui.icons.core.ApplicationImageFactory;
4035
import org.eclipse.chemclipse.rcp.ui.icons.core.IApplicationImage;
4136
import org.eclipse.chemclipse.rcp.ui.icons.core.IApplicationImageProvider;
4237
import org.eclipse.chemclipse.support.ui.updates.IUpdateListenerUI;
43-
import org.eclipse.chemclipse.ux.extension.ui.methods.SettingsWizard;
44-
import org.eclipse.chemclipse.ux.extension.xxd.ui.Activator;
4538
import org.eclipse.chemclipse.ux.extension.xxd.ui.internal.runnables.MassSpectrumIdentifierRunnable;
4639
import org.eclipse.chemclipse.ux.extension.xxd.ui.internal.runnables.WaveSpectrumIdentifierRunnable;
4740
import org.eclipse.chemclipse.ux.extension.xxd.ui.preferences.PreferenceSupplier;
41+
import org.eclipse.chemclipse.ux.extension.xxd.ui.support.ProcessorSettingsSupport;
4842
import org.eclipse.chemclipse.wsd.model.core.IScanWSD;
4943
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
5044
import org.eclipse.jface.operation.IRunnableWithProgress;
51-
import org.eclipse.jface.preference.IPreferenceStore;
5245
import org.eclipse.swt.SWT;
5346
import org.eclipse.swt.events.SelectionAdapter;
5447
import org.eclipse.swt.events.SelectionEvent;
@@ -77,8 +70,6 @@ public class ScanIdentifierUI extends Composite {
7770
private IMassSpectrumIdentifierSupplier massSpectrumIdentifierSupplier;
7871
private IWaveSpectrumIdentifierSupplier waveSpectrumIdentifierSupplier;
7972

80-
private final IPreferenceStore preferenceStore = Activator.getDefault().getPreferenceStore();
81-
8273
public ScanIdentifierUI(Composite parent, int style) {
8374

8475
super(parent, style);
@@ -250,11 +241,11 @@ private void activateDefaultIdentifierMSD(List<IMassSpectrumIdentifierSupplier>
250241
/*
251242
* Try to set the selected identifier.
252243
*/
253-
String id = preferenceStore.getString(PreferenceSupplier.P_SCAN_IDENTIFER_MSD);
254-
if(!id.isEmpty()) {
244+
String identifier = PreferenceSupplier.getScanIdentifierMSD();
245+
if(!identifier.isEmpty()) {
255246
exitloop:
256247
for(IMassSpectrumIdentifierSupplier identifierSupplier : identifierSuppliers) {
257-
if(id.equals(identifierSupplier.getId())) {
248+
if(identifier.equals(identifierSupplier.getId())) {
258249
massSpectrumIdentifierSupplier = identifierSupplier;
259250
break exitloop;
260251
}
@@ -279,11 +270,11 @@ private void activateDefaultIdentifierWSD(List<IWaveSpectrumIdentifierSupplier>
279270
/*
280271
* Try to set the selected identifier.
281272
*/
282-
String id = preferenceStore.getString(PreferenceSupplier.P_SCAN_IDENTIFER_WSD);
283-
if(!id.isEmpty()) {
273+
String identifier = PreferenceSupplier.getScanIdentifierWSD();
274+
if(!identifier.isEmpty()) {
284275
exitloop:
285276
for(IWaveSpectrumIdentifierSupplier identifierSupplier : identifierSuppliers) {
286-
if(id.equals(identifierSupplier.getId())) {
277+
if(identifier.equals(identifierSupplier.getId())) {
287278
waveSpectrumIdentifierSupplier = identifierSupplier;
288279
break exitloop;
289280
}
@@ -322,7 +313,7 @@ private void createMenuIdentifierMSD(Button button, List<IMassSpectrumIdentifier
322313
public void widgetSelected(SelectionEvent e) {
323314

324315
button.setToolTipText(identifierSupplier.getIdentifierName());
325-
preferenceStore.setValue(PreferenceSupplier.P_SCAN_IDENTIFER_MSD, identifierSupplier.getId());
316+
PreferenceSupplier.setScanIdentifierMSD(identifierSupplier.getId());
326317
massSpectrumIdentifierSupplier = identifierSupplier;
327318
runIdentification();
328319
}
@@ -349,7 +340,7 @@ private void createMenuIdentifierWSD(Button button, List<IWaveSpectrumIdentifier
349340
public void widgetSelected(SelectionEvent e) {
350341

351342
button.setToolTipText(identifierSupplier.getIdentifierName());
352-
preferenceStore.setValue(PreferenceSupplier.P_SCAN_IDENTIFER_WSD, identifierSupplier.getId());
343+
PreferenceSupplier.setScanIdentifierWSD(identifierSupplier.getId());
353344
waveSpectrumIdentifierSupplier = identifierSupplier;
354345
runIdentification();
355346
}
@@ -392,29 +383,14 @@ private void runIdentification(Display display, List<IScanMSD> massSpectra, List
392383
private void runIdentificationMSD(Display display, List<IScanMSD> massSpectra, boolean update) {
393384

394385
if(!massSpectra.isEmpty() && massSpectrumIdentifierSupplier != null) {
395-
/*
396-
* Retrieve the settings interactively.
397-
*/
398-
IMassSpectrumIdentifierSettings identifierSettings = null;
399-
IProcessSupplierContext supplierContext = Activator.getProcessSupplierContext();
400-
IProcessSupplier<? extends IMassSpectrumIdentifierSettings> processSupplier = supplierContext.getSupplier(massSpectrumIdentifierSupplier.getId());
401-
if(processSupplier != null) {
402-
try {
403-
IProcessorPreferences<? extends IMassSpectrumIdentifierSettings> processorPreferences = SettingsWizard.getSettings(getShell(), ProcessSettingsSupport.getWorkspacePreferences(processSupplier), true);
404-
if(processorPreferences != null) {
405-
identifierSettings = processorPreferences.getSettings();
406-
}
407-
} catch(IOException e) {
408-
logger.warn(e);
409-
}
410-
}
411386
/*
412387
* Run the identification using the dynamic settings.
413388
*/
414-
IRunnableWithProgress runnable = new MassSpectrumIdentifierRunnable(massSpectra, massSpectrumIdentifierSupplier.getId(), identifierSettings);
415-
ProgressMonitorDialog monitor = new ProgressMonitorDialog(display.getActiveShell());
416389
try {
417-
monitor.run(true, true, runnable);
390+
IMassSpectrumIdentifierSettings identifierSettings = ProcessorSettingsSupport.getSettings(getShell(), massSpectrumIdentifierSupplier.getId());
391+
IRunnableWithProgress runnable = new MassSpectrumIdentifierRunnable(massSpectra, massSpectrumIdentifierSupplier.getId(), identifierSettings);
392+
ProgressMonitorDialog monitor = new ProgressMonitorDialog(display.getActiveShell());
393+
monitor.run(false, true, runnable);
418394
if(update) {
419395
fireUpdate(display);
420396
}
@@ -430,28 +406,13 @@ private void runIdentificationMSD(Display display, List<IScanMSD> massSpectra, b
430406
private void runIdentificationWSD(Display display, List<IScanWSD> waveSpectra, boolean update) {
431407

432408
if(!waveSpectra.isEmpty() && waveSpectrumIdentifierSupplier != null) {
433-
/*
434-
* Retrieve the settings interactively.
435-
*/
436-
IWaveSpectrumIdentifierSettings identifierSettings = null;
437-
IProcessSupplierContext supplierContext = Activator.getProcessSupplierContext();
438-
IProcessSupplier<? extends IWaveSpectrumIdentifierSettings> processSupplier = supplierContext.getSupplier(waveSpectrumIdentifierSupplier.getId());
439-
if(processSupplier != null) {
440-
try {
441-
IProcessorPreferences<? extends IWaveSpectrumIdentifierSettings> processorPreferences = SettingsWizard.getSettings(getShell(), ProcessSettingsSupport.getWorkspacePreferences(processSupplier), true);
442-
if(processorPreferences != null) {
443-
identifierSettings = processorPreferences.getSettings();
444-
}
445-
} catch(IOException e) {
446-
logger.warn(e);
447-
}
448-
}
449409
/*
450410
* Run the identification using the dynamic settings.
451411
*/
452-
IRunnableWithProgress runnable = new WaveSpectrumIdentifierRunnable(waveSpectra, waveSpectrumIdentifierSupplier.getId(), identifierSettings);
453-
ProgressMonitorDialog monitor = new ProgressMonitorDialog(display.getActiveShell());
454412
try {
413+
IWaveSpectrumIdentifierSettings identifierSettings = ProcessorSettingsSupport.getSettings(getShell(), waveSpectrumIdentifierSupplier.getId());
414+
IRunnableWithProgress runnable = new WaveSpectrumIdentifierRunnable(waveSpectra, waveSpectrumIdentifierSupplier.getId(), identifierSettings);
415+
ProgressMonitorDialog monitor = new ProgressMonitorDialog(display.getActiveShell());
455416
monitor.run(true, true, runnable);
456417
if(update) {
457418
fireUpdate(display);

0 commit comments

Comments
 (0)