/** * Resets the value to the empty one. * <p> * This is just a shorthand for resetting the value, see the methods * {@link #setValue(Object)} and {@link #getEmptyValue()}. * * @see #setValue(Object) * @see #getEmptyValue() */ public default void clear() { setValue(getEmptyValue()); }
@Override public void read(BEAN bean) { getField().setValue(convertDataToFieldType(bean)); }
/** * Sets the field value by invoking the getter function on the given * bean. The default listener attached to the field will be removed for * the duration of this update. * * @param bean * the bean to fetch the property value from */ private void initFieldValue(BEAN bean) { assert bean != null; assert onValueChange != null; valueInit = true; try { getField().setValue(convertDataToFieldType(bean)); } finally { valueInit = false; } }
private void colorChanged(ValueChangeEvent<Color> event) { event.getSource().setValue(event.getValue()); setValue(event.getValue()); updatingColors = true; setRgbSliderValues(selectedColor); float[] hsv = selectedColor.getHSV(); setHsvSliderValues(hsv); updatingColors = false; for (HasValue<Color> s : selectors) { if (event.getSource() != s && s != this && s.getValue() != selectedColor) { s.setValue(selectedColor); } } }
@Override public void setValue(V value) { field.setValue(value); }
/** * Sets the value of this object. If the new value is not equal to * {@code getValue()}, fires a value change event. May throw * {@code IllegalArgumentException} if the value is not acceptable. * <p> * <i>Implementation note:</i> the implementing class should document * whether null values are accepted or not. * * @param value * the new value * @return this (for method chaining) * @throws IllegalArgumentException * if the value is invalid */ public default S withValue(V value) { ((HasValue<V>) this).setValue(value); return (S) this; }
protected void setValueToPresentation(P value) { if (hasValidationError()) { setValidationError(null); } component.setValue(value); }
@Override protected void doSetValue(T value) { getInternalField().setValue(toInternalValue(value)); }
@Override public Component apply(S t) { return Optional.ofNullable(componentDefinition.getEditor()).map(ColumnEditorDefinition::getField).map(fieldDefinition -> { final Component component = formFieldFactory.createField((FieldDefinition<?>) fieldDefinition, Locale.getDefault()); if (component instanceof AbstractField) { ((AbstractField) component).setReadOnly(true); } else if (component instanceof AbstractSingleSelect) { ((AbstractSingleSelect) component).setReadOnly(true); } Object value = wrapped.apply(t); if (value != null) { ((HasValue) component).setValue(value); } return component; }).orElse(null); }
/** * Binds a HasValue<String> to a cookie that lives for a month. The cookies value is updated via a * ValueChangeListener. Its crrent value is copied into the HasValue<String>. * * @param field The HasValue<String> that gets bound. * @param name The name of the cookie * * @throws IllegalArgumentException if field or name are null or if name is empty. */ public static void bindValueToCookie(HasValue<String> field, String name) { if (Objects.isNull(name) || name.isEmpty()) { throw new IllegalArgumentException("Name must not be null or empty"); } if (Objects.isNull(field)) { throw new IllegalArgumentException("Field must not be null"); } detectCookieValue(name, (v) -> { if (v != null) { field.setValue(v); } }); field.addValueChangeListener((event) -> { setCookie(name, event.getValue(), LocalDateTime.now().plusMonths(1l)); }); } }
/** * Applies annotation values to {@code component} * * @param component the component to be updated * @param annotationValues the annotation values to apply * @param annotationInfo used primarily to identify the Field, and therefore its name */ private void applyAnnotationValues(AbstractComponent component, AnnotationValues annotationValues, AnnotationInfo annotationInfo) { // set locale first Locale locale = annotationValues.locale.isPresent() ? annotationValues.locale.get() : currentLocale.getLocale(); component.setLocale(locale); // set caption, description & value if available if (annotationValues.captionKey.isPresent()) { component.setCaption(translate.from(annotationValues.captionKey.get(), locale)); } if (annotationValues.descriptionKey.isPresent()) { component.setDescription(translate.from(annotationValues.descriptionKey.get(), locale)); } if (annotationValues.valueKey.isPresent()) { if (component instanceof HasValue) { ((HasValue) component).setValue(translate.from(annotationValues.valueKey.get(), locale)); return; } else { log.warn("Field {} has a value annotation but does not implement HasValue. Annotation ignored", annotationInfo.getField() .getName()); } } }
@Override protected Component initContent() { comboBox.addValueChangeListener((ValueChangeListener<T>) event -> { if (event.getValue() != null) { //for now, we use caption as value to not introduce any JCR specific logic here tokenField.addTokenizable(new ToStringTokenizable(comboBox.getItemCaptionGenerator().apply(event.getValue()))); event.getSource().setValue(null); } }); tokenField.setTokenDragDropEnabled(true); tokenField.setEnableDefaultDeleteTokenAction(true); tokenField.setInputField(comboBox); return tokenField; }