Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed optional setting fields requiring a value set #1525

Merged
merged 3 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

public abstract class AbstractChromatogramReportSettings extends AbstractProcessSettings implements IChromatogramReportSettings {

@JsonProperty(value = "Export Folder", defaultValue = "")
@JsonProperty(value = "Export Folder", defaultValue = "", required = true)
@FileSettingProperty(onlyDirectory = true)
private File exportFolder;
@JsonProperty(value = "Append", defaultValue = "false")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ protected String getDefaultFolder() {
}

/**
* Method that check if systemsettings are available, this is used in conjunction with the SystemSettings annotation but can also be called by user code
* Method that check if system settings are available, this is used in conjunction with the SystemSettings annotation but can also be called by user code
*
* @return
*/
Expand Down
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()) {
Mailaender marked this conversation as resolved.
Show resolved Hide resolved
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