当前位置: 首页>>代码示例>>Java>>正文


Java Validator类代码示例

本文整理汇总了Java中org.controlsfx.validation.Validator的典型用法代码示例。如果您正苦于以下问题:Java Validator类的具体用法?Java Validator怎么用?Java Validator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Validator类属于org.controlsfx.validation包,在下文中一共展示了Validator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: showLineJumpDialog

import org.controlsfx.validation.Validator; //导入依赖的package包/类
private void showLineJumpDialog() {
  TextInputDialog dialog = new TextInputDialog();
  dialog.setTitle("Goto Line");
  dialog.getDialogPane().setContentText("Input Line Number: ");
  dialog.initOwner(area.getValue().getScene().getWindow());
  TextField tf = dialog.getEditor();

  int lines = StringUtil.countLine(area.getValue().getText());
  ValidationSupport vs = new ValidationSupport();
  vs.registerValidator(tf, Validator.<String> createPredicateValidator(
      s -> TaskUtil.uncatch(() -> MathUtil.inRange(Integer.valueOf(s), 1, lines)) == Boolean.TRUE,
      String.format("Line number must be in [%d,%d]", 1, lines)));

  dialog.showAndWait().ifPresent(s -> {
    if (vs.isInvalid() == false) {
      area.getValue().moveTo(Integer.valueOf(s) - 1, 0);
    }
  });
}
 
开发者ID:XDean,项目名称:CSS-Editor-FX,代码行数:20,代码来源:StatusBarManager.java

示例2: recreateValidationSupport

import org.controlsfx.validation.Validator; //导入依赖的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);
}
 
开发者ID:ubershy,项目名称:StreamSis,代码行数:26,代码来源:CommonElementFieldsController.java

示例3: setValidationSupport

import org.controlsfx.validation.Validator; //导入依赖的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);
}
 
开发者ID:ubershy,项目名称:StreamSis,代码行数:18,代码来源:SwitchSisSceneActionController.java

示例4: setValidationSupport

import org.controlsfx.validation.Validator; //导入依赖的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);
}
 
开发者ID:ubershy,项目名称:StreamSis,代码行数:24,代码来源:SoundActionController.java

示例5: setValidationSupport

import org.controlsfx.validation.Validator; //导入依赖的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);
}
 
开发者ID:ubershy,项目名称:StreamSis,代码行数:25,代码来源:LogicalCheckerController.java

示例6: registerValidators

import org.controlsfx.validation.Validator; //导入依赖的package包/类
private void registerValidators() {
    vd.registerValidator(emne, Validator.createEmptyValidator("Tittel mangler", Severity.WARNING));
    vd.registerValidator(datePicker, Validator.createEmptyValidator("Dato mangler", Severity.WARNING));
    vd.registerValidator(capacityField, Validator.createRegexValidator("Kapasiteten må være et tall", "[0-9]*",
            Severity.ERROR));

    vd.registerValidator(toTimeField,
            Validator.combine(
                    Validator.createEmptyValidator("Sluttidspunkt mangler", Severity.WARNING),
                    Validator.createRegexValidator("Tid må være på formen hh:mm",
                            "^$|([0-1]?[0-9]|2[0-3]):[0-5][0-9]", Severity.ERROR),
                    Validator.createPredicateValidator(o -> isTimeValid(),
                            "Sluttidspunkt må være etter starttidspunkt", Severity.ERROR)));


    vd.registerValidator(fromTimeField,
            Validator.combine(
                    Validator.createEmptyValidator("Starttidspunkt mangler", Severity.WARNING),
                    Validator.createRegexValidator("Tid må være på formen hh:mm",
                            "^$|([0-1]?[0-9]|2[0-3]):[0-5][0-9]", Severity.ERROR)));

    vd.setValidationDecorator(new ValidationDecoration());
}
 
开发者ID:Fellesprosjekt-27,项目名称:fellesprosjekt,代码行数:24,代码来源:CreateEventController.java

示例7: createBooleanFormatValidator

import org.controlsfx.validation.Validator; //导入依赖的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);
    };
}
 
开发者ID:aftenkap,项目名称:jutility-javafx,代码行数:30,代码来源:ValidationUtils.java

示例8: createURIFormatValidator

import org.controlsfx.validation.Validator; //导入依赖的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);
    };
}
 
