Skip to content

Commit 30a4f59

Browse files
committed
Add a name replacer to swap names and a specific synonyms in targets.
1 parent e1174b4 commit 30a4f59

25 files changed

Lines changed: 1655 additions & 4 deletions

openchrom/plugins/net.openchrom.xxd.process.supplier.templates.ui/META-INF/MANIFEST.MF

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,6 @@ Export-Package: net.openchrom.xxd.process.supplier.templates.ui.charts,
5858
net.openchrom.xxd.process.supplier.templates.ui.swt.peaks,
5959
net.openchrom.xxd.process.supplier.templates.ui.validators,
6060
net.openchrom.xxd.process.supplier.templates.ui.wizards
61-
Service-Component: OSGI-INF/net.openchrom.xxd.process.supplier.templates.ui.services.ReportColumnsAnnotationService.xml,
61+
Service-Component: OSGI-INF/net.openchrom.xxd.process.supplier.templates.ui.services.NameReplacementsAnnotationService.xml,
62+
OSGI-INF/net.openchrom.xxd.process.supplier.templates.ui.services.ReportColumnsAnnotationService.xml,
6263
OSGI-INF/net.openchrom.xxd.process.supplier.templates.ui.services.ReportSettingsAnnotationService.xml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" configuration-policy="optional" name="net.openchrom.xxd.process.supplier.templates.ui.services.NameReplacementsAnnotationService">
3+
<service>
4+
<provide interface="org.eclipse.chemclipse.support.ui.services.IAnnotationWidgetService"/>
5+
</service>
6+
<implementation class="net.openchrom.xxd.process.supplier.templates.ui.services.NameReplacementsAnnotationService"/>
7+
</scr:component>

