/** * * Binds a HasValue<V> to a cookie that lives for a month. The cookies value is updated via a * ValueChangeListener. * * @param <V> The value-type of the HasValue<> * @param field The HasValue<V> that gets bound. * @param name The name of the cookie * @param cb A BrowserCookie.Callback that gets called with the actual value of the cookie. The value is guaranteed to be not null. * * @throws IllegalArgumentException if field or name are null or if name is empty. */ public static <V> void bindValueToCookie(HasValue<V> field, String name, Callback cb) { 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) { cb.onValueDetected(v); } }); field.addValueChangeListener((event) -> { setCookie(name, event.getValue().toString(), LocalDateTime.now().plusMonths(1l)); }); }
protected void fireSelectionEvent(com.vaadin.event.selection.SelectionEvent<E> e) { Set<E> oldSelection; if (e instanceof MultiSelectionEvent) { oldSelection = ((MultiSelectionEvent<E>) e).getOldSelection(); } else { //noinspection unchecked E oldValue = ((HasValue.ValueChangeEvent<E>) e).getOldValue(); oldSelection = oldValue != null ? Collections.singleton(oldValue) : Collections.emptySet(); } SelectionEvent<E> event = new SelectionEvent<>(WebTree.this, oldSelection, e.isUserOriginated()); publish(SelectionEvent.class, event); }
public CommaSeparatedStringField() { tf.addValueChangeListener(e -> { if (e.isUserOriginated()) { List<String> set = new ArrayList<>(); for (String s : tf.getValue().split(",\\s*")) { set.add(s); } collection.removeAll(collection); collection.addAll(set); fireEvent(new ValueChangeEvent(CommaSeparatedStringField.this, collection, true)); } }); tf.setWidth("100%"); setWidth("300px"); }
if (e.getValue().equals("")) { gtInput.setEnabled(true); ltInput.setEnabled(true);
headerRow .getCell(tColumn) .setComponent(new TextField(e -> filter.mutate(dataFilter -> dataFilter.setPathFilter(e.getValue()))));
protected void substitutedUserChanged(ValueChangeEvent<User> event) { UserSessionSource uss = beanLocator.get(UserSessionSource.NAME); User newUser = event.getValue(); UserSession userSession = uss.getUserSession(); if (userSession == null) {
public MDComboBox(String label, boolean light) { String primaryStyleName = light ? Styles.ComboBoxes.LIGHT : Styles.ComboBoxes.DARK; setPrimaryStyleName(primaryStyleName); this.label.setValue(label); this.label.setPrimaryStyleName(primaryStyleName + "-label"); this.label.addStyleName(RESTING); this.label.setWidthUndefined(); this.icon.setPrimaryStyleName(primaryStyleName + "-icon"); this.field.setPrimaryStyleName(primaryStyleName + "-input"); this.field.addFocusListener(event -> { addStyleName("focus"); updateFloatingLabelPosition(this.field.getValue()); }); this.field.addBlurListener(event -> { removeStyleName("focus"); updateFloatingLabelPosition(this.field.getValue()); }); this.field.addValueChangeListener(event -> { if (generator != null) { Resource itemIcon = generator.apply(event.getValue()); if (itemIcon instanceof MaterialIcons) setIcon((MaterialIcons) itemIcon); else setIcon(itemIcon); } updateFloatingLabelPosition(event.getValue()); }); this.helper.setPrimaryStyleName(primaryStyleName + "-helper"); this.helper.setWidthUndefined(); addComponents(this.label, icon, field, this.helper); setFloatingLabelEnabled(true); }
/** * 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)); }); } }
public MDDateField(String label, boolean light) { String primaryStyleName = light ? Styles.DateFields.LIGHT : Styles.DateFields.DARK; setPrimaryStyleName(primaryStyleName); setFloatingLabelEnabled(true); this.label.setValue(label); this.label.setPrimaryStyleName(primaryStyleName + "-label"); this.label.addStyleName(RESTING); this.label.setWidthUndefined(); this.icon.setPrimaryStyleName(primaryStyleName + "-icon"); this.field.setPrimaryStyleName(primaryStyleName + "-input"); this.field.addFocusListener(event -> { addStyleName("focus"); updateFloatingLabelPosition(this.field.getValue()); }); this.field.addBlurListener(event -> { removeStyleName("focus"); updateFloatingLabelPosition(this.field.getValue()); }); this.field.addValueChangeListener(event -> updateFloatingLabelPosition(event.getValue())); this.helper.setPrimaryStyleName(primaryStyleName + "-helper"); this.helper.setWidthUndefined(); addComponents(this.label, icon, field, this.helper); }
public MDTextField(String label, boolean light) { String primaryStyleName = light ? Styles.TextFields.LIGHT : Styles.TextFields.DARK; setPrimaryStyleName(primaryStyleName); setFloatingLabelEnabled(true); this.label.setValue(label); this.label.setPrimaryStyleName(primaryStyleName + "-label"); this.label.addStyleName(RESTING); this.label.setWidthUndefined(); this.icon.setPrimaryStyleName(primaryStyleName + "-icon"); this.field.setPrimaryStyleName(primaryStyleName + "-input"); this.field.addFocusListener(event -> { addStyleName("focus"); updateFloatingLabelPosition(field.getValue()); }); this.field.addBlurListener(event -> { removeStyleName("focus"); updateFloatingLabelPosition(field.getValue()); }); this.field.addValueChangeListener(event -> updateFloatingLabelPosition(event.getValue())); this.helper.setPrimaryStyleName(primaryStyleName + "-helper"); this.helper.setWidthUndefined(); addComponents(this.label, icon, field, this.helper); }
public MDDateTimeField(String label, boolean light) { String primaryStyleName = light ? Styles.DateFields.LIGHT : Styles.DateFields.DARK; setPrimaryStyleName(primaryStyleName); setFloatingLabelEnabled(true); this.label.setValue(label); this.label.setPrimaryStyleName(primaryStyleName + "-label"); this.label.addStyleName(RESTING); this.label.setWidthUndefined(); this.icon.setPrimaryStyleName(primaryStyleName + "-icon"); this.field.setPrimaryStyleName(primaryStyleName + "-input"); this.field.addFocusListener(event -> { addStyleName("focus"); updateFloatingLabelPosition(this.field.getValue()); }); this.field.addBlurListener(event -> { removeStyleName("focus"); updateFloatingLabelPosition(this.field.getValue()); }); this.field.addValueChangeListener(event -> updateFloatingLabelPosition(event.getValue())); this.helper.setPrimaryStyleName(primaryStyleName + "-helper"); this.helper.setWidthUndefined(); addComponents(this.label, icon, field, this.helper); }
@Override protected Component initContent() { addStyleName("linkfield"); rootLayout.setSizeFull(); rootLayout.setSpacing(true); textField.setWidth(100, Unit.PERCENTAGE); textField.addValueChangeListener(event -> { // null value means "remove the currently selected link" T value = itemResolver.getItemByPath(event.getValue()).orElse(null); setValue(value); }); linkLayout.setSizeFull(); linkLayout.addComponent(textField); linkLayout.setExpandRatio(textField, 1); if (!textField.isReadOnly()) { selectButton.addStyleName("magnoliabutton"); linkLayout.addComponent(selectButton); linkLayout.setExpandRatio(selectButton, 0); } rootLayout.addComponent(linkLayout); addValueChangeListener(event -> updateComponents()); updateComponents(); return rootLayout; }
public MDTextFieldBox(String label, boolean light) { String primaryStyleName = light ? Styles.TextFieldBoxes.LIGHT : Styles.TextFieldBoxes.DARK; setPrimaryStyleName(primaryStyleName); this.label.setValue(label); this.label.setPrimaryStyleName(primaryStyleName + "-label"); this.label.addStyleName(RESTING); this.label.setWidthUndefined(); this.icon.setPrimaryStyleName(primaryStyleName + "-icon"); this.ripple.setPrimaryStyleName(primaryStyleName + "-ripple"); this.field.setPrimaryStyleName(primaryStyleName + "-input"); this.field.addFocusListener(event -> { addStyleName("focus"); updateFloatingLabelPosition(this.field.getValue()); }); this.field.addBlurListener(event -> { removeStyleName("focus"); updateFloatingLabelPosition(this.field.getValue()); }); this.field.addValueChangeListener(event -> updateFloatingLabelPosition(event.getValue())); this.helper.setPrimaryStyleName(primaryStyleName + "-helper"); this.helper.setWidthUndefined(); addComponents(this.label, icon, field, ripple, this.helper); }
public MDTextAreaBox(String label, boolean light) { String primaryStyleName = light ? Styles.TextFieldBoxes.LIGHT : Styles.TextFieldBoxes.DARK; setPrimaryStyleName(primaryStyleName); this.label.setValue(label); this.label.setPrimaryStyleName(primaryStyleName + "-label"); this.label.addStyleName(RESTING); this.label.setWidthUndefined(); this.icon.setPrimaryStyleName(primaryStyleName + "-icon"); this.ripple.setPrimaryStyleName(primaryStyleName + "-ripple"); this.field.setPrimaryStyleName(primaryStyleName + "-input"); this.field.addFocusListener(event -> { addStyleName("focus"); updateFloatingLabelPosition(this.field.getValue()); }); this.field.addBlurListener(event -> { removeStyleName("focus"); updateFloatingLabelPosition(this.field.getValue()); }); this.field.addValueChangeListener(event -> updateFloatingLabelPosition(event.getValue())); this.helper.setPrimaryStyleName(primaryStyleName + "-helper"); this.helper.setWidthUndefined(); addComponents(this.label, icon, field, ripple, this.helper); }
public MDPasswordField(String label, boolean light) { String primaryStyleName = light ? Styles.TextFields.LIGHT : Styles.TextFields.DARK; setPrimaryStyleName(primaryStyleName); setFloatingLabelEnabled(true); this.label.setValue(label); this.label.setPrimaryStyleName(primaryStyleName + "-label"); this.label.addStyleName(RESTING); this.label.setWidthUndefined(); this.icon.setPrimaryStyleName(primaryStyleName + "-icon"); this.field.setPrimaryStyleName(primaryStyleName + "-input"); this.field.addFocusListener(event -> { addStyleName("focus"); updateFloatingLabelPosition(field.getValue()); }); this.field.addBlurListener(event -> { removeStyleName("focus"); updateFloatingLabelPosition(field.getValue()); }); this.field.addValueChangeListener(event -> updateFloatingLabelPosition(event.getValue())); this.helper.setPrimaryStyleName(primaryStyleName + "-helper"); this.helper.setWidthUndefined(); addComponents(this.label, icon, field, this.helper); }
private void initialize() { optionsField = formFieldFactory.createField(definition.getField(), locale); layout.addComponent(optionsField); optionsField.addValueChangeListener(e -> { if (e.getOldValue() == null || e.getOldValue() == null) { return; } EditorView<T> oldView = subForm(e.getOldValue()); EditorView<T> newView = subForm(e.getValue()); layout.replaceComponent(oldView.asVaadinComponent(), newView.asVaadinComponent()); }); definition.getForms().forEach(formDefinition -> { ItemProviderStrategy<T> subFormProviderStrategy = create(((ComplexPropertyDefinition<T>) formDefinition).getItemProvider(), formDefinition, itemProviderStrategy); EditorView<T> subForm = getViewProvider().create(formDefinition); subForms.put(formDefinition.getName(), Pair.of(subForm, subFormProviderStrategy)); }); binder = ConfiguredBinder.withPropertySet(propertySetFactory.fromFieldDefinitions(Collections.singletonList(definition.getField()), locale)); binder.forField(optionsField) .withConverter(new StringToOptionDefinitionConverter(definition.getField())) .bind(resolvePropertyNameByLocale(definition.getField().getName(), locale, definition.getField().isI18n())); }
public Registration addFieldListener(FieldValueChangeListener<T> listener) { if (fieldValueChangeListener == null) { fieldValueChangeListener = ((CubaTextField) field).addValueChangeListener(event -> { String text = event.getValue(); if (!suppressTextChangeListener && !Objects.equals(getStringRepresentation(), text)) { suppressTextChangeListener = true; FieldValueChangeEvent<T> e = new FieldValueChangeEvent<>(CubaPickerField.this, text, getValue()); fireEvent(e); suppressTextChangeListener = false; // update text representation manually if (field instanceof TextField) { updateTextRepresentation(); } } }); } addListener(FieldValueChangeEvent.class, listener, FIELD_VALUE_CHANGE_METHOD); return fieldValueChangeListener; }
@Override protected void init(VaadinRequest request) { DisclosurePanel aboutBox = new DisclosurePanel("Spring Boot JPA CRUD example with Vaadin UI", new RichText().withMarkDownResource("/welcome.md")); setContent( new MVerticalLayout( aboutBox, new MHorizontalLayout(filterByName, addNew, edit, delete), list ).expand(list) ); listEntities(); list.asSingleSelect().addValueChangeListener(e -> adjustActionButtonState()); filterByName.addValueChangeListener(e -> { listEntities(e.getValue()); }); // Listen to change events emitted by PersonForm see onEvent method eventBus.subscribe(this); }
private HorizontalLayout createUserPanel() { HorizontalLayout hl = new HorizontalLayout(); hl.setMargin(new MarginInfo(false,true,true,true)); hl.setSpacing(true); userComboBox = createUserBox(); userComboBox.setStyleName(ValoTheme.COMBOBOX_SMALL); userComboBox.addValueChangeListener(listener -> { ConfigurableFilterDataProvider wrapper = (ConfigurableFilterDataProvider) getGrid().getDataProvider(); wrapper.setFilter(listener.getValue()); this.selectedUser = listener.getValue(); wrapper.refreshAll(); }); hl.addComponent(userComboBox); return hl; }