@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(); }
@Override public <T> Optional<Property<T>> setValue(Path<T> path, T value) { Optional<Property<T>> property = getProperty(path); property.ifPresent(p -> { getPropertyBox().setValue(p, value); }); return property; }
public void collectionProperties() { // tag::collprops[] final ListPathProperty<String> STR = ListPathProperty.create("str", String.class); // <1> final SetPathProperty<Integer> ITG = SetPathProperty.create("str", Integer.class); // <2> Class<?> elementType = STR.getElementType(); // <3> PropertyBox box = PropertyBox.create(STR, ITG); box.setValue(STR, Collections.singletonList("a")); // <4> List<String> listValue = box.getValue(STR); // <5> box.setValue(ITG, Collections.singleton(1)); // <6> Set<Integer> setValue = box.getValue(ITG); // <7> // end::collprops[] }
@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; }
/** * Decode given document into a {@link PropertyBox} using given adapter to match the document field names and * property paths. * @param context Resolution context * @param parent Optional parent field name expression * @param document Document to decode * @param propertyBox PropertyBox to use to collect the decoded values * @param adapter PropertyBox adapter * @throws InvalidExpressionException If an error occurred */ private static void decodeDocument(final MongoDocumentContext<?> context, final String parent, Map<String, Object> document, PropertyBox propertyBox, PathPropertyBoxAdapter adapter) throws InvalidExpressionException { final List<Property<?>> properties = new ArrayList<>(context.getPropertySet().asList()); document.entrySet().stream().forEach(entry -> { decodeDocumentField(context, propertyBox, adapter, parent, entry.getKey(), entry.getValue()) .ifPresent(p -> { properties.remove(p); }); }); // check properties with converter and force value set for (Property<?> property : properties) { if (property.getConverter().isPresent() && propertyBox.contains(property)) { propertyBox.setValue(property, null); } } }
public void propertyBox3() { // tag::propertybox3[] final StringProperty NAME = StringProperty.create("name"); final StringProperty SURNAME = StringProperty.create("surname"); final VirtualProperty<String> FULL_NAME = VirtualProperty.create(String.class, propertyBox -> { // <1> return propertyBox.getValue(NAME) + " " + propertyBox.getValue(SURNAME); }); PropertyBox propertyBox = PropertyBox.create(NAME, SURNAME, FULL_NAME); // <2> propertyBox.setValue(NAME, "John"); propertyBox.setValue(SURNAME, "Doe"); String fullName = propertyBox.getValue(FULL_NAME); // <3> // end::propertybox3[] }
@SuppressWarnings("unchecked") @Override @Deprecated public O add(Map<Path<?>, Object> values) { if (values != null && !values.isEmpty()) { final PropertySet<?> propertySet = getDefinition().getPropertySet().orElse(asPropertySet(values.keySet())); final PropertyBox propertyBox = PropertyBox.builder(propertySet).invalidAllowed(true).build(); final PathPropertySetAdapter adapter = PathPropertySetAdapter.create(propertySet); for (Entry<Path<?>, Object> entry : values.entrySet()) { adapter.getProperty(entry.getKey()).ifPresent(p -> { if (entry.getValue() != null) { propertyBox.setValue((Property<Object>) p, entry.getValue()); } }); } getDefinition().addValue(propertyBox); return getActualOperation(); } return getActualOperation(); }
/** * Writes the property bound {@link Input} components values, obtained through the {@link Input#getValue()} method, * to given <code>propertyBox</code>, * @param propertyBox the {@link PropertyBox} into which to write the property values (not null) * @param validate whether to perform inputs and overall validation */ @SuppressWarnings("unchecked") private void flush(PropertyBox propertyBox, boolean validate) { ObjectUtils.argumentNotNull(propertyBox, "PropertyBox must be not null"); if (validate) { // inputs validation validateInputs(); } propertySet.forEach(p -> { final PropertyConfiguration<?> cfg = getPropertyConfiguration(p); if (cfg.isHidden()) { getCurrentPropertyValue(p).ifPresent(v -> { propertyBox.setValue(p, v); }); } else { cfg.getInput().ifPresent(i -> { propertyBox.setValue(p, i.getValue()); }); } }); if (validate) { // Overall validation validate(propertyBox); } }
public void propertyBox() { // tag::propertybox[] final PathProperty<Long> ID = PathProperty.create("id", Long.class); final StringProperty NAME = StringProperty.create("name"); final PropertySet<?> PROPERTIES = PropertySet.of(ID, NAME); PropertyBox propertyBox = PropertyBox.create(ID, NAME); // <1> propertyBox = PropertyBox.create(PROPERTIES); // <2> propertyBox.setValue(ID, 1L); // <3> propertyBox.setValue(NAME, "testName"); // <4> propertyBox = PropertyBox.builder(PROPERTIES).set(ID, 1L).set(NAME, "testName").build(); // <5> Long id = propertyBox.getValue(ID); // <6> String name = propertyBox.getValueIfPresent(NAME).orElse("default"); // <7> boolean containsNotNullId = propertyBox.containsValue(ID); // <8> PropertyBox ids = propertyBox.cloneBox(ID); // <9> // end::propertybox[] }
documentContext.getDocumentIdProperty().ifPresent(idProperty -> { if (value.contains(idProperty)) { value.setValue((Property<Object>) idProperty, idPropertyValue);
@Override public void setValue(T newValue) throws com.vaadin.data.Property.ReadOnlyException { // Check read-only if (isReadOnly()) { throw new Property.ReadOnlyException(); } try { getPropertyBox().setValue(getPropertyId(), newValue); } catch (@SuppressWarnings("unused") PropertyReadOnlyException e) { throw new com.vaadin.data.Property.ReadOnlyException("Property is read-only: " + getPropertyId()); } // fire value change event fireValueChange(); }
/** * Check generated document id after an upsert type operation, setting the inserted key using given * {@link OperationResult} builder. * @param builder OperationResult builder * @param documentContext Document context * @param configuration Operation configuration * @param upsertedId Optional upserted id value * @param value Original {@link PropertyBox} value */ @SuppressWarnings("unchecked") public static void checkUpsertedKey(OperationResult.Builder builder, MongoDocumentContext<?> documentContext, DatastoreOperationConfiguration configuration, BsonValue upsertedId, PropertyBox value) { if (upsertedId != null) { final ObjectId oid = upsertedId.asObjectId().getValue(); documentContext.getDocumentIdPath().ifPresent(idp -> { final Object idPropertyValue = documentContext.getDocumentIdResolver().decode(oid, idp.getType()); builder.withInsertedKey(idp, idPropertyValue); // check bring back ids if (configuration.hasWriteOption(DefaultWriteOption.BRING_BACK_GENERATED_IDS)) { documentContext.getDocumentIdProperty().ifPresent(idprp -> { if (value.contains(idprp)) { value.setValue((Property<Object>) idprp, idPropertyValue); } }); } }); } }
idProperty.getType()); if (rd.getValue().contains(idProperty)) { rd.getValue().setValue((Property<Object>) idProperty, idPropertyValue);
public void propertyBox2() { // tag::propertybox2[] final PathProperty<Long> ID = PathProperty.create("id", Long.class).withValidator(Validator.notNull()); // <1> final StringProperty NAME = StringProperty.create("name").withValidator(Validator.notBlank()); // <2> final PropertySet<?> PROPERTIES = PropertySet.of(ID, NAME); PropertyBox propertyBox = PropertyBox.create(PROPERTIES); propertyBox.setValue(ID, null); // <3> propertyBox = PropertyBox.builder(PROPERTIES).invalidAllowed(true).build(); // <4> propertyBox.validate(); // <5> // end::propertybox2[] }
propertyBox.setValue(b.getProperty(), b.getElement().getValue());