Skip to content

Commit

Permalink
Don't always complain for missing fields.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mailaender committed Oct 6, 2023
1 parent 9619b73 commit 33e3e13
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -128,7 +128,7 @@ public List<InputValue> 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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Object> {

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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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";
}
Expand Down

0 comments on commit 33e3e13

Please sign in to comment.