com.vaadin.flow.data.provider.DataProvider Java Examples
The following examples show how to use
com.vaadin.flow.data.provider.DataProvider.
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: MultiselectComboBoxTest.java From multiselect-combo-box-flow with Apache License 2.0 | 5 votes |
@Test(expected = NullPointerException.class) public void shouldThrowExceptionWhenSettingNullDataProvider() { // given MultiselectComboBox<Object> multiselectComboBox = new MultiselectComboBox<>(); DataProvider<Object, String> dataProvider = null; // when multiselectComboBox.setDataProvider(dataProvider); // then, expect exception }
Example #3
Source File: SearchOverlayView.java From vaadin-app-layout with Apache License 2.0 | 4 votes |
public void setDataProvider(DataProvider<T, F> dataProvider) { this.dataProvider = dataProvider; }
Example #4
Source File: HierarchicalDataProvider.java From flow with Apache License 2.0 | 4 votes |
@Override default HierarchicalConfigurableFilterDataProvider<T, Void, F> withConfigurableFilter() { return (HierarchicalConfigurableFilterDataProvider<T, Void, F>) DataProvider.super.withConfigurableFilter(); }
Example #5
Source File: HasDataProvider.java From flow with Apache License 2.0 | 4 votes |
@Override default void setItems(Collection<T> items) { setDataProvider(DataProvider.ofCollection(items)); }
Example #6
Source File: AbstractCrud.java From crudui with Apache License 2.0 | 4 votes |
@Override public void setFindAllOperation(DataProvider<T, ?> dataProvider) { this.findAllOperation = (LazyFindAllCrudOperationListener<T>) () -> dataProvider; }
Example #7
Source File: UserToGroupView.java From radman with MIT License | 4 votes |
private void buildView() { setHeightFull(); setSpacing(false); RoleDto role = securityService.getLoggedUserRole(); Grid<RadiusUserToGroupDto> grid = new Grid<>(RadiusUserToGroupDto.class, false); grid.addColumns("username", "groupName", "userInRadman", "groupInRadman"); DataProvider<RadiusUserToGroupDto, Object> dataProvider = new SpringDataProviderBuilder<>( (pageable, o) -> userService.pageRadiusUserToGroupRecords(filter, pageable), value -> userService.countRadiusUserToGroupRecords(filter)) .withDefaultSort("username", SortDirection.ASCENDING) .build(); grid.setDataProvider(dataProvider); grid.setSortableColumns("username", "groupName"); grid.setColumnReorderingAllowed(true); grid.setMinHeight("500px"); grid.setHeight("100%"); Button addUserToGroup = new Button("Add user to group", event -> { AddUserToGroupDialog addDialog = new AddUserToGroupDialog( (source, bean) -> grid.getDataProvider().refreshAll()); addDialog.startAdding(); }); addUserToGroup.setEnabled(role == RoleDto.ADMIN); ConfirmationDialog deleteDialog = new ConfirmationDialog(); deleteDialog.setTitle("Delete User to Group mapping"); deleteDialog.setDescription("Are you sure?"); deleteDialog.setConfirmButtonCaption("Delete"); deleteDialog.setConfirmListener(() -> { Optional<RadiusUserToGroupDto> optional = grid.getSelectionModel().getFirstSelectedItem(); try { optional.ifPresent(userService::removeRadiusUserFromGroup); grid.getDataProvider().refreshAll(); } catch (Exception e) { log.warn("Failed to delete user to group mapping. Reason = '{}'", e.getMessage()); ErrorNotification.show("Error", "Ooops, something went wrong, try again please"); } deleteDialog.setOpened(false); }); Button removeUserFromGroup = new Button("Remove user from group", event -> deleteDialog.setOpened(true)); removeUserFromGroup.setEnabled(false); grid.asSingleSelect().addValueChangeListener(event -> removeUserFromGroup.setEnabled(Objects.nonNull(event.getValue()) && role == RoleDto.ADMIN)); TextField search = new TextField(event -> { filter.setSearchText(event.getValue()); grid.getDataProvider().refreshAll(); }); search.setValueChangeMode(ValueChangeMode.EAGER); search.setPlaceholder("Search..."); add(new H4("Data from Radius DB - \"radusergroup\" table")); HorizontalLayout horizontalLayout = new HorizontalLayout(); horizontalLayout.setDefaultVerticalComponentAlignment(FlexComponent.Alignment.BASELINE); horizontalLayout.add(new H3("Users to Groups")); horizontalLayout.add(addUserToGroup); horizontalLayout.add(removeUserFromGroup); horizontalLayout.add(search); add(horizontalLayout); add(grid); }
Example #8
Source File: SearchOverlayView.java From vaadin-app-layout with Apache License 2.0 | 4 votes |
public DataProvider<T, F> getDataProvider() { return dataProvider; }
Example #9
Source File: SearchOverlayButton.java From vaadin-app-layout with Apache License 2.0 | 4 votes |
public void setDataProvider(DataProvider<T, F> dataProvider) { this.searchView.setDataProvider(dataProvider); }
Example #10
Source File: SearchOverlayButtonBuilder.java From vaadin-app-layout with Apache License 2.0 | 4 votes |
public SearchOverlayButtonBuilder<T, F> withDataProvider(DataProvider<T, F> dataProvider) { this.dataProvider = dataProvider; return this; }
Example #11
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; }
Example #12
Source File: AccountingView.java From radman with MIT License | 4 votes |
private void buildView() { setHeightFull(); setSpacing(false); Grid<AccountingDto> grid = new Grid<>(AccountingDto.class, false); grid.addColumns("username", "callingStationId", "nasIpAddress", "serviceType"); grid.addColumn(new LocalDateTimeRenderer<>((ValueProvider<AccountingDto, LocalDateTime>) accountingDto -> { if (Objects.isNull(accountingDto.getAcctStartTime())) { return null; } return LocalDateTime.ofInstant(accountingDto.getAcctStartTime().toInstant(), TimeZone.getDefault().toZoneId()); })).setSortProperty("acctStartTime").setHeader("Acct Start Time"); grid.addColumn(new LocalDateTimeRenderer<>((ValueProvider<AccountingDto, LocalDateTime>) accountingDto -> { if (Objects.isNull(accountingDto.getAcctStopTime())) { return null; } return LocalDateTime.ofInstant(accountingDto.getAcctStopTime().toInstant(), TimeZone.getDefault().toZoneId()); })).setSortProperty("acctStopTime").setHeader("Acct Stop Time"); grid.addColumns("acctTerminateCause", "framedIpAddress", "framedProtocol"); grid.addColumns("acctAuthentic", "acctInputOctets", "acctInterval", "acctOutputOctets", "acctSessionId"); grid.addColumn(accountingDto -> { if (Objects.isNull(accountingDto.getAcctSessionTime())) { return null; } return DurationFormatUtils.formatDurationHMS(accountingDto.getAcctSessionTime()); }).setSortProperty("acctSessionTime").setHeader("Acct Session Time"); grid.addColumns("acctUniqueId", "acctUpdateTime", "calledStationId", "connectInfoStart", "connectInfoStop", "nasPortId", "nasPortType", "radAcctId", "realm"); DataProvider<AccountingDto, Object> dataProvider = new SpringDataProviderBuilder<>( (pageable, o) -> accountingService.pageAccountingRecords(filter, pageable), value -> accountingService.countAccountingRecords(filter)) .withDefaultSort("acctStartTime", SortDirection.DESCENDING) .build(); grid.setDataProvider(dataProvider); grid.getColumns().forEach(column -> column.setResizable(true)); grid.setColumnReorderingAllowed(true); grid.setMinHeight("500px"); grid.setHeight("100%"); TextField search = new TextField(event -> { filter.setSearchText(event.getValue()); grid.getDataProvider().refreshAll(); }); search.setValueChangeMode(ValueChangeMode.EAGER); search.setPlaceholder("Search..."); SetAcctStopTimeDialog setAcctStopTimeDialog = new SetAcctStopTimeDialog((source, bean) -> grid.getDataProvider().refreshItem(bean)); Button setAcctStopTimeButton = new Button("Set Acct Stop Time", event -> { Optional<AccountingDto> optional = grid.getSelectionModel().getFirstSelectedItem(); optional.ifPresent(setAcctStopTimeDialog::set); }); setAcctStopTimeButton.setEnabled(false); grid.asSingleSelect().addValueChangeListener(event -> setAcctStopTimeButton.setEnabled(Objects.nonNull(event.getValue()))); Checkbox onlyActiveSessions = new Checkbox("Filter only active sessions"); onlyActiveSessions.setValue(filter.isSearchOnlyActiveSessions()); onlyActiveSessions.addValueChangeListener(event -> { filter.setSearchOnlyActiveSessions(event.getValue()); grid.getDataProvider().refreshAll(); }); add(new H4("Data from Radius DB - \"radacct\" table")); HorizontalLayout horizontalLayout = new HorizontalLayout(); horizontalLayout.setDefaultVerticalComponentAlignment(FlexComponent.Alignment.BASELINE); horizontalLayout.add(new H3("Accounting")); horizontalLayout.add(setAcctStopTimeButton); horizontalLayout.add(search); horizontalLayout.add(onlyActiveSessions); add(horizontalLayout); add(grid); }
Example #13
Source File: HierarchicalDataCommunicator.java From flow with Apache License 2.0 | 3 votes |
/** * Set the current hierarchical data provider for this communicator. * * @param dataProvider * the data provider to set, must extend * {@link HierarchicalDataProvider}, not <code>null</code> * @param initialFilter * the initial filter value to use, or <code>null</code> to not * use any initial filter value * * @param <F> * the filter type * * @return a consumer that accepts a new filter value to use */ @Override public <F> SerializableConsumer<F> setDataProvider( DataProvider<T, F> dataProvider, F initialFilter) { if (dataProvider instanceof HierarchicalDataProvider) { return setDataProvider( (HierarchicalDataProvider<T, F>) dataProvider, initialFilter); } throw new IllegalArgumentException( "Only " + HierarchicalDataProvider.class.getName() + " and subtypes supported."); }
Example #14
Source File: MultiselectComboBox.java From multiselect-combo-box-flow with Apache License 2.0 | 2 votes |
/** * {@inheritDoc} * <p> * The filter-type of the given data provider must be String so that it can * handle the filters typed into the MultiselectComboBox by users. If your * data provider uses some other type of filter, you can provide a function * which converts the MultiselectComboBox's filter-string into that type via * {@link #setDataProvider(DataProvider, SerializableFunction)}. Another way * to do the same thing is to use this method with your data provider * converted with * {@link DataProvider#withConvertedFilter(SerializableFunction)}. * <p> * Changing the multiselect combo box's data provider resets its current * value to {@code null}. */ @Override public void setDataProvider(DataProvider<T, String> dataProvider) { setDataProvider(dataProvider, SerializableFunction.identity()); }
Example #15
Source File: MultiselectComboBox.java From multiselect-combo-box-flow with Apache License 2.0 | 2 votes |
/** * Sets the data items of this multiselect combo box and a filtering * function for defining which items are displayed when user types into the * combo box. * <p> * Note that defining a custom filter will force the component to make * server round trips to handle the filtering. Otherwise, it can handle * filtering in the client-side, if the size of the data set is less than * the {@link #setPageSize(int) pageSize}. * <p> * Setting the items creates a new DataProvider, which in turn resets the * combo box's value to {@code null}. If you want to add and remove items to * the current item set without resetting the value, you should update the * previously set item collection and call * {@code getDataProvider().refreshAll()}. * * @param itemFilter * filter to check if an item is shown when user typed some text * into the MultiselectComboBox * @param items * the data items to display */ public void setItems(ItemFilter<T> itemFilter, Collection<T> items) { ListDataProvider<T> listDataProvider = DataProvider.ofCollection(items); setDataProvider(itemFilter, listDataProvider); }
Example #16
Source File: HasFilterableDataProvider.java From flow with Apache License 2.0 | 2 votes |
/** * Sets the data provider for this listing. The data provider is queried for * displayed items as needed. * * @param dataProvider * the data provider, not <code>null</code> */ default void setDataProvider(DataProvider<T, F> dataProvider) { setDataProvider(dataProvider, SerializableFunction.identity()); }
Example #17
Source File: HasFilterableDataProvider.java From flow with Apache License 2.0 | 2 votes |
/** * Sets the data provider and filter converter for this listing. The data * provider is queried for displayed items as needed. * * @param dataProvider * the data provider, not <code>null</code> * @param filterConverter * a function that converts filter values produced by this * listing into filter values expected by the provided data * provider, not <code>null</code> * @param <C> * the filter type */ <C> void setDataProvider(DataProvider<T, C> dataProvider, SerializableFunction<F, C> filterConverter);
Example #18
Source File: HasDataProvider.java From flow with Apache License 2.0 | 2 votes |
/** * Sets the data provider for this listing. The data provider is queried for * displayed items as needed. * * @param dataProvider * the data provider, not null */ void setDataProvider(DataProvider<T, ?> dataProvider);
Example #19
Source File: MultiselectComboBox.java From multiselect-combo-box-flow with Apache License 2.0 | 2 votes |
/** * {@inheritDoc} * <p> * Filtering will use a case insensitive match to show all items where the * filter text is a substring of the label displayed for that item, which * you can configure with * {@link #setItemLabelGenerator(ItemLabelGenerator)}. * <p> * Filtering will be handled in the client-side if the size of the data set * is less than the page size. To force client-side filtering with a larger * data set (at the cost of increased network traffic), you can increase the * page size with {@link #setPageSize(int)}. * <p> * Setting the items creates a new DataProvider, which in turn resets the * multiselect combo box's value to {@code null}. If you want to add and * remove items to the current item set without resetting the value, you * should update the previously set item collection and call * {@code getDataProvider().refreshAll()}. */ @Override public void setItems(Collection<T> items) { setDataProvider(DataProvider.ofCollection(items)); }
Example #20
Source File: MultiselectComboBox.java From multiselect-combo-box-flow with Apache License 2.0 | 2 votes |
/** * Gets the data provider used by this {@link MultiselectComboBox}. * * @return the data provider, not {@code null} */ public DataProvider<T, ?> getDataProvider() { return dataCommunicator.getDataProvider(); }
Example #21
Source File: LazyCrudListener.java From crudui with Apache License 2.0 | votes |
DataProvider<T, ?> getDataProvider();
Example #22
Source File: Crud.java From crudui with Apache License 2.0 | votes |
void setFindAllOperation(DataProvider<T, ?> dataProvider);
Example #23
Source File: LazyFindAllCrudOperationListener.java From crudui with Apache License 2.0 | votes |
DataProvider<T, ?> getDataProvider();