diff --git a/chemclipse/plugins/org.eclipse.chemclipse.support/src/org/eclipse/chemclipse/support/settings/parser/SettingsClassParser.java b/chemclipse/plugins/org.eclipse.chemclipse.support/src/org/eclipse/chemclipse/support/settings/parser/SettingsClassParser.java index 1fc3da7a4a..b1419a30e9 100644 --- a/chemclipse/plugins/org.eclipse.chemclipse.support/src/org/eclipse/chemclipse/support/settings/parser/SettingsClassParser.java +++ b/chemclipse/plugins/org.eclipse.chemclipse.support/src/org/eclipse/chemclipse/support/settings/parser/SettingsClassParser.java @@ -34,11 +34,11 @@ import org.eclipse.chemclipse.support.settings.SystemSettings; import org.eclipse.chemclipse.support.settings.SystemSettingsStrategy; import org.eclipse.chemclipse.support.settings.ValidatorSettingsProperty; +import org.eclipse.chemclipse.support.settings.validation.EmptyStringValidator; import org.eclipse.chemclipse.support.settings.validation.EvenOddValidatorByte; import org.eclipse.chemclipse.support.settings.validation.EvenOddValidatorInteger; import org.eclipse.chemclipse.support.settings.validation.EvenOddValidatorLong; import org.eclipse.chemclipse.support.settings.validation.EvenOddValidatorShort; -import org.eclipse.chemclipse.support.settings.validation.InputValidator; import org.eclipse.chemclipse.support.settings.validation.MinMaxValidator; import org.eclipse.chemclipse.support.settings.validation.RegularExpressionValidator; import org.eclipse.core.databinding.validation.IValidator; @@ -128,7 +128,7 @@ public List getInputValues() { for(Annotation annotation : annotations) { if(annotation instanceof JsonProperty jsonProperty) { if(jsonProperty.required()) { - inputValue.addValidator(new InputValidator(inputValue)); + inputValue.addValidator(new EmptyStringValidator()); } } if(annotation instanceof LabelProperty labelProperty) { diff --git a/chemclipse/plugins/org.eclipse.chemclipse.support/src/org/eclipse/chemclipse/support/settings/validation/EmptyStringValidator.java b/chemclipse/plugins/org.eclipse.chemclipse.support/src/org/eclipse/chemclipse/support/settings/validation/EmptyStringValidator.java new file mode 100644 index 0000000000..f74f5ed8ae --- /dev/null +++ b/chemclipse/plugins/org.eclipse.chemclipse.support/src/org/eclipse/chemclipse/support/settings/validation/EmptyStringValidator.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2023 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.settings.validation; + +import org.eclipse.core.databinding.validation.IValidator; +import org.eclipse.core.databinding.validation.ValidationStatus; +import org.eclipse.core.runtime.IStatus; + +public class EmptyStringValidator implements IValidator { + + private static final String ERROR = "Please enter a value."; + + public EmptyStringValidator() { + + } + + @Override + public IStatus validate(Object value) { + + if(value == null) { + return ValidationStatus.error(ERROR); + } + if(value instanceof String text && text.isEmpty()) { + return ValidationStatus.error(ERROR); + } + return ValidationStatus.ok(); + } +} diff --git a/chemclipse/plugins/org.eclipse.chemclipse.support/src/org/eclipse/chemclipse/support/settings/validation/InputValidator.java b/chemclipse/plugins/org.eclipse.chemclipse.support/src/org/eclipse/chemclipse/support/settings/validation/InputValidator.java index 577e574a98..f74f34799f 100644 --- a/chemclipse/plugins/org.eclipse.chemclipse.support/src/org/eclipse/chemclipse/support/settings/validation/InputValidator.java +++ b/chemclipse/plugins/org.eclipse.chemclipse.support/src/org/eclipse/chemclipse/support/settings/validation/InputValidator.java @@ -37,8 +37,6 @@ public IStatus validate(Object value) { String message = null; if(value == null) { message = ERROR; - } else if(value instanceof String text && text.isEmpty()) { - message = ERROR; } else { Class rawType = inputValue.getRawType(); if(rawType != null) { @@ -65,7 +63,7 @@ private String parse(Class rawType, String value) { } } else if(rawType == File.class) { FileSettingProperty property = inputValue.getFileSettingProperty(); - if(property != null && !(property.dialogType() == DialogType.SAVE_DIALOG)) { + if(property != null && property.dialogType() != DialogType.SAVE_DIALOG) { if(value != null && !value.isEmpty() && !new File(value).exists()) { return "Location does not exits, please choose a valid location"; }