Java Code Examples for com.vaadin.flow.data.provider.DataProvider#addDataProviderListener()
The following examples show how to use
com.vaadin.flow.data.provider.DataProvider#addDataProviderListener() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DataSerializableTest.java From flow with Apache License 2.0 | 5 votes |
@Override public void setDataProvider(DataProvider<Object, ?> dataProvider) { if (registration != null) { registration.remove(); } registration = dataProvider.addDataProviderListener(event -> onDataProviderChange()); }
Example 2
Source File: MultiselectComboBox.java From multiselect-combo-box-flow with Apache License 2.0 | 4 votes |
/** * {@inheritDoc} * <p> * MultiselectComboBox triggers filtering queries based on the strings users * type into the field. For this reason you need to provide the second * parameter, a function which converts the filter-string typed by the user * into filter-type used by your data provider. If your data provider * already supports String as the filter-type, it can be used without a * converter function via {@link #setDataProvider(DataProvider)}. * <p> * Using this method provides the same result as using a data provider * wrapped with * {@link DataProvider#withConvertedFilter(SerializableFunction)}. * <p> * Changing the multiselect combo box's data provider resets its current * value to {@code null}. */ @Override public <C> void setDataProvider(DataProvider<T, C> dataProvider, SerializableFunction<String, C> filterConverter) { Objects.requireNonNull(dataProvider, "The data provider can not be null"); Objects.requireNonNull(filterConverter, "filterConverter cannot be null"); if (userProvidedFilter == UserProvidedFilter.UNDECIDED) { userProvidedFilter = UserProvidedFilter.YES; } if (dataCommunicator == null) { dataCommunicator = new MultiselectComboBoxDataCommunicator<>(dataGenerator, arrayUpdater, data -> getElement() .callJsFunction("$connector.updateData", data), getElement().getNode()); } scheduleRender(); setValue(null); SerializableFunction<String, C> convertOrNull = filterText -> { if (filterText == null) { return null; } return filterConverter.apply(filterText); }; SerializableConsumer<C> providerFilterSlot = dataCommunicator .setDataProvider(dataProvider, convertOrNull.apply(null)); filterSlot = filter -> { if (!Objects.equals(filter, lastFilter)) { providerFilterSlot.accept(convertOrNull.apply(filter)); lastFilter = filter; } }; boolean shouldForceServerSideFiltering = userProvidedFilter == UserProvidedFilter.YES; dataProvider.addDataProviderListener(e -> { if (e instanceof DataChangeEvent.DataRefreshEvent) { dataCommunicator.refresh( ((DataChangeEvent.DataRefreshEvent<T>) e).getItem()); } else { refreshAllData(shouldForceServerSideFiltering); } }); refreshAllData(shouldForceServerSideFiltering); userProvidedFilter = UserProvidedFilter.UNDECIDED; }