@SuppressWarnings("unchecked") @Override public Class<V> getType() { return (Class<V>) ReflectTools.convertPrimitiveType(property.getType()); }
@Override protected Class<?> getPropertyType(String property) { return propertySet.property(property).getType(); }
/** * Check the given property is of given value type. * @param property Property to check * @param type Required type * @return Typed property * @throws TypeMismatchException If the given type is not consistent with actual property type */ @SuppressWarnings("unchecked") private static <PT> PathProperty<PT> checkPropertyType(PathProperty<?> property, Class<PT> type) { if (!TypeUtils.isAssignable(type, property.getType())) { throw new TypeMismatchException("Requested property type " + type.getName() + " doesn't match property type " + property.getType().getName()); } return (PathProperty<PT>) property; }
@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); }
@Override public BeanBulkUpdate<B> set(String propertyName, Object value) { ObjectUtils.argumentNotNull(propertyName, "Property name must be not null"); if (value == null) { return setNull(propertyName); } final PathProperty<Object> beanProperty = getBeanPropertySet(getBeanClass()).property(propertyName); if (!TypeUtils.isAssignable(value.getClass(), beanProperty.getType())) { throw new TypeMismatchException( "Value type [" + value.getClass().getName() + "] doesn't match the bean property [" + propertyName + "] type [" + beanProperty.getType().getName() + "]"); } return set(beanProperty, value); }
@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)); }