Search in sources :

Example 1 with Validator

use of org.netbeans.validation.api.Validator in project gephi by gephi.

the class CreateTimeIntervalUI method buildValidationPanel.

private void buildValidationPanel() {
    validationPanel = new ValidationPanel();
    validationPanel.setInnerComponent(this);
    ValidationGroup group = validationPanel.getValidationGroup();
    group.add(dateFormatComboBox, new Validator<String>() {

        @Override
        public boolean validate(Problems prblms, String string, String t) {
            boolean valid = validateDateFormat(t);
            if (!valid) {
                prblms.add(NbBundle.getMessage(CreateTimeIntervalUI.class, "CreateTimeIntervalUI.invalid.dateformat"));
            }
            return valid;
        }
    });
    Validator<String> emptyOrNumberValidator = new Validator<String>() {

        @Override
        public boolean validate(Problems prblms, String string, String t) {
            boolean valid = validateNumberOrEmpty(t);
            if (!valid) {
                prblms.add(NbBundle.getMessage(CreateTimeIntervalUI.class, "CreateTimeIntervalUI.invalid.number"));
            }
            return valid;
        }
    };
    group.add(defaultStartNumberText, emptyOrNumberValidator);
    group.add(defaultEndNumberText, emptyOrNumberValidator);
    validationPanel.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            refreshOkButton();
        }
    });
}
Also used : Problems(org.netbeans.validation.api.Problems) ChangeEvent(javax.swing.event.ChangeEvent) ValidationGroup(org.netbeans.validation.api.ui.ValidationGroup) ChangeListener(javax.swing.event.ChangeListener) ValidationPanel(org.netbeans.validation.api.ui.ValidationPanel) Validator(org.netbeans.validation.api.Validator)

Aggregations

ChangeEvent (javax.swing.event.ChangeEvent)1 ChangeListener (javax.swing.event.ChangeListener)1 Problems (org.netbeans.validation.api.Problems)1 Validator (org.netbeans.validation.api.Validator)1 ValidationGroup (org.netbeans.validation.api.ui.ValidationGroup)1 ValidationPanel (org.netbeans.validation.api.ui.ValidationPanel)1