/** * Try to obtain a {@link ValidatableInput} component to handle the value of given <code>property</code>. * <p> * The current {@link PropertyRendererRegistry} is used to look for a suitable {@link PropertyRenderer} to render * the {@link ValidatableInput} using the provided {@link Property}. * </p> * @param <T> Property type * @param property The property for which to obtain the {@link ValidatableInput} (not null) * @return Optional property {@link ValidatableInput} component * @see PropertyRendererRegistry#get() */ @SuppressWarnings("unchecked") static <T> Optional<ValidatableInput<T>> forProperty(Property<T> property) { return property.renderIfAvailable(ValidatableInput.class).map(input -> input); }
/** * Try to render given property as a {@link Field} using a suitable {@link PropertyRenderer}, if available * @param property Property to render as Field * @return Optional Field */ @SuppressWarnings({ "rawtypes", "unchecked" }) protected Optional<Field> renderField(P property) { if (Property.class.isAssignableFrom(property.getClass())) { return ((Property) property).renderIfAvailable(Field.class); } return Optional.empty(); }
/** * Render given property as a {@link ViewComponent}, using custom {@link ViewComponentPropertyRenderer} or default * {@link Property#render(Class)} method * @param <T> Property type * @param property Property to render * @return Rendered ViewComponent */ @SuppressWarnings({ "unchecked", "rawtypes" }) protected <T> Optional<ViewComponent> render(Property<T> property) { // check custom renderer if (propertyRenderers.containsKey(property)) { final ViewComponentPropertyRenderer<T> r = propertyRenderers.get(property); return Optional.ofNullable(r.render(property)); } // use registry return property.renderIfAvailable(ViewComponent.class); }
/** * Render given property as a {@link ViewComponent}, using custom {@link ViewComponentPropertyRenderer} or default * {@link Property#render(Class)} method * @param <T> Property type * @param property Property to render * @return Rendered ViewComponent */ @SuppressWarnings({ "unchecked", "rawtypes" }) protected <T> Optional<ViewComponent> render(Property<T> property) { // check custom renderer if (propertyRenderers.containsKey(property)) { final ViewComponentPropertyRenderer<T> r = propertyRenderers.get(property); return Optional.ofNullable(r.render(property)); } // use registry return property.renderIfAvailable(ViewComponent.class); }
/** * Render this property as given <code>renderType</code>. * <p> * To successfully render the property, a suitable {@link PropertyRenderer} for given render type must be available * from the {@link PropertyRendererRegistry} obtained from current {@link Context} or from the default one for * current ClassLoader. * </p> * @param <R> Rendered object type * @param renderType Render type * @return Rendered property as given render type * @throws NoSuitableRendererAvailableException if no PropertyRenderer is available for this property and given * rendering type */ default <R> R render(Class<R> renderType) { return renderIfAvailable(renderType).orElseThrow(() -> new NoSuitableRendererAvailableException( "No PropertyRenderer available for rendering type " + renderType + " and property " + this)); }
@SuppressWarnings("unchecked") @Override protected <E extends HasValue<?> & Component> Optional<E> getDefaultPropertyEditor(Property property) { try { return property.renderIfAvailable(Field.class); } catch (Exception e) { if (isEditable()) { LOGGER.warn("No default property editor available for property [" + property + "]", e); } return Optional.empty(); } }
@SuppressWarnings("unchecked") @Override public ValidatableInput render(Property<? extends T> property) { ObjectUtils.argumentNotNull(property, "Property must be not null"); // render as Input and convert to ValidatableInput return property.renderIfAvailable(Input.class).map(input -> (Input<T>) input) .map(input -> ValidatableInput.from(input)).map(input -> { // property validators ((Property<T>) property).getValidators().forEach(validator -> input.addValidator(validator)); return input; }).orElse(null); }
/** * Get a {@link ValidatableInput} component to handle the value of given <code>property</code>. * <p> * The current {@link PropertyRendererRegistry} is used to look for a suitable {@link PropertyRenderer} to render * the {@link ValidatableInput} using the provided {@link Property}. * </p> * @param <T> Property type * @param property The property for which to obtain the {@link ValidatableInput} (not null) * @return The property {@link ValidatableInput} component * @throws NoSuitableRendererAvailableException If a suitable PropertyRenderer is not available to render given * property as a ValidatableInput * @see PropertyRendererRegistry#get() */ @SuppressWarnings("unchecked") static <T> ValidatableInput<T> create(Property<T> property) { ObjectUtils.argumentNotNull(property, "Property must be not null"); return property.renderIfAvailable(ValidatableInput.class).orElseGet(() -> from(Input.create(property))); }
@SuppressWarnings("unchecked") @Override protected <V> Optional<Input<V>> buildPropertyEditor(ItemListingColumn<Property<?>, PropertyBox, V> configuration) { final Property<V> property = (Property<V>) configuration.getProperty(); // check custom renderer Optional<Input<V>> component = configuration.getEditorInputRenderer().map(r -> r.render(property)); if (component.isPresent()) { return component; } // check specific registry if (getPropertyRendererRegistry().isPresent()) { return getPropertyRendererRegistry().get().getRenderer(Input.class, property).map(r -> r.render(property)); } else { // use default return property.renderIfAvailable(Input.class).map(c -> (Input<V>) c); } }
/** * Render given property as a {@link Input}. * @param <T> Property type * @param property Property to render * @return Rendered input */ @SuppressWarnings("unchecked") protected <T> Optional<Input<T>> render(Property<T> property) { // check custom renderer final PropertyConfiguration<T> cfg = getPropertyConfiguration(property); if (cfg.getRenderer().isPresent()) { final PropertyRenderer<Input<T>, T> r = cfg.getRenderer().get(); // check render type if (!Input.class.isAssignableFrom(r.getRenderType())) { throw new IllegalStateException( "Renderer for property [" + property + "] is not of Input type: [" + r.getRenderType() + "]"); } return Optional.ofNullable(r.render(property)); } // use registry return property.renderIfAvailable(Input.class).map(i -> i); }
/** * Render given property as a {@link Input}. * @param <T> Property type * @param property Property to render * @return Rendered input */ @SuppressWarnings("unchecked") protected <T> Optional<Input<T>> render(Property<T> property) { // check custom renderer final PropertyConfiguration<T> cfg = getPropertyConfiguration(property); if (cfg.getRenderer().isPresent()) { final PropertyRenderer<Input<T>, T> r = cfg.getRenderer().get(); // check render type if (!Input.class.isAssignableFrom(r.getRenderType())) { throw new IllegalStateException( "Renderer for property [" + property + "] is not of Input type: [" + r.getRenderType() + "]"); } return Optional.ofNullable(r.render(property)); } // use registry return property.renderIfAvailable(Input.class).map(i -> i); }
@SuppressWarnings("unchecked") @Override protected <V> Optional<Input<V>> buildPropertyEditor(ItemListingColumn<String, T, V> configuration) { return propertySet.getProperty(configuration.getProperty()).flatMap(p -> { final Property<V> property = (Property<V>) p; // check custom renderer Optional<Input<V>> component = configuration.getEditorInputRenderer().map(r -> r.render(property)); if (component.isPresent()) { return component; } // check specific registry if (getPropertyRendererRegistry().isPresent()) { return getPropertyRendererRegistry().get().getRenderer(Input.class, property) .map(r -> r.render(property)); } else { // use default return property.renderIfAvailable(Input.class).map(c -> (Input<V>) c); } }); }
/** * Render given property configuration as a {@link ViewComponent}. * @param <T> Property type * @param propertyConfiguration Property configuration * @return Optional rendered component */ @SuppressWarnings("unchecked") protected <T> Optional<ViewComponent<T>> render(ViewComponentPropertyConfiguration<T> propertyConfiguration) { // check custom renderer Optional<ViewComponent<T>> component = propertyConfiguration.getRenderer() .map(r -> r.render(propertyConfiguration.getProperty())); if (component.isPresent()) { return component; } // check specific registry if (getPropertyRendererRegistry().isPresent()) { return getPropertyRendererRegistry().get() .getRenderer(ViewComponent.class, propertyConfiguration.getProperty()) .map(r -> r.render(propertyConfiguration.getProperty())); } else { // use default return propertyConfiguration.getProperty().renderIfAvailable(ViewComponent.class) .map(c -> (ViewComponent<T>) c); } }
/** * Render given property configuration as a {@link ViewComponent}. * @param <T> Property type * @param propertyConfiguration Property configuration * @return Optional rendered component */ @SuppressWarnings("unchecked") protected <T> Optional<Input<T>> render(InputPropertyConfiguration<T> propertyConfiguration) { // check custom renderer Optional<Input<T>> component = propertyConfiguration.getRenderer() .map(r -> r.render(propertyConfiguration.getProperty())); if (component.isPresent()) { return component; } // check specific registry if (getPropertyRendererRegistry().isPresent()) { return getPropertyRendererRegistry().get().getRenderer(Input.class, propertyConfiguration.getProperty()) .map(r -> r.render(propertyConfiguration.getProperty())); } else { // use default return propertyConfiguration.getProperty().renderIfAvailable(Input.class).map(c -> (Input<T>) c); } }