/** * Sets a component and setter to use for editing values of this column * in the editor row. This is a shorthand for use in simple cases where * no validator or converter is needed. Use * {@link #setEditorBinding(Binding)} to support more complex cases. * <p> * <strong>Note:</strong> The same component cannot be used for multiple * columns. * * @param editorComponent * the editor component * @param setter * a setter that stores the component value in the row item * @return this column * * @see #setEditorBinding(Binding) * @see Grid#getEditor() * @see Binder#bind(HasValue, ValueProvider, Setter) */ public <C extends HasValue<V> & Component> Column<T, V> setEditorComponent( C editorComponent, Setter<T, V> setter) { Objects.requireNonNull(editorComponent, "Editor component cannot be null"); Objects.requireNonNull(setter, "Setter cannot be null"); Binding<T, V> binding = getGrid().getEditor().getBinder() .bind(editorComponent, valueProvider::apply, setter); return setEditorBinding(binding); }
.bind(editorComponent, propertyName); return setEditorBinding(binding);
column.setEditorBinding(bindingBuilder.bind(columnDefinition.getName())); });
@SuppressWarnings("unchecked") public EntityGrid<T> withDefinition(final TableDefinition<T> definition) { Column<T, ?> column; Binder<T> binder = getEditor().getBinder(); /* Remove the columns added by the constructor when evaluating the beanType */ removeAllColumns(); /* Redefine the columns based upon the definition */ for(ColumnDefinition<T> c : definition.getColumns()) { if (c.isId()) { column = addColumn(row -> buildNavigationLink(row, c, definition.getEntityViewName().orElse("error"), definition.getLinkPrefix()), new HtmlRenderer()); column.setCaption(c.getHeading()); /* Add a hidden column for the display */ if (c.getDisplay() != null) { column = addColumn(c.getDisplay().getProvider()); column.setHidden(true); } } else { column = addColumn(c.getProperty().getProvider()); column.setCaption(c.getHeading()); Optional<Binder.Binding<T, ?>> binding = Optional.ofNullable(c.getProperty().bind(binder)); if (binding.isPresent()) { column.setEditorBinding(binding.get()); getEditor().setEnabled(true); } } } return this; }
@SuppressWarnings({ "unchecked", "rawtypes" }) private void setEditorBinding(P property, Column column, HasValue editor, boolean readOnly, PropertyColumn<?, ?> pc) { BindingBuilder builder = getGrid().getEditor().getBinder().forField(editor); if (pc.isRequired()) { final Localizable requiredMessage = (pc.getRequiredMessage() != null) ? pc.getRequiredMessage() : RequiredInputValidator.DEFAULT_REQUIRED_ERROR; builder.asRequired(context -> { return LocalizationContext.translate(requiredMessage, true); }); } // default validators getDefaultPropertyValidators(property).forEach(v -> builder.withValidator(new ValidatorWrapper<>(v))); // validators pc.getValidators().forEach(v -> builder.withValidator(v)); // bind column.setEditorBinding(builder.bind(getColumnId(property))); // set editable if not read-only column.setEditable(!readOnly); }