/** * Convert given {@link Path} set to a {@link PropertySet}, including only {@link Property} type paths. * @param paths Path collection * @return A {@link PropertySet} which includes the {@link Property} type paths, in the given order */ @SuppressWarnings({ "rawtypes", "unchecked" }) private static PropertySet<?> asPropertySet(Iterable<Path<?>> paths) { final PropertySet.Builder builder = PropertySet.builder(); for (Path<?> path : paths) { if (path != null && Property.class.isAssignableFrom(path.getClass())) { builder.add((Property) path); } } return builder.build(); }
/** * Join given {@link PropertySet}s and return a new PropertySet containing all the properties of given sets. * @param <P> Actual property type * @param propertySets PropertySet to join (not null and not empty) * @return New PropertySet containing all the properties of given sets * @deprecated Using this method causes the loss of any property set configuration and/or identifier property * declaration. Use the default PropertySet builder to compose a new PropertySet from different property * sources. */ @SuppressWarnings("unchecked") @Deprecated @SafeVarargs static <P extends Property> PropertySet<P> join(PropertySet<? extends P>... propertySets) { if (propertySets == null || propertySets.length == 0) { throw new IllegalArgumentException("No PropertySet to join"); } Builder builder = builder(); for (PropertySet<? extends P> ps : propertySets) { ps.forEach(p -> builder.add(p)); } return builder.build(); }
@SuppressWarnings("unchecked") @Override public B dataSource(ItemDataProvider<PropertyBox> dataProvider, final Property... identifierProperties) { ObjectUtils.argumentNotNull(identifierProperties, "Identifier properties must be not null"); if (identifierProperties.length == 0) { throw new IllegalArgumentException("Identifier properties must be not empty"); } final PropertySet<?> propertySet = PropertySet.builderOf(identifierProperties) .identifiers(Arrays.asList(identifierProperties)).build(); return dataSource(dataProvider, item -> { PropertyBox.Builder builder = PropertyBox.builder(propertySet); for (Property p : identifierProperties) { item.getValueIfPresent(p).ifPresent(v -> builder.set(p, v)); } return builder.build(); }); }
return builder.build();
/** * Create a {@link DatastoreDataProvider} and use given <code>identifierProperties</code> as {@link PropertyBox} * items identifiers. * <p> * The {@link PropertyBox} items will be fetched from the persistence source using a properly configured Datastore * query, with given <code>dataTarget</code> representing the persistent entity to query. The {@link PropertyBox} * items will be built using given <code>propertySet</code>. * </p> * <p> * The provided identifier properties will be used as {@link PropertyBox} item identifiers, i.e. the * <code>equals</code> and <code>hashCode</code> logic of the items will be implemented accordingly to the values of * the identifier properties. * </p> * @param datastore The {@link Datastore} to use (not null) * @param target The data target to use (not null) * @param propertySet The query projection property set (not null) * @param identifierProperties Properties to use as item identifiers * @return A new {@link DatastoreDataProvider} instance */ static DatastoreDataProvider create(Datastore datastore, DataTarget<?> target, PropertySet<?> propertySet, Property<?>... identifierProperties) { if (identifierProperties == null || identifierProperties.length == 0) { return create(datastore, target, propertySet); } // set given identifier properties as property set identifiers PropertySet<?> propertySetWithIds = PropertySet.builder().add(propertySet) .identifiers(Arrays.asList(identifierProperties)).build(); return builder().datastore(datastore).target(target).withProperties(propertySetWithIds).build(); }
/** * Builder to create an {@link PropertyListing} instance using a {@link Grid} as backing component. * @param <P> Actual property type * @param properties The property set to use for the listing (not null) * @param additionalProperties Additional properties to declare * @return Grid {@link PropertyListing} builder */ @SafeVarargs @SuppressWarnings("rawtypes") static <P extends Property> GridPropertyListingBuilder properties(PropertySet<P> properties, P... additionalProperties) { ObjectUtils.argumentNotNull(properties, "Properties must be not null"); if (additionalProperties != null && additionalProperties.length > 0) { PropertySet.Builder<Property<?>> builder = PropertySet.builder().add(properties); for (P property : additionalProperties) { builder.add(property); } return PropertyListing.builder(builder.build()); } return PropertyListing.builder(properties); }
public void listingVirtual() { // tag::virtualproperty1[] final VirtualProperty<Component> EDIT = VirtualProperty.create(Component.class).message("Edit") // <1> .valueProvider( // <2> row -> Components.button().styleName(ValoTheme.BUTTON_ICON_ONLY).icon(VaadinIcons.EDIT) .onClick(e -> { Long rowId = row.getValue(ID); // <3> // perform edit action ... }).build()); PropertyListing listing = Components.listing.properties(PROPERTIES) // <4> .build(EDIT, ID, DESCRIPTION); // <5> listing = Components.listing.properties(PROPERTIES) // .build(PropertySet.builder().add(PROPERTIES).add(EDIT).build()); // <6> // end::virtualproperty1[] }
@Override public B dataSource(Datastore datastore, DataTarget<?> dataTarget, Property... identifierProperties) { if (identifierProperties == null || identifierProperties.length == 0) { return dataSource(datastore, dataTarget); } // set given identifier properties ad property set identifiers PropertySet<?> propertySet = PropertySet.builder().add(properties) .identifiers(Arrays.asList(identifierProperties)).build(); // set data source dataSource(ItemDataProvider.create(datastore, dataTarget, propertySet)); // set commit handler commitHandler(CommitHandler.datastore(datastore, dataTarget)); return builder(); }
public void propertyBox4() { // tag::propertybox4[] final NumericProperty<Long> ID = NumericProperty.longType("id"); final StringProperty NAME = StringProperty.create("name"); final PropertySet<?> PROPERTIES = PropertySet.builderOf(ID, NAME).identifier(ID).build(); // <1> PropertyBox propertyBox1 = PropertyBox.builder(PROPERTIES).set(ID, 1L).set(NAME, "name1").build(); PropertyBox propertyBox2 = PropertyBox.builder(PROPERTIES).set(ID, 1L).set(NAME, "name2").build(); boolean isTrue = propertyBox1.equals(propertyBox2); // <2> // end::propertybox4[] }
public void propertySet3() { // tag::propertyset3[] final NumericProperty<Long> ID = NumericProperty.longType("id"); final StringProperty NAME = StringProperty.create("name"); PropertySet<Property<?>> SET = PropertySet.builder().add(ID).add(NAME).identifier(ID).build(); // <1> SET = PropertySet.builderOf(ID, NAME).identifier(ID).build(); // <2> Set<Property<?>> ids = SET.getIdentifiers(); // <3> Optional<Property<?>> id = SET.getFirstIdentifier(); // <4> SET.identifiers().forEach(p -> p.toString()); // <5> // end::propertyset3[] }
public void identifiers() { // tag::identifiers[] final NumericProperty<Long> ID = NumericProperty.longType("id"); final StringProperty DESCRIPTION = StringProperty.create("description"); final PropertySet<?> PROPERTIES = PropertySet.builderOf(ID, DESCRIPTION).identifier(ID).build(); // <1> PropertyListing listing = Components.listing.properties(PROPERTIES).build(); // end::identifiers[] }
public void dataMappable2() { final StringProperty P1 = StringProperty.create("p1"); final StringProperty P2 = StringProperty.create("p2"); // tag::datamappable2[] PropertySet<?> PROPERTIES = PropertySet.builderOf(P1, P2) // .withConfiguration(DataMappable.PATH, "mapping-name") // <1> .build(); Optional<String> mapping = PROPERTIES.getConfiguration().getParameter(DataMappable.PATH); // <2> // end::datamappable2[] }
public void propertySet() { // tag::propertyset[] final StringProperty NAME = StringProperty.create("name"); final StringProperty SURNAME = StringProperty.create("surname"); final NumericProperty<Integer> SEQUENCE = NumericProperty.integerType("surname"); PropertySet<Property<?>> set = PropertySet.of(NAME, SURNAME); // <1> set = PropertySet.builder().add(NAME).add(SURNAME).build(); // <2> PropertySet<Property<?>> set2 = PropertySet.builder().add(set).add(SEQUENCE).build(); // <3> // end::propertyset[] }
public void serializationConfig() { // tag::sconfig[] StringProperty NAME = StringProperty.create("name"); // <1> VirtualProperty<String> VRT = VirtualProperty.create(String.class, pb -> "(" + pb.getValue(NAME) + ")") .name("vrt"); // <2> final PropertySet<?> PROPERTY_SET = PropertySet.builderOf(NAME, VRT).withConfiguration( JsonConfigProperties.PROPERTYBOX_SERIALIZATION_MODE, PropertyBoxSerializationMode.ALL).build(); // <3> PropertyBox propertyBox = PropertyBox.builder(PROPERTY_SET).set(NAME, "test").build(); // <4> // end::sconfig[] }