Package com.vaadin.data.validator

Examples of com.vaadin.data.validator.AbstractValidator


       field.setResolution(fieldMinResolution ? DateField.RESOLUTION_MIN : DateField.RESOLUTION_DAY);
       if (hasText(dwe.getNotAfter())) {
           try {
               boolean usesCurrent = XmlConstants.DATE_CURRENT.equalsIgnoreCase(dwe.getNotAfter());
               final Date notAfter = (usesCurrent) ? sdf.parse(sdf.format(new Date())) : sdf.parse(dwe.getNotAfter());
               field.addValidator(new AbstractValidator(getMessage("processdata.block.error.date.notafter").replaceFirst("%s", dwe.getNotAfter())) {
          @Override
          public boolean isValid(Object value) {
            Date formatedDateFromCalendarInput = formatTimeFromCalendarInput((Date)value,sdf);
            return value == null ||  isBeforeCurrentDate(formatedDateFromCalendarInput);
          }
          private boolean isBeforeCurrentDate(Date formatedDateFromCalendarInput){

            return  isRightSideOpen()?  isBeforeCurrentDateRightSideOpen(formatedDateFromCalendarInput):isBeforeCurrentDateRightSideClosed(formatedDateFromCalendarInput);

            }

            private boolean isRightSideOpen(){
            if(dwe.getDiscludeNotAfter()==null){
              return false;
            }
            else{
              return dwe.getDiscludeNotAfter();
            }
          }


            private boolean isBeforeCurrentDateRightSideClosed(Date formatedDateFromCalendarInput){

              return notAfter.equals(formatedDateFromCalendarInput)? true : isNotAfter(formatedDateFromCalendarInput);
            }

            private boolean isBeforeCurrentDateRightSideOpen(Date formatedDateFromCalendarInput){
             
              return   notAfter.equals(formatedDateFromCalendarInput)? false : isNotAfter(formatedDateFromCalendarInput);
            }
           
            private boolean isNotAfter(Date formatedDateFromCalendarInput){
              return   !notAfter.before(formatedDateFromCalendarInput);
             
            }
        });
               //why notify and interrupt?
               //we already have a perfect validation mechanisms
               //so let's use classic validators
//               field.addListener(new ValueChangeListener() {
//                   @Override
//                   public void valueChange(ValueChangeEvent event) {
//                       Object value = event.getProperty().getValue();
//                       if (value != null && value instanceof Date) {
//                           if (notAfter.before((Date) value)) {
////                               TODO: TODO: notification fails on preview, because application object is only a stub
//                               VaadinUtility.validationNotification(getApplication(), i18NSource,
//                                       getMessage("processdata.block.error.date.notafter").replaceFirst("%s", dwe.getNotAfter()));
//                               field.setValue(notAfter);
//                           }
//                       }
//                   }
//               });
           } catch (ParseException e) {
               handleException(getMessage("processdata.block.error.unparsable.date").replaceFirst("%s", dwe.getNotAfter()), e);
           }
       }
       if (hasText(dwe.getNotBefore())) {
           try {
               boolean usesCurrent = XmlConstants.DATE_CURRENT.equalsIgnoreCase(dwe.getNotBefore());
               final Date notBefore = (usesCurrent) ? sdf.parse(sdf.format(new Date())) : sdf.parse(dwe.getNotBefore());
               field.addValidator(new AbstractValidator(getMessage("processdata.block.error.date.notbefore").replaceFirst("%s", dwe.getNotBefore())) {
          @Override
          public boolean isValid(Object value) {
            Date formatedDateFromCalendarInput = formatTimeFromCalendarInput((Date)value,sdf);
            return value == null || isAfterCurrentDate(formatedDateFromCalendarInput);
          }
View Full Code Here

TOP

Related Classes of com.vaadin.data.validator.AbstractValidator

Copyright © 2018 www.massapicom. 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.