openchrom/plugins/net.openchrom.xxd.process.supplier.templates.ui/plugin.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,4 +333,11 @@
333333
id="net.openchrom.xxd.process.supplier.templates.ui.msd">
334334
</icon>
335335
</extension>
336+
<extension
337+
point="org.eclipse.chemclipse.xxd.process.ui.menu.icon">
338+
<icon
339+
class="net.openchrom.xxd.process.supplier.templates.ui.icon.ReplacerMenuIcon"
340+
id="net.openchrom.xxd.process.supplier.templates.processors.nameReplacer">
341+
</icon>
342+
</extension>
336343
</plugin>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
* Matthias Mailänder - initial API and implementation
12+
*******************************************************************************/
13+
package net.openchrom.xxd.process.supplier.templates.ui.icon;
14+
15+
import org.eclipse.chemclipse.rcp.ui.icons.core.ApplicationImageFactory;
16+
import org.eclipse.chemclipse.rcp.ui.icons.core.IApplicationImage;
17+
import org.eclipse.chemclipse.rcp.ui.icons.core.IApplicationImageProvider;
18+
import org.eclipse.chemclipse.xxd.process.ui.menu.IMenuIcon;
19+
import org.eclipse.swt.graphics.Image;
20+
21+
public class ReplacerMenuIcon implements IMenuIcon {
22+
23+
@Override
24+
public Image getImage() {
25+
26+
return ApplicationImageFactory.getInstance().getImage(IApplicationImage.IMAGE_TAG, IApplicationImageProvider.SIZE_16x16);
27+
}
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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 net.openchrom.xxd.process.supplier.templates.ui.internal.provider;
14+
15+
import org.eclipse.core.runtime.IStatus;
16+
import org.eclipse.jface.dialogs.IInputValidator;
17+
18+
import net.openchrom.xxd.process.supplier.templates.model.NameReplacement;
19+
import net.openchrom.xxd.process.supplier.templates.model.NameReplacements;
20+
import net.openchrom.xxd.process.supplier.templates.util.NameReplacementValidator;
21+
22+
public class NameReplacementInputValidator implements IInputValidator {
23+
24+
private NameReplacementValidator validator = new NameReplacementValidator();
25+
private NameReplacements nameReplacements;
26+
27+
public NameReplacementInputValidator(NameReplacements nameReplacements) {
28+
29+
this.nameReplacements = nameReplacements;
30+
}
31+
32+
@Override
33+
public String isValid(String target) {
34+
35+
IStatus status = validator.validate(target);
36+
if(status.isOK()) {
37+
NameReplacement setting = validator.getSetting();
38+
if(nameReplacements.contains(setting)) {
39+
return "The element already exists: name, synonym.";
40+
}
41+
} else {
42+
return status.getMessage();
43+
}
44+
return null;
45+
}
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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 net.openchrom.xxd.process.supplier.templates.ui.internal.provider;
14+
15+
import org.eclipse.chemclipse.support.ui.swt.AbstractRecordTableComparator;
16+
import org.eclipse.jface.viewers.Viewer;
17+
18+
import net.openchrom.xxd.process.supplier.templates.model.NameReplacement;
19+
20+
public class NameReplacementsComparator extends AbstractRecordTableComparator {
21+
22+
@Override
23+
public int compare(Viewer viewer, Object e1, Object e2) {
24+
25+
int sortOrder = 0;
26+
if(e1 instanceof NameReplacement setting1 && e2 instanceof NameReplacement setting2) {
27+
switch(getPropertyIndex()) {
28+
case 0:
29+
sortOrder = setting2.getName().compareTo(setting1.getName());
30+
break;
31+
case 1:
32+
sortOrder = setting2.getSynonym().compareTo(setting1.getSynonym());
33+
break;
34+
default:
35+
sortOrder = 0;
36+
}
37+
}
38+
if(getDirection() == ASCENDING) {
39+
sortOrder = -sortOrder;
40+
}
41+
return sortOrder;
42+
}
43+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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 net.openchrom.xxd.process.supplier.templates.ui.internal.provider;
14+
15+
import org.eclipse.chemclipse.support.ui.swt.ExtendedTableViewer;
16+
import org.eclipse.jface.viewers.CellEditor;
17+
import org.eclipse.jface.viewers.EditingSupport;
18+
import org.eclipse.jface.viewers.TextCellEditor;
19+
20+
import net.openchrom.xxd.process.supplier.templates.model.NameReplacement;
21+
22+
public class NameReplacementsEditingSupport extends EditingSupport {
23+
24+
private CellEditor cellEditor;
25+
private ExtendedTableViewer tableViewer;
26+
private String column;
27+
28+
public NameReplacementsEditingSupport(ExtendedTableViewer tableViewer, String column) {
29+
30+
super(tableViewer);
31+
this.column = column;
32+
this.cellEditor = new TextCellEditor(tableViewer.getTable());
33+
this.tableViewer = tableViewer;
34+
}
35+
36+
@Override
37+
protected CellEditor getCellEditor(Object element) {
38+
39+
return cellEditor;
40+
}
41+
42+
@Override
43+
protected boolean canEdit(Object element) {
44+
45+
return tableViewer.isEditEnabled();
46+
}
47+
48+
@Override
49+
protected Object getValue(Object element) {
50+
51+
/*
52+
* Do not edit the name
53+
*/
54+
if(element instanceof NameReplacement setting) {
55+
switch(column) {
56+
case NameReplacementsLabelProvider.SYNONYM:
57+
return setting.getSynonym();
58+
}
59+
}
60+
return false;
61+
}
62+
63+
@Override
64+
protected void setValue(Object element, Object value) {
65+
66+
/*
67+
* Do not edit the name
68+
*/
69+
if(element instanceof NameReplacement setting) {
70+
switch(column) {
71+
case NameReplacementsLabelProvider.SYNONYM:
72+
setting.setSynonym(value.toString());
73+
break;
74+
}
75+
tableViewer.refresh();
76+
}
77+
}
78+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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 net.openchrom.xxd.process.supplier.templates.ui.internal.provider;
14+
15+
import org.eclipse.jface.viewers.Viewer;
16+
import org.eclipse.jface.viewers.ViewerFilter;
17+
18+
import net.openchrom.xxd.process.supplier.templates.model.NameReplacement;
19+
20+
public class NameReplacementsFilter extends ViewerFilter {
21+
22+
private String searchText;
23+
private boolean caseSensitive;
24+
25+
public void setSearchText(String searchText, boolean caseSensitive) {
26+
27+
this.searchText = searchText;
28+
this.caseSensitive = caseSensitive;
29+
}
30+
31+
@Override
32+
public boolean select(Viewer viewer, Object parentElement, Object element) {
33+
34+
if(searchText == null || searchText.equals("")) {
35+
return true;
36+
}
37+
38+
if(element instanceof NameReplacement setting) {
39+
40+
if(!caseSensitive) {
41+
searchText = searchText.toLowerCase();
42+
}
43+
44+
String name = caseSensitive ? setting.getName() : setting.getName().toLowerCase();
45+
if(name.contains(searchText)) {
46+
return true;
47+
}
48+
49+
String synonym = caseSensitive ? setting.getSynonym() : setting.getSynonym().toLowerCase();
50+
if(synonym.contains(searchText)) {
51+
return true;
52+
}
53+
}
54+
55+
return false;
56+
}
57+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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 net.openchrom.xxd.process.supplier.templates.ui.internal.provider;
14+
15+
import org.eclipse.chemclipse.rcp.ui.icons.core.ApplicationImageFactory;
16+
import org.eclipse.chemclipse.rcp.ui.icons.core.IApplicationImage;
17+
import org.eclipse.chemclipse.rcp.ui.icons.core.IApplicationImageProvider;
18+
import org.eclipse.jface.viewers.ColumnLabelProvider;
19+
import org.eclipse.jface.viewers.ITableLabelProvider;
20+
import org.eclipse.swt.graphics.Image;
21+
22+
import net.openchrom.xxd.process.supplier.templates.model.NameReplacement;
23+
24+
public class NameReplacementsLabelProvider extends ColumnLabelProvider implements ITableLabelProvider {
25+
26+
public static final String NAME = "Name";
27+
public static final String SYNONYM = "Synonym";
28+
29+
public static final String[] TITLES = { //
30+
NAME, //
31+
SYNONYM //
32+
};
33+
34+
public static final int[] BOUNDS = { //
35+
200, //
36+
200 //
37+
};
38+
39+
@Override
40+
public Image getColumnImage(Object element, int columnIndex) {
41+
42+
if(columnIndex == 0) {
43+
return getImage(element);
44+
}
45+
return null;
46+
}
47+
48+
@Override
49+
public String getColumnText(Object element, int columnIndex) {
50+
51+
String text = "";
52+
if(element instanceof NameReplacement setting) {
53+
switch(columnIndex) {
54+
case 0:
55+
text = setting.getName();
56+
break;
57+
case 1:
58+
text = setting.getSynonym();
59+
break;
60+
default:
61+
text = "n.v.";
62+
}
63+
}
64+
return text;
65+
}
66+
67+
@Override
68+
public Image getImage(Object element) {
69+
70+
return ApplicationImageFactory.getInstance().getImage(IApplicationImage.IMAGE_TAG, IApplicationImageProvider.SIZE_16x16);
71+
}
72+
}

0 commit comments

Comments
 (0)