/** * Default constructor. * * @param groupedProperty * {@link GroupedProperty} to display. * @see PropertyPreferencePage#PropertyPreferencePage(String, java.util.Collection) */ public GroupedPropertyPreferencePage(GroupedProperty groupedProperty) { super(groupedProperty.getName(), groupedProperty.getSingleProperties()); this.setDescription(groupedProperty.getDescription()); this.groupedProperty = groupedProperty; }
/** * Returns property defined by {@link #property} from the grouped property. If for some reason * property can not be found, {@link PropertyValidation} will be filled with error(s) and * <code>null</code> returned. * * @param groupProperty * {@link GroupedProperty} to search in. * @param propertyValidation * {@link PropertyValidation} to report errors. * @return {@link SingleProperty} or <code>null</code> if finding fails. */ private SingleProperty<?> getProperty(GroupedProperty groupProperty, PropertyValidation propertyValidation) { if (StringUtils.isEmpty(property)) { ValidationError validationError = new ValidationError(new ArrayList<>(groupProperty.getSingleProperties()), "Validation of grouped property " + groupProperty.getName() + " failed because property logical name is not set."); propertyValidation.addValidationError(validationError); return null; } SingleProperty<?> p = groupProperty.forLogicalname(property); if (null == p) { ValidationError validationError = new ValidationError(new ArrayList<>(groupProperty.getSingleProperties()), "Validation of grouped property " + groupProperty.getName() + " failed because property with logical name '" + property + "' does not exist."); propertyValidation.addValidationError(validationError); } return p; }
/** * Returns property defined by {@link #this} from the grouped property. If for some reason * property can not be found, {@link PropertyValidation} will be filled with error(s) and * <code>null</code> returned. * * @param groupProperty * {@link GroupedProperty} to search in. * @param propertyValidation * {@link PropertyValidation} to report errors. * @return {@link SingleProperty} or <code>null</code> if finding fails. */ private SingleProperty<?> getAgainstProperty(GroupedProperty groupProperty, PropertyValidation propertyValidation) { if (StringUtils.isEmpty(than)) { ValidationError validationError = new ValidationError(new ArrayList<>(groupProperty.getSingleProperties()), "Validation of grouped property " + groupProperty.getName() + " failed because logical name of the property to compare against is not set."); propertyValidation.addValidationError(validationError); return null; } SingleProperty<?> p = groupProperty.forLogicalname(than); if (null == p) { ValidationError validationError = new ValidationError(new ArrayList<>(groupProperty.getSingleProperties()), "Validation of grouped property " + groupProperty.getName() + " failed because property with logical name '" + than + "' does not exist."); propertyValidation.addValidationError(validationError); } return p; }
/** * {@inheritDoc} */ @Override @SuppressWarnings("unchecked") public void validate(GroupedProperty groupProperty, PropertyValidation propertyValidation) { SingleProperty<?> compare = getProperty(groupProperty, propertyValidation); SingleProperty<?> against = getAgainstProperty(groupProperty, propertyValidation); if ((null == compare) || (null == against)) { return; } try { compare((SingleProperty<T>) compare, (SingleProperty<T>) against, (T) compare.getValue(), (T) against.getValue(), propertyValidation); } catch (Exception e) { ValidationError validationError = new ValidationError(new ArrayList<>(groupProperty.getSingleProperties()), "Validation of grouped property " + groupProperty.getName() + " failed because exception occurred during validation. Exception message: " + e.getMessage()); propertyValidation.addValidationError(validationError); } }
compare((SingleProperty<T>) compareProperty, (SingleProperty<T>) againstProperty, value, against, propertyValidation); } catch (Exception e) { ValidationError validationError = new ValidationError(new ArrayList<>(groupProperty.getSingleProperties()), "Validation of grouped property " + groupProperty.getName() + " failed because exception occurred during validation. Exception message: " + e.getMessage()); propertyValidation.addValidationError(validationError);