Java Code Examples for com.vaadin.data.provider.DataProvider#ofCollection()

The following examples show how to use com.vaadin.data.provider.DataProvider#ofCollection() . 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: ComboBoxMultiselect.java    From vaadin-combobox-multiselect with Apache License 2.0 7 votes vote down vote up
/**
 * {@inheritDoc}
 * <p>
 * Filtering will use a case insensitive match to show all items where the filter text is a substring of the caption displayed for that item.
 */
@Override
public void setItems(final Collection<T> items) {
    final ListDataProvider<T> listDataProvider = DataProvider.ofCollection(items);

    setDataProvider(listDataProvider);

    // sets the PageLength to 10.
    // if there are less then 10 items in the combobox, PageLength will get the amount of items.
    setPageLength(getDataProvider().size(new Query<>()) >= ComboBoxMultiselect.DEFAULT_PAGE_LENGTH ? ComboBoxMultiselect.DEFAULT_PAGE_LENGTH : getDataProvider().size(new Query<>()));
}
 
Example 2
Source File: ComboBoxMultiselect.java    From vaadin-combobox-multiselect with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 * <p>
 * Filtering will use a case insensitive match to show all items where the filter text is a substring of the caption displayed for that item.
 */
@Override
public void setItems(final Collection<T> items) {
    final ListDataProvider<T> listDataProvider = DataProvider.ofCollection(items);

    setDataProvider(listDataProvider);

    // sets the PageLength to 10.
    // if there are less then 10 items in the combobox, PageLength will get the amount of items.
    setPageLength(getDataProvider().size(new Query<>()) >= ComboBoxMultiselect.DEFAULT_PAGE_LENGTH ? ComboBoxMultiselect.DEFAULT_PAGE_LENGTH : getDataProvider().size(new Query<>()));
}
 
Example 3
Source File: DemoContentLayout.java    From GridExtensionPack with Apache License 2.0 4 votes vote down vote up
public DemoContentLayout() {
	final SelectGrid<TestObject> grid = new SelectGrid<>();
	grid.addColumn(TestObject::getFoo).setCaption("Foo");
	grid.addColumn(TestObject::getBar, new NumberRenderer()).setCaption("Bar");
	grid.addColumn(TestObject::getKm, new NumberRenderer()).setCaption("KM");
	grid.setHeightByRows(10);
	grid.setHeightMode(HeightMode.ROW);

	// Show it in the middle of the screen
	setStyleName("demoContentLayout");
	setSizeFull();
	addComponent(grid);
	setComponentAlignment(grid, Alignment.MIDDLE_CENTER);

	final TableSelectionModel<TestObject> tableSelect = new TableSelectionModel<>();
	grid.setSelectionModel(tableSelect);
	tableSelect.setMode(TableSelectionMode.CTRL);

	HorizontalLayout tableSelectionControls = new HorizontalLayout();
	tableSelectionControls.setCaption("Table Selection Controls");

	// Controls for testing different TableSelectionModes
	for (final TableSelectionMode t : TableSelectionMode.values()) {
		tableSelectionControls.addComponent(new Button(t.toString(), e -> tableSelect.setMode(t)));
	}

	addComponent(tableSelectionControls);

	// TODO: PagingDataProvider

	PagedDataProvider<TestObject, SerializablePredicate<TestObject>> dataProvider = new PagedDataProvider<>(
			DataProvider.ofCollection(TestObject.generateTestData(995)));
	grid.setDataProvider(dataProvider);
	PagingControls pagingControls = dataProvider.getPagingControls();

	HorizontalLayout pages = new HorizontalLayout();
	pages.setCaption("Paging controls");
	pages.addComponent(new Button("First", e -> pagingControls.setPageNumber(0)));
	pages.addComponent(new Button("Previous", e -> pagingControls.previousPage()));
	pages.addComponent(new Button("Next", e -> pagingControls.nextPage()));
	pages.addComponent(new Button("Last", e -> pagingControls.setPageNumber(pagingControls.getPageCount() - 1)));
	VerticalLayout controls = new VerticalLayout();
	controls.addComponents(tableSelectionControls, pages);
	controls.setWidth("100%");
	controls.setHeightUndefined();
	controls.setComponentAlignment(tableSelectionControls, Alignment.MIDDLE_CENTER);
	controls.setComponentAlignment(pages, Alignment.BOTTOM_CENTER);
	addComponent(controls);
	setComponentAlignment(controls, Alignment.MIDDLE_CENTER);

	grid.getEditor().setEnabled(true);
	for (Column<TestObject, ?> c : grid.getColumns()) {
		c.setHidable(true);
	}
}
 
Example 4
Source File: ComboBoxMultiselect.java    From vaadin-combobox-multiselect with Apache License 2.0 2 votes vote down vote up
/**
 * Sets the data items of this listing and a simple string filter with which the item string and the text the user has input are compared.
 * <p>
 * Note that unlike {@link #setItems(Collection)}, no automatic case conversion is performed before the comparison.
 *
 * @param captionFilter filter to check if an item is shown when user typed some text into the ComboBoxMultiselect
 * @param items the data items to display
 * @since 8.0
 */
public void setItems(final CaptionFilter captionFilter, final Collection<T> items) {
    final ListDataProvider<T> listDataProvider = DataProvider.ofCollection(items);

    setDataProvider(captionFilter, listDataProvider);
}
 
Example 5
Source File: ComboBoxMultiselect.java    From vaadin-combobox-multiselect with Apache License 2.0 2 votes vote down vote up
/**
 * Sets the data items of this listing and a simple string filter with which the item string and the text the user has input are compared.
 * <p>
 * Note that unlike {@link #setItems(Collection)}, no automatic case conversion is performed before the comparison.
 *
 * @param captionFilter filter to check if an item is shown when user typed some text into the ComboBoxMultiselect
 * @param items the data items to display
 * @since 8.0
 */
public void setItems(final CaptionFilter captionFilter, final Collection<T> items) {
    final ListDataProvider<T> listDataProvider = DataProvider.ofCollection(items);

    setDataProvider(captionFilter, listDataProvider);
}