@Override public <T> VirtualPropertyColumnBuilder<T, PropertyBox, Property, C, B> withVirtualProperty(Class<T> type, PropertyValueProvider<T> valueProvider) { return withVirtualProperty(VirtualProperty.create(type, valueProvider)); }
/** * Get the value of given <code>property</code> using given <code>propertyBox</code>. * @param <T> Property type * @param propertyBox PropertyBox * @param property Property * @return Property value */ protected <T> T getPropertyValue(PropertyBox propertyBox, Property<T> property) { if (VirtualProperty.class.isAssignableFrom(property.getClass())) { if (((VirtualProperty<T>) property).getValueProvider() != null) { return ((VirtualProperty<T>) property).getValueProvider().getPropertyValue(propertyBox); } return null; } if (propertyBox.contains(property)) { return propertyBox.getValue(property); } return null; }
@Override public String apply(PropertyBox source) { return property.present(property.getValueProvider().getPropertyValue(source)); }
@Override public <T> VirtualPropertyColumnBuilder<T, PropertyBox, Property, C, B> withVirtualProperty(Class<T> type, String name, PropertyValueProvider<T> valueProvider) { return withVirtualProperty(VirtualProperty.create(type, valueProvider).name(name)); }
/** * Get the value of given <code>property</code> using given <code>propertyBox</code>. * @param <T> Property type * @param propertyBox PropertyBox * @param property Property * @return Property value */ protected <T> T getPropertyValue(PropertyBox propertyBox, Property<T> property) { if (VirtualProperty.class.isAssignableFrom(property.getClass())) { if (((VirtualProperty<T>) property).getValueProvider() != null) { return ((VirtualProperty<T>) property).getValueProvider().getPropertyValue(propertyBox); } return null; } if (propertyBox.containsValue(property)) { return propertyBox.getValue(property); } return null; }
@Override public <X> ItemListingColumnBuilder<PropertyBox, Property<?>, PropertyListing, PropertyListingBuilder> withColumn( ValueProvider<PropertyBox, X> valueProvider) { ObjectUtils.argumentNotNull(valueProvider, "ValueProvider must be not null"); return withColumn(VirtualProperty.create(Object.class, item -> valueProvider.apply(item))); }
/** * Get the value of given <code>property</code> using given <code>propertyBox</code>. * @param <T> Property type * @param propertyBox PropertyBox * @param property Property * @return Property value */ protected <T> T getPropertyValue(PropertyBox propertyBox, Property<T> property) { if (VirtualProperty.class.isAssignableFrom(property.getClass())) { if (((VirtualProperty<T>) property).getValueProvider() != null) { return ((VirtualProperty<T>) property).getValueProvider().getPropertyValue(propertyBox); } return null; } if (propertyBox.containsValue(property)) { return propertyBox.getValue(property); } return null; }
@Override public ItemListingColumnBuilder<PropertyBox, Property<?>, PropertyListing, PropertyListingBuilder> withComponentColumn( ValueProvider<PropertyBox, Component> valueProvider) { ObjectUtils.argumentNotNull(valueProvider, "ValueProvider must be not null"); return withComponentColumn(VirtualProperty.create(Component.class, item -> valueProvider.apply(item))); }
/** * Get the value of given <code>property</code> using given <code>propertyBox</code>. * @param <T> Property type * @param propertyBox The PropertyBox value (may be null) * @param property The property for which to obtain the value * @return Optional property value, empty if the given PropertyBox was <code>null</code> */ protected <T> Optional<T> getPropertyValue(PropertyBox propertyBox, Property<T> property) { if (propertyBox != null) { // check vitual property if (VirtualProperty.class.isAssignableFrom(property.getClass())) { if (((VirtualProperty<T>) property).getValueProvider() != null) { return Optional.ofNullable( ((VirtualProperty<T>) property).getValueProvider().getPropertyValue(propertyBox)); } return null; } // get the property value if (propertyBox.containsValue(property)) { return Optional.ofNullable(propertyBox.getValue(property)); } } return Optional.empty(); }
@Override public <X> ItemListingColumnBuilder<PropertyBox, Property<?>, PropertyListing, DatastorePropertyListingBuilder> withColumn( ValueProvider<PropertyBox, X> valueProvider) { ObjectUtils.argumentNotNull(valueProvider, "ValueProvider must be not null"); return withColumn(VirtualProperty.create(Object.class, item -> valueProvider.apply(item))); }
/** * Get the value of given <code>property</code> using given <code>propertyBox</code>. * @param <T> Property type * @param propertyBox PropertyBox * @param property Property * @return Property value */ protected <T> T getPropertyValue(PropertyBox propertyBox, Property<T> property) { if (VirtualProperty.class.isAssignableFrom(property.getClass())) { if (((VirtualProperty<T>) property).getValueProvider() != null) { return ((VirtualProperty<T>) property).getValueProvider().getPropertyValue(propertyBox); } return null; } if (propertyBox.contains(property)) { return propertyBox.getValue(property); } return null; }
@Override public ItemListingColumnBuilder<PropertyBox, Property<?>, PropertyListing, DatastorePropertyListingBuilder> withComponentColumn( ValueProvider<PropertyBox, Component> valueProvider) { ObjectUtils.argumentNotNull(valueProvider, "ValueProvider must be not null"); return withComponentColumn(VirtualProperty.create(Component.class, item -> valueProvider.apply(item))); }
/** * Get the value of given <code>property</code> using given <code>propertyBox</code>. * @param <T> Property type * @param propertyBox PropertyBox * @param property Property * @return Property value */ protected <T> T getPropertyValue(PropertyBox propertyBox, Property<T> property) { if (VirtualProperty.class.isAssignableFrom(property.getClass())) { if (((VirtualProperty<T>) property).getValueProvider() != null) { return ((VirtualProperty<T>) property).getValueProvider().getPropertyValue(propertyBox); } return null; } if (propertyBox.contains(property)) { return propertyBox.getValue(property); } return null; }
public void propertyListing5() { // tag::propertyListing5[] final NumericProperty<Long> ID = NumericProperty.longType("id"); final VirtualProperty<String> DESCRIPTION = VirtualProperty.create(String.class, item -> "ID: " + item.getValue(ID)); // <1> final PropertySet<?> PROPERTIES = PropertySet.of(ID, DESCRIPTION); PropertyListing listing = Components.listing.properties(PROPERTIES).build(); // <2> // end::propertyListing5[] }
/** * Add a property definition using given {@link VirtualProperty}, if not already present. * @param property Property to add * @return Column name, or <code>null</code> if the property column was already present */ public <V> String addVirtualProperty(VirtualProperty<V> property) { if (property != null && !propertyDefinitions.containsKey(property)) { GridPropertyDefinition definition = new GridPropertyDefinition<>(this, property, generatePropertyName(property), property.getValueProvider()); propertyDefinitions.put(property, definition); return definition.getName(); } return null; }
public void propertyListing4() { // tag::propertyListing4[] final NumericProperty<Long> ID = NumericProperty.longType("id"); final StringProperty TEXT = StringProperty.create("txt"); final VirtualProperty<String> DESCRIPTION = VirtualProperty.create(String.class, item -> "ID: " + item.getValue(ID)); // <1> PropertyListing listing = Components.listing.properties(ID, TEXT) // .build(ID, TEXT, DESCRIPTION); // <2> // end::propertyListing4[] }
/** * Get value of a {@link VirtualProperty} using {@link PropertyValueProvider#getPropertyValue(PropertyBox)}. * @param <T> Property type * @param property Property * @return Property value * @throws PropertyAccessException Error obtaining property value from provider */ protected <T> T getValueProviderPropertyValue(VirtualProperty<T> property) throws PropertyAccessException { PropertyValueProvider<T> valueProvider = property.getValueProvider(); if (valueProvider == null) { throw new PropertyReadException(property, "Property " + property + " declares to provide a value using a PropertyValueProvider, but returned PropertyValueProvider is null"); } try { return valueProvider.getPropertyValue(this); } catch (Exception e) { throw new PropertyReadException(property, e); } }
public void group8() { // tag::group8[] final VirtualProperty<String> VIRTUAL = VirtualProperty.create(String.class, propertyBox -> propertyBox.getValue(ID) + " -" + propertyBox.getValue(DESCRIPTION)); final PropertySet<?> PROPERTIES = PropertySet.of(ID, DESCRIPTION, VIRTUAL); PropertyInputGroup group = Components.input.propertyGroup().properties(PROPERTIES) // .withValueChangeListener(DESCRIPTION, (event, binder) -> { // <1> binder.refresh(VIRTUAL); }) // .build(); // end::group8[] }
@Override public ItemListingColumnBuilder<PropertyBox, Property<?>, PropertyListing, DatastorePropertyListingBuilder> withComponentColumn( VirtualProperty<? extends Component> property) { ObjectUtils.argumentNotNull(property, "VirtualProperty must be not null"); final ItemListingColumn<Property<?>, PropertyBox, ?> column = builder.getInstance() .addPropertyColumn(property); column.setRenderer(new ComponentRenderer<>(item -> property.getValueProvider().getPropertyValue(item))); return new DefaultItemListingColumnBuilder<>(property, builder.getInstance(), this); }
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[] }