/** * 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(); }
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[] }
/** * Obtain a builder to create and populate a {@link PropertySet}, and add given <code>properties</code> to the * property set to build. * @param <P> Property type * @param properties Properties to initially add to the property set (not null) * @return A new {@link PropertySet} builder * @since 5.1.0 */ @SafeVarargs static <P extends Property> Builder<Property<?>> builderOf(P... properties) { ObjectUtils.argumentNotNull(properties, "Properties must be not null"); Builder<Property<?>> builder = builder(); for (P property : properties) { builder.add(property); } return builder; }
/** * 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(); }
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[] }
/** * 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); }
@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(); }
/** * 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(); }
static <P extends Property> PropertySet<P> of(PropertySet<? extends P> propertySet, P... properties) { ObjectUtils.argumentNotNull(propertySet, "Source property set must be not null"); final Builder builder = builder(); propertySet.forEach(p -> builder.add(p));
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[] }