@Override
 public void validate(Problems problems, String compName, ListSelectionModel model) {
   if (model.isSelectionEmpty()) {
     wrapped.validate(problems, compName, new Integer[0]);
   } else {
     List<Integer> list =
         new ArrayList<Integer>(model.getMaxSelectionIndex() + 1 - model.getMinSelectionIndex());
     for (int i = model.getMinSelectionIndex(); i <= model.getMaxSelectionIndex(); ++i) {
       if (model.isSelectedIndex(i)) {
         list.add(i);
       }
     }
     wrapped.validate(problems, compName, list.toArray(new Integer[list.size()]));
   }
 }
Пример #2
0
 private boolean validate(String realName, String address, Problems problems, String compName) {
   String[] nameAndHost = address.split("@");
   if (nameAndHost.length == 1 && nameAndHost[0].contains("@")) {
     problems.add(
         NbBundle.getMessage(
             EmailAddressValidator.class, "EMAIL_MISSING_HOST", compName, nameAndHost[0]));
     return false;
   }
   if (nameAndHost.length > 2) {
     problems.add(
         NbBundle.getMessage(EmailAddressValidator.class, "EMAIL_HAS_>1_@", compName, address));
     return false;
   }
   String name = nameAndHost[0];
   if (name.length() == 0) {
     problems.add(
         NbBundle.getMessage(EmailAddressValidator.class, "EMAIL_MISSING_NAME", compName, name));
     return false;
   }
   if (name.length() > 64) {
     problems.add(
         new Problem(
             NbBundle.getMessage(
                 EmailAddressValidator.class, "ADDRESS_MAY_BE_TOO_LONG", compName, name),
             Severity.WARNING));
   }
   String host = nameAndHost.length >= 2 ? nameAndHost[1] : null;
   boolean result = host != null;
   if (result) {
     result = hv.validate(problems, compName, host);
     if (result) {
       MayNotContainSpacesValidator v = new MayNotContainSpacesValidator();
       result = v.validate(problems, compName, name);
     }
     Validator<String> v = new EncodableInCharsetValidator("US-ASCII");
     if (result) {
       result = v.validate(problems, compName, address);
     }
   } else {
     problems.add(
         NbBundle.getMessage(
             EmailAddressValidator.class, "EMAIL_MISSING_HOST", compName, nameAndHost[0]));
   }
   return result;
 }