/** * Create a new {@link PathProperty} with given <code>name</code> and <code>type</code>, setting this * {@link DataTarget} as property parent path. * @param <P> Property type * @param name Property name (not null) * @param type Property value type (not null) * @return Property builder */ default <P> PathPropertyBuilder<P> property(String name, Class<? extends P> type) { return PathProperty.<P>create(name, type).parent(this); }
@Override protected Optional<ValueProvider<?, ?>> getDefaultPropertyPresenter(String property) { Optional<PathProperty<Object>> beanProperty = getBeanProperty(property); if (beanProperty.isPresent()) { if (FontIcon.class.isAssignableFrom(beanProperty.get().getType())) { return Optional.of(v -> ((FontIcon) v).getHtml()); } return Optional.of(v -> beanProperty.get().present(v)); } return super.getDefaultPropertyPresenter(property); }
public void filter2() { final PathProperty<Integer> PROPERTY1 = PathProperty.create("test1", Integer.class); final PathProperty<Integer> PROPERTY2 = PathProperty.create("test2", Integer.class); final StringProperty STRING_PROPERTY = StringProperty.create("test3"); QueryFilter restriction = PROPERTY1.isNotNull(); // is not null restriction = PROPERTY1.isNull(); // is null restriction = PROPERTY1.eq(7); // equal to a value restriction = PROPERTY1.eq(PROPERTY2); // equal to another property restriction = PROPERTY1.neq(7); // not equal restriction = PROPERTY1.lt(7); // less than restriction = PROPERTY1.loe(7); // less than or equal restriction = PROPERTY1.gt(7); // greater than restriction = PROPERTY1.goe(7); // greater than or equal restriction = PROPERTY1.between(1, 7); // between restriction = PROPERTY1.in(1, 2, 3); // in restriction = PROPERTY1.nin(1, 2, 3); // not in QueryFilter negation = PROPERTY1.eq(7).not(); // negation QueryFilter conjuction = PROPERTY1.isNotNull().and(PROPERTY2.eq(3)); // conjuction QueryFilter disjunction = PROPERTY1.isNull().or(PROPERTY2.eq(3)); // disjunction
@SuppressWarnings("unchecked") public void renderers1() { // tag::renderers1[] final PathProperty<String> TEXT = PathProperty.create("text", String.class); final PathProperty<Long> LONG = PathProperty.create("long", Long.class); Input<String> input = TEXT.render(Input.class); // <1> Field<Long> field = LONG.render(Field.class); // <2> ViewComponent<String> view = TEXT.render(ViewComponent.class); // <3> // end::renderers1[] }
public void sort2() { // tag::sort2[] final PathProperty<String> PROPERTY = PathProperty.create("test", String.class); final PathProperty<String> ANOTHER_PROPERTY = PathProperty.create("another", String.class); // <1> QuerySort sortAsc = PROPERTY.asc(); // sort ASCENDING on given property QuerySort sortDesc = PROPERTY.desc(); // sort DESCENDING on given property // <2> PROPERTY.asc().and(ANOTHER_PROPERTY.desc()); // sort ASCENDING on PROPERTY, than sort DESCENDING on // ANOTHER_PROPERTY // end::sort2[] }
public void dataMappable1() { // tag::datamappable1[] PathProperty<Integer> property = PathProperty.create("name", Integer.class) // .dataPath("mapping-name"); // <1> Optional<String> mapping = property.getDataPath(); // <2> // end::datamappable1[] }
public void selectable10() { // tag::selectable10[] Datastore datastore = obtainDatastore(); final PathProperty<Long> ID = PathProperty.create("id", Long.class); final PathProperty<String> DESCRIPTION = PathProperty.create("description", String.class); SingleSelect<Long> singleSelect = Components.input.singleSelect(ID) .dataSource(datastore, DataTarget.named("testData"), PropertySet.of(ID, DESCRIPTION), // Datastore () -> ID.gt(0L)) // <1> .itemCaptionGenerator(propertyBox -> propertyBox.getValue(DESCRIPTION)).build(); // end::selectable10[] }
public void queryDefinition() { // tag::querydefinition[] final PathProperty<Integer> PROPERTY = PathProperty.create("test", Integer.class); Datastore datastore = getDatastore(); // build or obtain a Datastore Query query = datastore.query() // <1> .target(DataTarget.named("testTarget")) // <2> .filter(PROPERTY.gt(10)) // <3> .sort(PROPERTY.asc()) // <4> .aggregate(PROPERTY) // <5> .limit(100) // <6> .offset(200); // <7> query = datastore.query(DataTarget.named("testTarget")) // <8> .aggregate(QueryAggregation.builder().path(PROPERTY).filter(PROPERTY.gt(10)).build()) // <9> .restrict(100, 200); // <10> // end::querydefinition[] }
public void listing9() { // tag::listing9[] PropertyListing listing = Components.listing.properties(PROPERTIES) // .sortable(ID, true) // <1> .sortUsing(ID, DESCRIPTION) // <2> .sortGenerator(ID, (property, ascending) -> { // <3> return ascending ? ID.asc() : ID.desc(); }) // .fixedSort(ID.asc()) // <4> .defaultSort(DESCRIPTION.asc()) // <5> .fixedFilter(ID.gt(0L)) // <6> .withQueryConfigurationProvider(() -> DESCRIPTION.isNotNull()) // <7> .build(); // end::listing9[] }
public void presenter() { // tag::presenter[] final PathProperty<Long> ID = PathProperty.create("id", Long.class); String stringValue = ID.present(1L); // <1> stringValue = PropertyValuePresenterRegistry.get().getPresenter(ID) .orElseThrow(() -> new IllegalStateException("No presenter available for given property")) .present(ID, 1L); // <2> // end::presenter[] }
@Override public String getName() { return property.relativeName(); }
public void aggregation() { // tag::aggregation[] final PathProperty<Integer> PROPERTY = PathProperty.create("test", Integer.class); final PathProperty<String> ANOTHER_PROPERTY = PathProperty.create("another", String.class); QueryAggregation aggregation = QueryAggregation.builder() // <1> .path(PROPERTY) // <2> .path(ANOTHER_PROPERTY) // <3> .filter(PROPERTY.isNotNull()) // <4> .build(); // end::aggregation[] }
public void selectable11() { // tag::selectable11[] Datastore datastore = obtainDatastore(); final PathProperty<Long> ID = PathProperty.create("id", Long.class); final PathProperty<String> DESCRIPTION = PathProperty.create("description", String.class); final DataTarget<?> TARGET = DataTarget.named("testData"); final PropertySet<?> PROPERTIES = PropertySet.of(ID, DESCRIPTION); SingleSelect<Long> singleSelect = Components.input.singleSelect(ID) .dataSource(datastore, DataTarget.named("testData"), PROPERTIES) .itemConverter( value -> datastore.query().target(TARGET).filter(ID.eq(value)).findOne(PROPERTIES).orElse(null)) // <1> .build(); // end::selectable11[] }
@SuppressWarnings("unchecked") public DefaultGridItemListingBuilder(Class<T> beanType) { super(new DefaultBeanListing<>(RenderingMode.GRID)); ObjectUtils.argumentNotNull(beanType, "Item bean type must be not null"); // setup datasource BeanPropertySet<T> ps = BeanPropertySet.create(beanType); getInstance().setPropertySet(ps); final List<String> nested = new LinkedList<>(); ps.forEach(p -> { final String name = p.relativeName(); dataSourceBuilder.withProperty(name, p.getType()); if (p.getParent().isPresent()) { nested.add(p.relativeName()); } }); // item adapter dataSourceBuilder.itemAdapter(new BeanItemAdapter(nested)); }
public void datastore() { // tag::datastore[] final PathProperty<String> A_PROPERTY = PathProperty.create("propertyPath", String.class); final DataTarget<String> TARGET = DataTarget.named("test"); final Datastore datastore = getDatastore(); // build or obtain a concrete Datastore implementation PropertyBox data = PropertyBox.builder(A_PROPERTY).set(A_PROPERTY, "aValue").build(); OperationResult result = datastore.save(TARGET, data); // <1> result = datastore.insert(TARGET, data); // <2> result = datastore.update(TARGET, data); // <3> PropertyBox refreshed = datastore.refresh(TARGET, data); // <4> datastore.delete(TARGET, refreshed); // <5> // Bulk operations result = datastore.bulkInsert(TARGET, PropertySet.of(A_PROPERTY)) .add(PropertyBox.builder(A_PROPERTY).set(A_PROPERTY, "aValue1").build()) .add(PropertyBox.builder(A_PROPERTY).set(A_PROPERTY, "aValue2").build()) .add(PropertyBox.builder(A_PROPERTY).set(A_PROPERTY, "aValue3").build()).execute(); // <6> result = datastore.bulkUpdate(TARGET).set(A_PROPERTY, "updated").filter(A_PROPERTY.isNull()).execute(); // <7> result = datastore.bulkDelete(TARGET).filter(A_PROPERTY.isNull()).execute(); // <8> // end::datastore[] }
@Override protected Class<?> getPropertyType(String property) { return propertySet.property(property).getType(); }
void operations() { Datastore datastore = getJpaDatastore(); PropertyBox value = PropertyBox.builder(Test.PROPERTIES).set(Test.PROPERTIES.property("id"), 1L) .set(Test.PROPERTIES.property("value"), "test").build(); // <3> datastore.save(Test.TARGET, value); List<PropertyBox> values = datastore.query(Test.TARGET).filter(Test.PROPERTIES.property("id").gt(0L)) .sort(Test.PROPERTIES.property("value").desc()).list(Test.PROPERTIES); // <4> } // end::beans1[]
public void listing9() { // tag::listing9[] PropertyListing listing = Components.listing.properties(PROPERTIES) // .sortable(ID, true) // <1> .sortUsing(ID, DESCRIPTION) // <2> .sortGenerator(ID, (property, ascending) -> { // <3> return ascending ? ID.asc() : ID.desc(); }) // .fixedSort(ID.asc()) // <4> .defaultSort(DESCRIPTION.asc()) // <5> .fixedFilter(ID.gt(0L)) // <6> .withQueryConfigurationProvider(() -> DESCRIPTION.isNotNull()) // <7> .build(); // end::listing9[] }
@SuppressWarnings({ "rawtypes", "unchecked" }) protected <P extends Property<?>> void setupItemConverter(Datastore datastore, DataTarget<?> dataTarget, Iterable<P> properties) { if (selectProperty != null && PathProperty.class.isAssignableFrom(selectProperty.getClass()) && !getInstance().getItemConverter().isPresent()) { itemConverter(value -> { if (value != null) { return datastore.query().target(dataTarget).filter(((PathProperty) selectProperty).eq(value)) .findOne(properties).orElse(null); } return null; }); } }