Skip to content

Commit

Permalink
Add support for labeled enum settings.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mailaender committed Sep 30, 2021
1 parent a738ee7 commit fdf1929
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ Require-Bundle: org.eclipse.chemclipse.numeric;bundle-version="0.8.0",
org.eclipse.chemclipse.model;bundle-version="0.8.0",
org.eclipse.core.runtime;bundle-version="3.9.100",
org.eclipse.chemclipse.processing;bundle-version="0.8.0",
org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.savitzkygolay
org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.savitzkygolay,
org.eclipse.chemclipse.support
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,37 @@
* Contributors:
* Alexander Kerner - initial API and implementation
* Philip Wenig - add elements for combo support
* Matthias Mailänder - add labels
*******************************************************************************/
package org.eclipse.chemclipse.chromatogram.peak.detector.core;

public enum FilterMode {
INCLUDE, //
EXCLUDE;
import org.eclipse.chemclipse.support.text.ILabel;

public enum FilterMode implements ILabel {

INCLUDE("inclusive"), //
EXCLUDE("exclusive");

private String label;

private FilterMode(String label) {

this.label = label;
}

@Override
public String label() {

return label;
}

public static String[][] getElements() {

String[][] elements = new String[values().length][2];
int counter = 0;
for(FilterMode filterMode : values()) {
elements[counter][0] = filterMode.name(); // Label
elements[counter][1] = filterMode.name(); // Value
elements[counter][0] = filterMode.label();
elements[counter][1] = filterMode.name();
counter++;
}
return elements;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@
*
* Contributors:
* Dr. Philip Wenig - initial API and implementation
* Matthias Mailänder - add label
*******************************************************************************/
package org.eclipse.chemclipse.chromatogram.peak.detector.model;

public enum Threshold {
import org.eclipse.chemclipse.support.text.ILabel;

public enum Threshold implements ILabel {

OFF(1), //
LOW(2), //
MEDIUM(3), //
Expand All @@ -29,13 +33,19 @@ public int getThreshold() {
return threshold;
}

@Override
public String label() {

return name().toLowerCase();
}

public static String[][] getElements() {

String[][] elements = new String[values().length][2];
int counter = 0;
for(Threshold threshold : values()) {
elements[counter][0] = threshold.name(); // Label
elements[counter][1] = threshold.name(); // Value
elements[counter][0] = threshold.label();
elements[counter][1] = threshold.name();
counter++;
}
return elements;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,15 @@ private ObjectMapper createMapper() {
/*
* Add additional mapper dynamically.
*/
for(Object object : Activator.getDefault().getSerializationServices()) {
if(object instanceof ISerializationService) {
ISerializationService serializationService = (ISerializationService)object;
Class clazz = serializationService.getSupportedClass();
simpleModule.addSerializer(clazz, serializationService.getSerializer());
simpleModule.addDeserializer(clazz, serializationService.getDeserializer());
Object[] serializationServices = Activator.getDefault().getSerializationServices();
if(serializationServices != null) {
for(Object object : Activator.getDefault().getSerializationServices()) {
if(object instanceof ISerializationService) {
ISerializationService serializationService = (ISerializationService)object;
Class clazz = serializationService.getSupportedClass();
simpleModule.addSerializer(clazz, serializationService.getSerializer());
simpleModule.addDeserializer(clazz, serializationService.getDeserializer());
}
}
}
//
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*******************************************************************************
* 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:
* Matthias Mailänder - initial API and implementation
*******************************************************************************/
package org.eclipse.chemclipse.support.text;

public interface ILabel {

String label();
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@
* Contributors:
* Dr. Philip Wenig - initial API and implementation
* Christoph Läubrich - support file selection, refactor for new settings model, use validators, support for longs
* Matthias Mailänder - add labeled combo boxes
*******************************************************************************/
package org.eclipse.chemclipse.ux.extension.xxd.ui.methods;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import org.eclipse.chemclipse.support.settings.ComboSettingsProperty.ComboSupplier;
import org.eclipse.chemclipse.support.settings.FileSettingProperty;
import org.eclipse.chemclipse.support.settings.FileSettingProperty.DialogType;
import org.eclipse.chemclipse.support.settings.parser.InputValue;
import org.eclipse.chemclipse.support.settings.validation.InputValidator;
import org.eclipse.chemclipse.support.text.ILabel;
import org.eclipse.chemclipse.support.ui.provider.AbstractLabelProvider;
import org.eclipse.chemclipse.support.ui.provider.AdapterLabelProvider;
import org.eclipse.chemclipse.ux.extension.xxd.ui.Activator;
Expand Down Expand Up @@ -171,9 +171,8 @@ public Object getValue() {
if(comboSupplier != null) {
return getValueAsString(comboSupplier);
}
Combo combo = (Combo)control;
if(rawType.isEnum()) {
return combo.getText().trim();
return currentSelection.toString();
}
} else {
/*
Expand Down Expand Up @@ -229,12 +228,9 @@ private Control createControl(Composite parent) {
} else if(rawType == boolean.class || rawType == Boolean.class) {
return createCheckboxWidget(parent);
} else if(rawType.isEnum()) {
List<String> input = new ArrayList<>();
Enum[] enums = (Enum[])rawType.getEnumConstants();
for(int i = 0; i < enums.length; i++) {
input.add(enums[i].toString());
}
return createEnumComboViewerWidget(parent, input);
ComboViewer viewer = createLabeledEnumComboViewerWidget(parent, enums);
return viewer.getControl();
} else if(rawType == File.class) {
return createFileWidget(parent);
} else {
Expand Down Expand Up @@ -407,29 +403,41 @@ private Control createCheckboxWidget(Composite parent) {
return button;
}

private Control createEnumComboViewerWidget(Composite parent, List<String> input) {
private ComboViewer createLabeledEnumComboViewerWidget(Composite parent, Enum[] input) {

ComboViewer comboViewer = new ComboViewer(parent, SWT.READ_ONLY);
//
Combo combo = comboViewer.getCombo();
comboViewer.setContentProvider(ArrayContentProvider.getInstance());
comboViewer.setLabelProvider(new AbstractLabelProvider() {

@Override
public String getText(Object element) {

if(element instanceof ILabel) {
return ((ILabel)element).label();
}
return element.toString();
}
});
Combo combo = comboViewer.getCombo();
combo.setToolTipText(inputValue.getDescription());
GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.widthHint = 150;
combo.setLayoutData(gridData);
//
comboViewer.setInput(input);
combo.setText(getValueAsString());
Enum initialSelection = Enum.valueOf(input[0].getDeclaringClass(), getValueAsString());
comboViewer.setSelection(new StructuredSelection(initialSelection));
//
comboViewer.addSelectionChangedListener(new ISelectionChangedListener() {

@Override
public void selectionChanged(SelectionChangedEvent event) {

currentSelection = comboViewer.getStructuredSelection().getFirstElement();
}
});
//
return combo;
return comboViewer;
}

private boolean getValueAsBoolean() {
Expand Down

0 comments on commit fdf1929

Please sign in to comment.