@Override default Optional<TemporalType> getTemporalType() { return Optional.ofNullable( getConfiguration().getTemporalType().orElse(TemporalType.getTemporalType(getType()).orElse(null))); }
@Override public String toString() { final StringBuilder sb = new StringBuilder(); sb.append("PropertyBox - PROPERTIES: "); sb.append(getPropertySet().stream().map( p -> "[\"" + p.getName() + "\":" + ((p.getType() != null) ? p.getType().getName() : "NOTYPE") + "]") .collect(Collectors.joining(","))); sb.append(" - VALUES: "); String values = propertyValues.entrySet().stream().filter(e -> e.getValue() != null) .map(e -> "(\"" + e.getKey().getName() + "\"=" + e.getValue() + ")").collect(Collectors.joining(",")); if (values == null || values.trim().equals("")) { sb.append("<EMPTY>"); } else { sb.append(values); } return sb.toString(); }
/** * Get whether the property is read-only. * @return <code>true</code> if the property is read-only */ public boolean isReadOnly() { return property.isReadOnly() || readOnly; }
@Override protected Optional<Localizable> getDefaultColumnHeader(Property<?> property) { if (property.getMessage() != null || property.getMessageCode() != null) { return Optional.of(Localizable.builder() .message((property.getMessage() != null) ? property.getMessage() : property.getName()) .messageCode(property.getMessageCode()).build()); } if (Path.class.isAssignableFrom(property.getClass()) && property.getName() != null) { return Optional.of(Localizable.of(property.getName())); } return Optional.empty(); }
/** * Checks if the type of given {@link Property} is admitted as document identifier value type. Admitted types are: * {@link String}, {@link BigInteger} and {@link ObjectId}. * @param property Property to check * @return <code>true</code> if given type is admitted as document identifier type, <code>false</code> otherwise */ @SuppressWarnings("rawtypes") private static boolean isValidDocumentIdPropertyType(Property<?> property) { final Class<?> type = property.getConverter().map(c -> (Class) c.getModelType()).orElse(property.getType()); return isAdmittedDocumentIdType(type); }
@Override protected Class<?> getPropertyType(Property<?> property) { return property.getType(); }
/** * Bind a {@link PropertyRenderer} to the given property configuration value. The renderer will be provided when the * property has the given <code>configurationProperty</code> and its value equals to given <code>value</code>. * @param <R> Rendering type * @param <T> Property base type * @param <C> Configuration property type * @param configurationProperty The configuration property to check (not null) * @param value The configuration property value to check (may be null) * @param renderer The PropertyRenderer to register (not null) */ default <R, T, C> void forPropertyConfiguration(ConfigProperty<C> configurationProperty, C value, PropertyRenderer<R, T> renderer) { ObjectUtils.argumentNotNull(configurationProperty, "Configuration property must be not null"); register(p -> p.getConfiguration().getParameter(configurationProperty).map(v -> Objects.equals(v, value)) .orElse(Boolean.FALSE), renderer); }
/** * Render the property as a numeric type {@link Input}. * @param property Property to render * @return The {@link Input} instance */ @SuppressWarnings("unchecked") protected Input<T> renderNumber(Property<? extends T> property) { // numeric type final Class<? extends Number> type = (Class<? extends Number>) property.getType(); // configuration int decimals = property.getConfiguration().getParameter(StringValuePresenter.DECIMAL_POSITIONS).orElse(-1); // build Input return (Input<T>) Input.number(type).label(property).readOnly(property.isReadOnly()).maxDecimals(decimals) .build(); }
/** * Constructor with function argument. * @param argument Function argument (not null) * @param resultType Function result type (not null) */ @SuppressWarnings("unchecked") public AbstractPropertyQueryFunction(TypedExpression<? extends A> argument, Class<? extends T> resultType) { super(argument); ObjectUtils.argumentNotNull(resultType, "Function result type must be not null"); this.resultType = resultType; if (argument instanceof Property) { final Property<?> property = (Property<?>) argument; this.configuration = PropertyConfiguration.clone(property.getConfiguration()); if (getType() == property.getType() && property.getConverter().isPresent()) { converter = (PropertyValueConverter<T, ?>) property.getConverter().get(); } } else { this.configuration = PropertyConfiguration.create(); } }
@SuppressWarnings("unchecked") @Override protected Optional<ValueProvider<?, ?>> getDefaultPropertyPresenter(Property property) { if (property != null) { if (Component.class.isAssignableFrom(property.getType())) { return Optional.empty(); } if (FontIcon.class.isAssignableFrom(property.getType())) { return Optional.of(v -> ((FontIcon) v).getHtml()); } return Optional.of(v -> property.present(v)); } return super.getDefaultPropertyPresenter(property); }
Property<?> property, String name) { if (TypeUtils.isDate(property.getType()) && schema instanceof AbstractProperty) { property.getTemporalType().ifPresent(tt -> { switch (tt) { case DATE: if (property.isReadOnly()) { schema.setReadOnly(Boolean.TRUE); property.getValidators().forEach(v -> { if (v instanceof BuiltinValidator) { ((BuiltinValidator<?>) v).getDescriptor().ifPresent(d -> {
@SuppressWarnings("unchecked") public <P extends Property<?>> DefaultTablePropertyListingBuilder(Iterable<P> properties) { super(new DefaultPropertyListing(RenderingMode.TABLE)); this.properties = (Iterable<Property<?>>) properties; // default adapter dataSourceBuilder.itemAdapter(new PropertyBoxItemAdapter()); // setup datasource properties.forEach(p -> { dataSourceBuilder.withProperty(p, p.getType()); if (p.isReadOnly()) { dataSourceBuilder.readOnly(p, true); } if (Path.class.isAssignableFrom(p.getClass())) { dataSourceBuilder.sortable(p, true); } }); }
private String generatePropertyName(Property<?> property) { String propertyName = property.getName(); if (propertyName == null) { propertyName = "property"; } // check duplicates Integer count = generatedPropertyIds.get(propertyName); if (count != null && count > 0) { int sequence = count.intValue() + 1; generatedPropertyIds.put(propertyName, sequence); return propertyName + sequence; } else { generatedPropertyIds.put(propertyName, 1); return propertyName; } }
/** * Render the property as a {@link Date} type {@link Input}. * @param property Property to render * @return The {@link Input} instance */ protected Input<Date> renderDate(Property<? extends T> property) { final TemporalType type = property.getConfiguration().getTemporalType().orElse(TemporalType.DATE); switch (type) { case TIME: return Input.from(Input.localTime().label(property).readOnly(property.isReadOnly()).build(), new DateToLocalTimeConverter()); case DATE_TIME: return Input.dateTime().label(property).readOnly(property.isReadOnly()).build(); case DATE: default: return Input.date().label(property).readOnly(property.isReadOnly()).build(); } }
/** * Try to obtain a {@link ValidatableInput} component to handle the value of given <code>property</code>. * <p> * The current {@link PropertyRendererRegistry} is used to look for a suitable {@link PropertyRenderer} to render * the {@link ValidatableInput} using the provided {@link Property}. * </p> * @param <T> Property type * @param property The property for which to obtain the {@link ValidatableInput} (not null) * @return Optional property {@link ValidatableInput} component * @see PropertyRendererRegistry#get() */ @SuppressWarnings("unchecked") static <T> Optional<ValidatableInput<T>> forProperty(Property<T> property) { return property.renderIfAvailable(ValidatableInput.class).map(input -> input); }
@SuppressWarnings("unchecked") @Override public ValidatableInput render(Property<? extends T> property) { ObjectUtils.argumentNotNull(property, "Property must be not null"); // render as Input and convert to ValidatableInput return property.renderIfAvailable(Input.class).map(input -> (Input<T>) input) .map(input -> ValidatableInput.from(input)).map(input -> { // property validators ((Property<T>) property).getValidators().forEach(validator -> input.addValidator(validator)); return input; }).orElse(null); }
@Override public String convertToPresentation(T value, Class<? extends String> targetType, Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException { return getProperty().present(value); }
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override protected Collection<Validator<Object>> getDefaultPropertyValidators(Property<?> property) { return ((Property) property).getValidators(); }
/** * Get the property/column type of given property id. * @param property Property id * @return property/column type which corresponds to given property id */ protected Class<?> getPropertyColumnType(P property) { if (property != null) { if (Property.class.isAssignableFrom(property.getClass())) { return ((Property<?>) property).getType(); } } return Object.class; }
/** * Bind a {@link PropertyValuePresenter} to the given property configuration value. The presenter will be provided * when the property has the given <code>configurationProperty</code> and its value equals to given * <code>value</code>. * @param <T> Property base type * @param <C> Configuration property type * @param configurationProperty The configuration property to check (not null) * @param value The configuration property value to check (may be null) * @param presenter The PropertyPresenter to register (not null) */ default <T, C> void forPropertyConfiguration(ConfigProperty<C> configurationProperty, C value, PropertyValuePresenter<? super T> presenter) { ObjectUtils.argumentNotNull(configurationProperty, "Configuration property must be not null"); register(p -> p.getConfiguration().getParameter(configurationProperty).map(v -> Objects.equals(v, value)) .orElse(Boolean.FALSE), presenter); }