/** * Get whether the property is read-only. * @return <code>true</code> if the property is read-only */ public boolean isReadOnly() { return property.isReadOnly() || readOnly; }
/** * 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 boolean isReadOnlyByDefault(Property<?> property) { return property.isReadOnly(); }
@Override public Optional<Setter<PropertyBox, V>> getSetter() { if (property.isReadOnly()) { return Optional.empty(); } return Optional.of((pb, value) -> { pb.setValue(property, value); }); }
@SuppressWarnings("unchecked") @Override protected Optional<Setter<PropertyBox, ?>> getPropertyValueSetter(Property<?> property) { if (!property.isReadOnly()) { return Optional.of((item, value) -> item.setValue((Property<Object>) property, value)); } return Optional.empty(); }
/** * Get the default value for given property, if available. * @param <T> Property type * @param property The property (not null) * @return The property default value */ protected <T> T getDefaultValue(Property<T> property) { if (!property.isReadOnly()) { return configuration.get(property).getDefaultValueProvider() .map(defaultValueProvider -> defaultValueProvider.get()).orElse(null); } return null; }
@SuppressWarnings("unchecked") @Override public void refresh(boolean readOnly) { final PropertyBox value = getValue(false); propertySet.forEach(p -> { if (!readOnly || p.isReadOnly()) { refresh(p, value); } }); }
@SuppressWarnings({ "unchecked", "rawtypes" }) @Override public PropertyBox read(final PropertyBox propertyBox, final T instance, final boolean ignoreMissing) { ObjectUtils.argumentNotNull(propertyBox, "PropertyBox must be not null"); ObjectUtils.argumentNotNull(instance, "Bean instance must be not null"); propertyBox.stream().filter(p -> !p.isReadOnly()).filter(p -> Path.class.isAssignableFrom(p.getClass())) .map(p -> (Path<?>) p).forEach(p -> { getProperty(p, ignoreMissing).ifPresent( bp -> propertyBox.setValue((Property) p, read(bp, instance, (Class<Object>) p.getType()))); }); return propertyBox; }
@Override public void setReadOnly(boolean readOnly) { components.stream() .filter(b -> !b.getProperty().isReadOnly() && !configuration.get(b.getProperty()).isReadOnly()) .map(b -> b.getElement()).forEach(c -> c.setReadOnly(readOnly)); }
/** * Build and bind {@link Input}s to the properties of the property set. */ public void build() { // render and bind inputs propertySet.forEach(p -> { // exclude hidden properties PropertyConfiguration<?> configuration = _propertyConfiguration(p); if (!configuration.isHidden()) { // check whether to exclude read-only properties if (!isExcludeReadOnlyProperties() || !p.isReadOnly()) { renderAndBind(configuration); } } }); }
/** * Render the property as a {@link Boolean} type {@link Input}. * @param property Property to render * @return The {@link Input} instance */ protected Input<Boolean> renderBoolean(Property<? extends T> property) { return Input.boolean_().label(property).readOnly(property.isReadOnly()).build(); }
/** * Render the property as a {@link LocalTime} type {@link Input}. * @param property Property to render * @return The {@link Input} instance */ protected Input<LocalTime> renderLocalTime(Property<? extends T> property) { return Input.localTime().label(property).readOnly(property.isReadOnly()).build(); }
@SuppressWarnings("unchecked") @Override public Builder copyValues(PropertyBox source) { ObjectUtils.argumentNotNull(source, "Source PropertyBox must be not null"); for (Property p : source) { if (!p.isReadOnly() && this.instance.contains(p)) { this.instance.setValue(p, source.getValue(p)); } } return this; }
/** * Render the property as a {@link LocalDate} type {@link Input}. * @param property Property to render * @return The {@link Input} instance */ protected Input<LocalDate> renderLocalDate(Property<? extends T> property) { return Input.localDate().label(property).readOnly(property.isReadOnly()).build(); }
/** * Render the property as a {@link LocalDateTime} type {@link Input}. * @param property Property to render * @return The {@link Input} instance */ protected Input<LocalDateTime> renderLocalDateTime(Property<? extends T> property) { return Input.localDateTime().label(property).readOnly(property.isReadOnly()).build(); }
@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); } }); }
@SuppressWarnings("unchecked") public <P extends Property<?>> DefaultGridPropertyListingBuilder(Iterable<P> properties) { super(new DefaultPropertyListing(RenderingMode.GRID)); 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); } }); }
/** * Render the property as a {@link String} type {@link Input}. * @param property Property to render * @return The {@link Input} instance */ protected Input<String> renderString(Property<? extends T> property) { return Input.string().emptyValuesAsNull(true).label(property).readOnly(property.isReadOnly()).build(); }
/** * Render the property as a {@link Enum} type {@link Input}. * @param property Property to render * @return The {@link Input} instance */ @SuppressWarnings("unchecked") protected Input<T> renderEnum(Property<? extends T> property) { final Class<Enum> enumType = (Class<Enum>) property.getType(); return (Input<T>) Input.singleSelect(enumType).items(enumType.getEnumConstants()).label(property) .readOnly(property.isReadOnly()).itemCaptionGenerator(new EnumItemCaptionGenerator<>()).build(); }
/** * 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(); }