Package com.dci.intellij.dbn.common.options.setting

Source Code of com.dci.intellij.dbn.common.options.setting.IntegerSettingValidator

package com.dci.intellij.dbn.common.options.setting;

import com.intellij.openapi.options.ConfigurationException;

import javax.swing.JTextField;

public class IntegerSettingValidator implements SettingValidator<IntegerSetting>{
    private String fieldName;
    private String hint;
    private int minValue;
    private int maxValue;
   
    @Override
    public void validate(IntegerSetting setting) throws ConfigurationException {
       
    }

    public static int parseIntegerInputValue(JTextField inputField, String name, int min, int max, String hint) throws ConfigurationException {
        try {
            int integer = Integer.parseInt(inputField.getText());
            if (min > integer || max < integer) throw new NumberFormatException("Number not in range");
            return integer;
        } catch (NumberFormatException e) {
            inputField.grabFocus();
            inputField.selectAll();
            String message = "Input value for \"" + name + "\" must be an integer between " + min + " and " + max + ".";
            if (hint != null) {
                message = message + " " + hint;
            }
            throw new ConfigurationException(message, "Invalid config value");
        }
    }
}
TOP

Related Classes of com.dci.intellij.dbn.common.options.setting.IntegerSettingValidator

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.