开发者ID:aftenkap,项目名称:jutility-javafx,代码行数:37,代码来源:ValidationUtils.java

示例9: AllwaysWrongValidator

import org.controlsfx.validation.Validator; //导入依赖的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;	
}
 
开发者ID:drivenbyentropy,项目名称:aptasuite,代码行数:19,代码来源:ControlFXValidatorFactory.java

示例10: init

import org.controlsfx.validation.Validator; //导入依赖的package包/类
@PostConstruct
public void init() {
	
    getBackButton().setDisable(true);

    // Fill the combobox
    //fileFormatComboBox.getItems().add("FASTA");
    fileFormatComboBox.getItems().add("FASTQ");
    fileFormatComboBox.getItems().add("RAW");
    
    // Bind the corresponding input fields to the DataModel associated with the wizard
    newExperimentName.textProperty().bindBidirectional(getDataModel().getExperimentName());
    newExperimentDescription.textProperty().bindBidirectional(getDataModel().getExperimentDescription());

    newExperimentIsDemultiplexed.selectedProperty().bindBidirectional(getDataModel().getIsDemultiplexed());
   	demultiplexedToggleGroup.selectToggle(getDataModel().getIsDemultiplexed().get() ? newExperimentIsDemultiplexed : newExperimentIsNotDemultiplexed);

    newExperimentIsPairedEnd.selectedProperty().bindBidirectional(getDataModel().getIsPairedEnd());
    pairedEndToggleGroup.selectToggle(getDataModel().getIsPairedEnd().get() ? newExperimentIsPairedEnd : newExperimentIsSingleEnd);
    projectPathTextField.textProperty().bindBidirectional(getDataModel().getProjectPath());
    
    this.fileFormatComboBox.valueProperty().bindBidirectional(getDataModel().getFileFormat());
    
    // Define the validation properties for the different fields
    validationSupport.registerValidator(newExperimentName, Validator.createEmptyValidator("The experiment name cannot be empty"));
    validationSupport.registerValidator(newExperimentDescription, Validator.createEmptyValidator("The experiment description cannot be empty"));
    validationSupport.registerValidator(projectPathTextField, Validator.createEmptyValidator("You must specify the base location for this experiment"));
    
    
    // Bind the validator to the next button so that it is only available if all fields have been filled
    nextButton.disableProperty().bind(validationSupport.invalidProperty()); 
    
    // Give the user the opportunity to configure advanced options related to the parser and database
    // For this, we temporarly highjack the Finish Button
    this.finishButton.setText("Advanced Options");
    
}
 
开发者ID:drivenbyentropy,项目名称:aptasuite,代码行数:38,代码来源:WizardStartController.java

示例11: addValidator

import org.controlsfx.validation.Validator; //导入依赖的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);

  }
}
 
开发者ID:mzmine,项目名称:mzmine3,代码行数:39,代码来源:ParameterEditorFactory.java

示例12: initialize

import org.controlsfx.validation.Validator; //导入依赖的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();
        }
    });
}
 
开发者ID:manami-project,项目名称:manami,代码行数:45,代码来源:NewEntryController.java

示例13: createFakeAlwaysSuccessfulValidator

import org.controlsfx.validation.Validator; //导入依赖的package包/类
/**
 * Create fake {@link Validator} that returns always successful result. Such Validator can be
 * used to substitute some normal Validator to disable validation for {@link Control}, because
 * currently the validation library doesn't support unregistering Validators from Controls.
 */
public static Validator<?> createFakeAlwaysSuccessfulValidator() {
	Validator<?> fakeValidator = (c, newValue) -> {
		return fakeSuccessfulValidationResult(c);
	};
	return fakeValidator;
}
 
开发者ID:ubershy,项目名称:StreamSis,代码行数:12,代码来源:GUIUtil.java

示例14: enableModifiersTextFieldValidation

import org.controlsfx.validation.Validator; //导入依赖的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);
	}
}
 
开发者ID:ubershy,项目名称:StreamSis,代码行数:14,代码来源:HotkeyRow.java

示例15: setValidationSupport

import org.controlsfx.validation.Validator; //导入依赖的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);
}
 
开发者ID:ubershy,项目名称:StreamSis,代码行数:34,代码来源:TargetImageWithActionsController.java


注:本文中的org.controlsfx.validation.Validator类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。