@Override public String getName() { return property.relativeName(); }
@Override public Collection<String> getProperties() { return propertySet.stream().map(p -> p.relativeName()).collect(Collectors.toList()); }
@Override public boolean contains(String propertyName) { ObjectUtils.argumentNotNull(propertyName, "Property name must be not null"); return stream().filter(p -> propertyName.equals(p.relativeName())).findAny().isPresent(); }
@SuppressWarnings("unchecked") @Override public <PT> Optional<PathProperty<PT>> getProperty(String propertyName) { ObjectUtils.argumentNotNull(propertyName, "Property name must be not null"); return stream().filter(p -> propertyName.equals(p.relativeName())).findFirst().map(p -> (PathProperty<PT>) p); }
@Override public Optional<StringProperty> getPropertyString(String propertyName) { ObjectUtils.argumentNotNull(propertyName, "Property name must be not null"); return stream().filter(p -> propertyName.equals(p.relativeName())).findFirst() .map(p -> checkPathPropertyType(p, StringProperty.class)); }
@Override public Optional<BooleanProperty> getPropertyBoolean(String propertyName) { ObjectUtils.argumentNotNull(propertyName, "Property name must be not null"); return stream().filter(p -> propertyName.equals(p.relativeName())).findFirst() .map(p -> checkPathPropertyType(p, BooleanProperty.class)); }
@SuppressWarnings("unchecked") @Override public <N extends Number> Optional<NumericProperty<N>> getPropertyNumeric(String propertyName) { ObjectUtils.argumentNotNull(propertyName, "Property name must be not null"); return stream().filter(p -> propertyName.equals(p.relativeName())).findFirst() .map(p -> checkPathPropertyType(p, NumericProperty.class)); }
@SuppressWarnings("unchecked") @Override public <X> Optional<TemporalProperty<X>> getPropertyTemporal(String propertyName) { ObjectUtils.argumentNotNull(propertyName, "Property name must be not null"); return stream().filter(p -> propertyName.equals(p.relativeName())).findFirst() .map(p -> checkPathPropertyType(p, TemporalProperty.class)); }
@Override public <PT> Optional<PathProperty<PT>> getProperty(String propertyName, Class<PT> type) { ObjectUtils.argumentNotNull(propertyName, "Property name must be not null"); ObjectUtils.argumentNotNull(type, "Property type must be not null"); return stream().filter(p -> propertyName.equals(p.relativeName())).findFirst() .map(p -> checkPropertyType(p, type)); }
@SuppressWarnings("unchecked") @Override public <X> Optional<TemporalProperty<X>> getPropertyTemporal(String propertyName, Class<X> type) { ObjectUtils.argumentNotNull(propertyName, "Property name must be not null"); ObjectUtils.argumentNotNull(type, "Property type must be not null"); return stream().filter(p -> propertyName.equals(p.relativeName())).findFirst() .map(p -> checkPropertyType(p, type)).map(p -> checkPathPropertyType(p, TemporalProperty.class)); }
@SuppressWarnings("unchecked") @Override public <N extends Number> Optional<NumericProperty<N>> getPropertyNumeric(String propertyName, Class<N> type) { ObjectUtils.argumentNotNull(propertyName, "Property name must be not null"); ObjectUtils.argumentNotNull(type, "Property type must be not null"); return stream().filter(p -> propertyName.equals(p.relativeName())).findFirst() .map(p -> checkPropertyType(p, type)).map(p -> checkPathPropertyType(p, NumericProperty.class)); }
/** * Get the property with given <code>propertyPath</code> from bean property set using the properties full name as * matching rule. * @param propertyPath Property path * @param ignoreMissing <code>true</code> to ignore mismatches * @return Optional matching bean property * @throws PropertyNotFoundException If ignoreMissing is false and a matching bean property was not found */ private Optional<BeanProperty<?>> getProperty(Path<?> propertyPath, boolean ignoreMissing) throws PropertyNotFoundException { ObjectUtils.argumentNotNull(propertyPath, "Property path must be not null"); Optional<PathProperty<?>> beanProperty = stream() .filter(p -> propertyPath.relativeName().equals(p.relativeName())).findFirst(); if (!ignoreMissing && !beanProperty.isPresent()) { throw new PropertyNotFoundException((propertyPath instanceof Property) ? (Property<?>) propertyPath : null, "Property with name [" + propertyPath.relativeName() + "] was not found in bean [" + getBeanClass() + "] property set"); } return beanProperty.map(p -> (BeanProperty<?>) p); }
/** * Constructor. * @param beanType Bean type (not null) */ public DefaultBeanListing(Class<T> beanType) { super(); ObjectUtils.argumentNotNull(beanType, "Bean type must be not null"); this.beanType = beanType; this.propertySet = BeanPropertySet.create(beanType); // add properties as columns for (PathProperty<?> property : propertySet) { addPropertyColumn(property.relativeName()); } }
@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)); }
@SuppressWarnings("unchecked") public DefaultTableItemListingBuilder(Class<T> beanType) { super(new DefaultBeanListing<>(RenderingMode.TABLE)); 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)); }