public List<Validator> getValidators(String propertyId) { List<Validator> list = super.getValidators(propertyId); if ("email".equals(propertyId)) { list.add(new EmailValidator(getApp().getMessage("errorMessage.invalidEmail")) { @Override protected boolean isValid(String value) { return value == null || value.isEmpty() || super.isValid(value); } }); } if ("nick".equals(propertyId)) { list.add(((UsersHelper)getHelper()).getNickTakenValidator()); } return list; } };
protected Component buildAndBindCustomComponent(String propertyId) { if ("roles".equalsIgnoreCase(propertyId)) { CheckBoxGroup<Role> checkBoxGroup = new CheckBoxGroup<>(QIUtils.getCaptionFromId(propertyId)); checkBoxGroup.setItems(((ConsumersHelper)getHelper()).getRoles()); checkBoxGroup.setItemCaptionGenerator(role -> StringUtils.capitalize(role.getName())); formatField(propertyId,checkBoxGroup).bind(propertyId); return checkBoxGroup; } if ("user".equalsIgnoreCase(propertyId)) { ComboBox<User> box = createUserBox(); formatField(propertyId,box).bind(propertyId); box.setEnabled(false); box.setValue(this.selectedUser); return box; } if ("startdate".equalsIgnoreCase(propertyId) || "endDate".equalsIgnoreCase(propertyId)) { return getFieldFactory().buildAndBindDateField(propertyId); } return null; }
@Override protected Component buildAndBindCustomComponent(String propertyId) { if ("created".equalsIgnoreCase(propertyId)){ return getFieldFactory().buildAndBindDateField(propertyId); } if ("expiration".equalsIgnoreCase(propertyId)){ return getFieldFactory().buildAndBindDateField(propertyId); } if ("parent".equalsIgnoreCase(propertyId)) { ComboBox<Account> parentCombo = new ComboBox<>(getCaptionFromId(propertyId)); parentCombo.setDataProvider(((AccountsHelper)getHelper()).getParentDataProvider()); parentCombo.setItemCaptionGenerator(parent -> parent.getCode() + " - " + parent.getDescription()); formatField(propertyId,parentCombo).bind(propertyId); return parentCombo; } if ("type".equalsIgnoreCase(propertyId)) { ComboBox<Integer> typeCombo = new ComboBox<>(getCaptionFromId(propertyId)); typeCombo.setItems(Account.CHART,Account.DEBIT,Account.CREDIT); typeCombo.setItemCaptionGenerator(type -> getApp().getMessage("account." + type).toUpperCase()); formatField(propertyId,typeCombo).bind(propertyId); return typeCombo; } if ("entries".equalsIgnoreCase(propertyId)) { //todo: should bind? return createEntriesPanel(); } return null; }
@Override protected Component buildAndBindCustomComponent(String propertyId) { List<Validator> validators = getFieldFactory().getValidators(propertyId); if ("permissions".equals(propertyId)) { CheckBoxGroup<Permission> f = new CheckBoxGroup("Permissions"); List<SysConfig> sysconfigs = ((RolesHelper)getHelper()).getPermissions(); List<Permission> allPermissions = new ArrayList<>(); //convert SysConfigs to Permissions for (SysConfig sys : sysconfigs) { Permission p = Permission.valueOf(sys.getId().substring(5)); allPermissions.add(p); } f.setItems(allPermissions); f.setItemCaptionGenerator((ItemCaptionGenerator<Permission>) item -> sysconfigs.get(allPermissions.indexOf(item)).getId().substring(5) + " : " + //remove "perm." prefix sysconfigs.get(allPermissions.indexOf(item)).getValue()); Binder.BindingBuilder builder = getBinder().forField(f); validators.forEach(builder::withValidator); builder.bind(propertyId); return f; } return null; }
return getFieldFactory().buildAndBindDateField(propertyId);
@Override public List<Validator> getValidators(String propertyId) { List<Validator> validators = super.getValidators(propertyId); if ("currencyCode".equalsIgnoreCase(propertyId)) { Validator<String> currencyCodeValidator = (Validator<String>) (value, context) -> { Account parentAccount = getInstance().getParent(); if (parentAccount != null && parentAccount.getCurrencyCode() != null && !parentAccount.getCurrencyCode().equals(value)) { return ValidationResult.error(getApp().getMessage("errorMessage.currencyCodeMismatch")); } return ValidationResult.ok(); }; validators.add(currencyCodeValidator); } return validators; } };
protected Component buildAndBindCustomComponent(String propertyId) { if ("roles".equals(propertyId)) { CheckBoxGroup g = new CheckBoxGroup(StringUtils.capitalize(getCaptionFromId(propertyId))); g.setItems(((UsersHelper)getHelper()).getRoles()); g.setItemCaptionGenerator((ItemCaptionGenerator<Role>) item -> StringUtils.capitalize(item.getName())); List<Validator> v = getFieldFactory().getValidators(propertyId); Binder.BindingBuilder builder = getBinder().forField(g); for (Validator val : v) { builder.withValidator(val); } builder.bind(propertyId); return g; } return null; }
@Override protected Component buildAndBindCustomComponent(String propertyId) { if ("id".equals(propertyId)) { TextField id = new TextField(getCaptionFromId(propertyId)); List<Validator> validators = getFieldFactory().getValidators(propertyId); Binder<SysConfig> binder = getBinder(); Binder.BindingBuilder builder = binder.forField(id) .asRequired(getApp().getMessage("errorMessage.req", StringUtils.capitalize(getCaptionFromId(propertyId)))) .withNullRepresentation("") .withConverter(userInputValue -> userInputValue , toPresentation -> removePrefix(toPresentation)); validators.forEach(builder::withValidator); builder.bind(propertyId); return id; } return null; }