/** * Creates a new data provider backed by a collection. * <p> * The collection is used as-is. Changes in the collection will be visible * via the created data provider. The caller should copy the collection if * necessary. * * @param <T> * the data item type * @param items * the collection of data, not <code>null</code> * @return a new list data provider */ public static <T> ListDataProvider<T> ofCollection(Collection<T> items) { return new ListDataProvider<>(items); }
/** * Creates a new data provider from the given items. * <p> * The items are copied into a new backing list, so structural changes to * the provided array will not be visible via the created data provider. * * @param <T> * the data item type * @param items * the data items * @return a new list data provider */ @SafeVarargs public static <T> ListDataProvider<T> ofItems(T... items) { return new ListDataProvider<>(new ArrayList<>(Arrays.asList(items))); }
/** * Creates a new data provider from the given stream. <b>All items in the * stream are eagerly collected to a list.</b> * <p> * This is a shorthand for using {@link #ofCollection(Collection)} after * collecting the items in the stream to a list with e.g. * {@code stream.collect(Collectors.toList));}. * <p> * <strong>Using big streams is not recommended, you should instead use a * lazy data provider.</strong> See * {@link #fromCallbacks(FetchCallback, CountCallback)} or * {@link BackEndDataProvider} for more info. * * @param <T> * the data item type * @param items * a stream of data items, not {@code null} * @return a new list data provider */ public static <T> ListDataProvider<T> fromStream(Stream<T> items) { return new ListDataProvider<>(items.collect(Collectors.toList())); }
protected DataProvider<E, ?> createEmptyDataProvider() { return new ListDataProvider<>(Collections.emptyList()); }
public FilterField( final ListDataProvider<T> dataProvider, final TableDefinition<T> tableDefinition) { super(); this.dataProvider = dataProvider; this.tableDefinition = tableDefinition; this.attributeField.setStyleName("filter-attribute"); this.attributeField.addValueChangeListener(this::onAttributeChange); this.attributeField.setDataProvider(new ListDataProvider<>(filterDefinitions)); this.attributeField.setTextInputAllowed(false); this.optionsField.setStyleName("filter-options"); this.optionsField.setDataProvider(optionsDataProvider); this.textField.setStyleName("filter-text"); this.tableDefinition.getFilterableColumns().map(ColumnDefinition::filterDefinition).forEach(filterDefinitions::add); if (hasFilterDefinitions()) { this.attributeField.setSelectedItem(this.filterDefinitions.get(0)); } this.optionsField.addValueChangeListener(this::onFilterOptionSelected); this.optionsField.addShortcutListener(new ClearFilterShortcutListener<>(this)); this.textField.addShortcutListener(new FilterShortcutListener<>(this)); this.textField.addShortcutListener(new ClearFilterShortcutListener<>(this)); }
new ListDataProvider<>(tasks);