Example usage for com.jgoodies.validation ValidationResult addWarning

List of usage examples for com.jgoodies.validation ValidationResult addWarning

Introduction

In this page you can find the example usage for com.jgoodies.validation ValidationResult addWarning.

Prototype

public ValidationResult addWarning(String text) 

Source Link

Document

Creates and adds a warning message to the list of validation messages using the given text.

Usage

From source file:org.epri.pt2.dnp3proxy.DNP3ProxyConfigurationPanel.java

License:Open Source License

public ValidationResult validateInput() {
    ValidationResult validationResult = new ValidationResult();

    if (Strings.isEmpty(proxyAddress.getText())) {
        validationResult.addError("The proxy address field can not be blank.");
    } else {//from  w w w.  j av  a2s .c  om
        String address = proxyAddress.getText();

        Matcher matcher = addressPattern.matcher(address);

        if (!matcher.matches()) {
            validationResult.addWarning("The proxy address field must be a valid ip address or hostname.");
        }
    }

    if (Strings.isEmpty(proxyPort.getText())) {
        validationResult.addError("The proxy port field can not be blank.");
    }

    try {
        if (Integer.parseInt(proxyPort.getText()) < 1) {
            validationResult.addError("The proxy port must be a number in the range of 1-65535.");
        }
    } catch (NumberFormatException e) {
        validationResult.addError("The proxy port must be a number in the range of 1-65535.");
    }
    /*
     * if (Strings.isEmpty(nameText.getText())) {
     * validationResult.addError("The name field can not be blank."); }
     * 
     * if (Strings.isEmpty(descText.getText())) { validationResult
     * .addInfo("Please add a description to the project."); }
     */

    return validationResult;
}

From source file:org.epri.pt2.proxy.ProxyConfigurationPanel.java

License:Open Source License

public ValidationResult validateInput() {

    /*// www .ja v a  2 s .  c o m
     * proxyConfigPanel.add(proxyEnabledLabel);
     * proxyConfigPanel.add(proxyEnabled);
     * proxyConfigPanel.add(sslEnabledLabel);
     * proxyConfigPanel.add(sslEnabled);
     * proxyConfigPanel.add(proxyAddressLabel);
     * proxyConfigPanel.add(proxyAddress);
     * proxyConfigPanel.add(proxyPortLabel);
     * proxyConfigPanel.add(proxyPort);
     */

    ValidationResult validationResult = new ValidationResult();

    if (Strings.isEmpty(proxyAddress.getText())) {
        validationResult.addError("The proxy address field can not be blank.");
    } else {
        String address = proxyAddress.getText();

        Matcher matcher = addressPattern.matcher(address);

        if (!matcher.matches()) {
            validationResult.addWarning("The proxy address field must be a valid ip address or hostname.");
        }
    }

    if (Strings.isEmpty(proxyPort.getText())) {
        validationResult.addError("The proxy port field can not be blank.");
    }

    try {
        if (Integer.parseInt(proxyPort.getText()) < 1) {
            validationResult.addError("The proxy port must be a number in the range of 1-65535.");
        }
    } catch (NumberFormatException e) {
        validationResult.addError("The proxy port must be a number in the range of 1-65535.");
    }
    /*
     * if (Strings.isEmpty(nameText.getText())) {
     * validationResult.addError("The name field can not be blank."); }
     * 
     * if (Strings.isEmpty(descText.getText())) { validationResult
     * .addInfo("Please add a description to the project."); }
     */

    return validationResult;
}