本文整理汇总了Java中org.controlsfx.validation.ValidationResult类的典型用法代码示例。如果您正苦于以下问题:Java ValidationResult类的具体用法?Java ValidationResult怎么用?Java ValidationResult使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ValidationResult类属于org.controlsfx.validation包,在下文中一共展示了ValidationResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: recreateValidationSupport
import org.controlsfx.validation.ValidationResult; //导入依赖的package包/类
/**
* Recreates {@link #validationSupport}, so the old validationSupport which is bound to unwanted
* fields can be garbage collected.
*/
private void recreateValidationSupport() {
validationSupport = new ValidationSupport();
CuteGraphicValidationDecoration cuteGVD = new CuteGraphicValidationDecoration(
validationSupport);
CompoundValidationDecoration validationDecor = new CompoundValidationDecoration(
// These styles are located in /StreamSis/src/main/resources/css/validation.css
new StyleClassValidationDecoration("cuteerror", "cutewarning"), cuteGVD);
validationSupport.setValidationDecorator(validationDecor);
Validator<String> nameTextFieldValidator = (c, newValue) -> {
ValidationResult alreadyExistanceResult = ValidationResult.fromErrorIf(c,
"The name is already taken. Please choose another one",
validateNameAlreadyExistence(c, newValue));
ValidationResult emptyResult = ValidationResult.fromErrorIf(c,
"Please choose a name for the element", !allowEmptyName && newValue.equals(""));
ValidationResult finalResult = ValidationResult.fromResults(emptyResult,
alreadyExistanceResult);
buttonStateManager.reportNewValueOfControl(originalName, newValue, c, finalResult);
return finalResult;
};
validationSupport.registerValidator(nameTextField, nameTextFieldValidator);
}
示例2: setValidationSupport
import org.controlsfx.validation.ValidationResult; //导入依赖的package包/类
@Override
public void setValidationSupport(ValidationSupport validationSupport) {
this.validationSupport = validationSupport;
Validator<String> ssNameTextFieldValidator = (c, newValue) -> {
boolean sisExist = ProjectManager.getProject().getSisSceneByName(newValue)!= null;
ValidationResult emptyResult = ValidationResult.fromErrorIf(c,
"Please specify existing SisScene name", newValue.isEmpty());
ValidationResult unexistingSisScene = ValidationResult.fromErrorIf(c,
"SisScene with such name does not exist", !sisExist);
ValidationResult finalResult = ValidationResult.fromResults(emptyResult,
unexistingSisScene);
buttonStateManager.reportNewValueOfControl(origSssAction.getSisSceneName(),
newValue, c, finalResult);
return finalResult;
};
this.validationSupport.registerValidator(ssNameTextField, ssNameTextFieldValidator);
}
示例3: setValidationSupport
import org.controlsfx.validation.ValidationResult; //导入依赖的package包/类
@Override
public void setValidationSupport(ValidationSupport validationSupport) {
this.validationSupport = validationSupport;
Validator<String> soundFileTextFieldValidator = (c, newValue) -> {
boolean extensionsValidationPassed = true;
if (!newValue.isEmpty()) {
extensionsValidationPassed = Util.checkFileExtension(newValue, allowedExtensions);
}
ValidationResult emptyResult = ValidationResult.fromErrorIf(c,
"Please select a path to sound file", newValue.isEmpty());
ValidationResult badExtensionResult = ValidationResult.fromErrorIf(c,
"The selected sound file has wrong extension", !extensionsValidationPassed);
ValidationResult existingPathResult = ValidationResult.fromErrorIf(c,
"Sound file is not found on this path",
!Util.checkIfPathIsAbsoluteAndFileExists(newValue));
ValidationResult finalResult = ValidationResult.fromResults(emptyResult,
existingPathResult, badExtensionResult);
buttonStateManager.reportNewValueOfControl(origSoundAction.getSoundPath(),
newValue, c, finalResult);
return finalResult;
};
this.validationSupport.registerValidator(soundFileTextField, soundFileTextFieldValidator);
}
示例4: setValidationSupport
import org.controlsfx.validation.ValidationResult; //导入依赖的package包/类
@Override
public void setValidationSupport(ValidationSupport validationSupport) {
this.validationSupport = validationSupport;
Validator<Toggle> operationValidator = (c, newValue) -> {
String whyBad = null;
if (newValue != null) {
String nameOfOperator = ((ToggleButton) newValue).getText();
BooleanOperator operator = BooleanOperator.valueOf(nameOfOperator);
if (logicalChecker != null) {
// Internally the result will depend on amount of children.
whyBad = logicalChecker
.whyOperatorCantBeAppliedToCurrentAmountOfCheckers(operator);
}
}
ValidationResult wrongResult = ValidationResult.fromErrorIf(c,
whyBad, whyBad != null);
if (newValue != null) {
ToggleButton origTB = mapWithButtons.get(origLogicalChecker.getOperator().name());
buttonStateManager.reportNewValueOfControl(origTB, newValue, c, wrongResult);
}
return wrongResult;
};
this.validationSupport.registerValidator(segmentedButton, operationValidator);
}
示例5: createBooleanFormatValidator
import org.controlsfx.validation.ValidationResult; //导入依赖的package包/类
/**
* Factory method to create a {@link Validator} which checks whether the
* string representation of a value represents a valid boolean.
*
* @param <T>
* the type of the {@link Validator}.
*
* @param message
* text of a message to be created if value is invalid
* @param severity
* severity of a message to be created if value is invalid
* @return new {@link Validator}
*/
public static <T> Validator<T> createBooleanFormatValidator(
final String message, final Severity severity) {
return (control, value) -> {
boolean invalidValue = value == null;
if (!invalidValue) {
invalidValue = !"true".equalsIgnoreCase(value.toString())
&& !"false".equalsIgnoreCase(value.toString());
}
return ValidationResult.fromMessageIf(control, message, severity,
invalidValue);
};
}
示例6: createURIFormatValidator
import org.controlsfx.validation.ValidationResult; //导入依赖的package包/类
/**
* Factory method to create a {@link Validator} which checks if the string
* representation of a value represents a valid URI.
*
* @param <T>
* the type of the {@link Validator}.
*
* @param message
* text of a message to be created if value is invalid.
* @param severity
* severity of a message to be created if value is invalid.
* @return new {@link Validator}.
*/
public static <T> Validator<T> createURIFormatValidator(
final String message, final Severity severity) {
return (control, value) -> {
boolean condition = value == null;
if (!condition) {
try {
URI.create(value.toString());
}
catch (Exception e) {
condition = true;
}
}
return ValidationResult.fromMessageIf(control, message, severity,
condition);
};
}
示例7: ValidationSupport
import org.controlsfx.validation.ValidationResult; //导入依赖的package包/类
/**
* Creates validation support instance
*/
public ValidationSupport() {
this.validationResultProperty()
.addListener((o, oldValue, validationResult) -> {
this.invalidProperty.set(!validationResult.getErrors()
.isEmpty());
this.redecorate();
});
// notify validation result observers
this.validationResults.addListener(
(final MapChangeListener.Change<? extends Control, ? extends
ValidationResult> change) -> this
.validationResultProperty.set(
ValidationResult.fromResults(
this.validationResults.values())));
}
示例8: apply
import org.controlsfx.validation.ValidationResult; //导入依赖的package包/类
@Override
public ValidationResult apply(Control control, String value) {
if (value.isEmpty() && emptyAllowed)
return null;
try {
int number = valueOf(value);
return fromErrorIf(control, message, (number < minValue) || (number > maxValue));
} catch (NumberFormatException e) {
return fromError(control, message);
}
}
示例9: apply
import org.controlsfx.validation.ValidationResult; //导入依赖的package包/类
@Override
public ValidationResult apply(Control control, String value) {
if (value.isEmpty() && emptyAllowed)
return null;
try {
if (converter.fromString(value) == null)
return fromError(control, message);
return null;
} catch (Exception e) {
return fromError(control, message);
}
}
示例10: AllwaysWrongValidator
import org.controlsfx.validation.ValidationResult; //导入依赖的package包/类
/**
* Custom validator to ensure primers and barcodes contain either only ACGTs OR
* that the field is empty
*/
public static Validator<String> AllwaysWrongValidator(String message){
Validator<String> validator = new Validator<String>() {
@Override
public ValidationResult apply(Control control, String value) {
boolean condition = true;
return ValidationResult.fromMessageIf(control, message, Severity.ERROR, condition );
}
};
return validator;
}
示例11: addValidator
import org.controlsfx.validation.ValidationResult; //导入依赖的package包/类
@SuppressWarnings({"rawtypes", "unchecked"})
private void addValidator(ValidationSupport validationSupport, Parameter<?> p,
ParameterEditor<?> pe) {
ParameterValidator pv = p.getValidator();
if (pv == null)
return;
Control mainControl = pe.getMainControl();
if (mainControl == null)
return;
if (mainControl != null && pv != null) {
// Create the official validator
Validator<?> validator = (control, value) -> {
ValidationResult result = new ValidationResult();
Object currentVal = pe.getValue();
List<String> errors = new ArrayList<>();
if (pv.checkValue(currentVal, errors))
return result;
// IF no message was produced, add our own message
if (errors.isEmpty())
errors.add(p.getName() + " is not set properly");
// Copy the messages to the result
for (String er : errors) {
String m = p.getName() + ": " + er;
ValidationMessage msg = ValidationMessage.error(control, m);
result.add(msg);
}
return result;
};
// Register the validator
validationSupport.registerValidator(mainControl, false, validator);
}
}
示例12: initialize
import org.controlsfx.validation.ValidationResult; //导入依赖的package包/类
/**
* Called on Construction
*
* @since 2.0.0
*/
public void initialize() {
validationSupport = new ValidationSupport();
validationSupport.registerValidator(txtTitle, Validator.createEmptyValidator("Title is required"));
validationSupport.registerValidator(txtLocation, Validator.createEmptyValidator("Location is required"));
validationSupport.registerValidator(txtInfoLink, (c, value) -> {
final String str = (String) value;
if (isNotEmpty(str)) {
if (!str.startsWith("http://")) {
if (!str.startsWith("https://")) {
return ValidationResult.fromError(txtInfoLink, "Info link must be a valid URL");
}
}
}
return null;
});
txtType.setText(AnimeType.TV.getValue());
txtEpisodes.focusedProperty().addListener((currentValue, valueBefore, valueAfter) -> {
if (!NumberUtils.isParsable(txtEpisodes.getText()) || txtEpisodes.getText().startsWith("-") || "0".equals(txtEpisodes.getText())) {
txtEpisodes.setText("1");
} else {
try {
Integer.parseInt(txtEpisodes.getText());
} catch (final NumberFormatException e) {
txtEpisodes.setText("1");
}
final boolean deactivateDecreaseButton = Integer.parseInt(txtEpisodes.getText()) == 1;
btnEpisodeDown.setDisable(deactivateDecreaseButton);
}
});
txtInfoLink.focusedProperty().addListener((currentValue, valueBefore, valueAfter) -> {
if (valueBefore && !valueAfter) {
autoFillForm();
}
});
}
示例13: enableModifiersTextFieldValidation
import org.controlsfx.validation.ValidationResult; //导入依赖的package包/类
private void enableModifiersTextFieldValidation() {
if (validationSupport != null) {
Validator<String> modifiersTextFieldValidator = (c, newValue) -> {
KeyCodeCombination kcc = keyCombinationProperty.get();
// Allow empty modifiers only if KeyCodeCombination is not set.
ValidationResult emptyResult = ValidationResult.fromErrorIf(c,
"Need at least one modifier", kcc != null && newValue.isEmpty());
ValidationResult finalResult = ValidationResult.fromResults(emptyResult);
return finalResult;
};
validationSupport.registerValidator(modifiersTextField, modifiersTextFieldValidator);
}
}
示例14: setValidationSupport
import org.controlsfx.validation.ValidationResult; //导入依赖的package包/类
@Override
public void setValidationSupport(ValidationSupport validationSupport) {
this.validationSupport = validationSupport;
Validator<String> targetFieldValidator = (c, newValue) -> {
boolean extensionsValidationPassed = true;
if (!newValue.isEmpty()) {
extensionsValidationPassed = Util.checkFileExtension(newValue, allowedExtensions);
}
ValidationResult emptyResult = ValidationResult.fromErrorIf(c,
"Please select a path to Target image file", newValue.isEmpty());
ValidationResult badExtensionResult = ValidationResult.fromErrorIf(c,
"The selected target Image file has wrong extension",
!extensionsValidationPassed);
ValidationResult invalidPathResult = ValidationResult.fromErrorIf(c,
"The path seems slightly... invalid",
!Util.checkIfAbsolutePathSeemsValid(newValue));
ValidationResult validPathResult = ValidationResult.fromErrorIf(c,
"Image file is not found on this path",
!Util.checkIfPathIsAbsoluteAndFileExists(newValue));
ValidationResult finalResult = ValidationResult.fromResults(emptyResult,
invalidPathResult, badExtensionResult, validPathResult);
if (finalResult.getErrors().isEmpty()) {
updateViewBasedOnTargetImagePath(newValue);
} else {
// If there are errors, let's not show image in ImageView.
updateViewBasedOnTargetImagePath(null);
}
buttonStateManager.reportNewValueOfControl(origTiwa.getTargetImagePath(),
newValue, c, finalResult);
return finalResult;
};
this.validationSupport.registerValidator(targetTextField, targetFieldValidator);
}
示例15: setValidationSupport
import org.controlsfx.validation.ValidationResult; //导入依赖的package包/类
@Override
public void setValidationSupport(ValidationSupport validationSupport) {
this.validationSupport = validationSupport;
coordsController.setValidationSupport(validationSupport);
simController.setValidationSupport(validationSupport);
Validator<String> targetFieldValidator = (c, newValue) -> {
boolean extensionsValidationPassed = true;
if (!newValue.isEmpty()) {
extensionsValidationPassed = Util.checkFileExtension(newValue, allowedExtensions);
}
ValidationResult emptyResult = ValidationResult.fromErrorIf(c,
"Please select a path to Target image file", newValue.isEmpty());
ValidationResult badExtensionResult = ValidationResult.fromErrorIf(c,
"The selected target Image file has wrong extension",
!extensionsValidationPassed);
ValidationResult invalidPathResult = ValidationResult.fromErrorIf(c,
"The path seems slightly... invalid",
!Util.checkIfAbsolutePathSeemsValid(newValue));
ValidationResult validPathResult = ValidationResult.fromErrorIf(c,
"Image file is not found on this path",
!Util.checkIfPathIsAbsoluteAndFileExists(newValue));
ValidationResult finalResult = ValidationResult.fromResults(emptyResult,
invalidPathResult, badExtensionResult, validPathResult);
if (finalResult.getErrors().isEmpty()) {
updateViewBasedOnTargetImagePath(newValue);
} else {
// If there are errors, let's not show image in ImageView.
updateViewBasedOnTargetImagePath(null);
}
buttonStateManager.reportNewValueOfControl(origRegCounter.getTargetImagePath(),
newValue, c, finalResult);
return finalResult;
};
this.validationSupport.registerValidator(targetTextField, targetFieldValidator);
}