com.vaadin.data.provider.DataProvider Java Examples

The following examples show how to use com.vaadin.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: 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 6 votes vote down vote up
@Override
public <C> void setDataProvider(final DataProvider<T, C> dataProvider, final SerializableFunction<String, C> filterConverter) {
    Objects.requireNonNull(dataProvider, "dataProvider cannot be null");
    Objects.requireNonNull(filterConverter, "filterConverter cannot be null");

    final SerializableFunction<String, C> convertOrNull = filterText -> {
        if (filterText == null || filterText.isEmpty()) {
            return null;
        }

        return filterConverter.apply(filterText);
    };

    final SerializableConsumer<C> providerFilterSlot = internalSetDataProvider(dataProvider, convertOrNull.apply(this.currentFilterText));

    this.filterSlot = filter -> providerFilterSlot.accept(convertOrNull.apply(filter));
}
 
Example #3
Source File: ComboBoxMultiselect.java    From vaadin-combobox-multiselect with Apache License 2.0 6 votes vote down vote up
@Override
protected <F> SerializableConsumer<F> internalSetDataProvider(final DataProvider<T, F> dataProvider, final F initialFilter) {
    final SerializableConsumer<F> consumer = super.internalSetDataProvider(dataProvider, initialFilter);

    if (getDataProvider() instanceof ListDataProvider) {
        final ListDataProvider<T> listDataProvider = ((ListDataProvider<T>) getDataProvider());
        listDataProvider.setSortComparator((o1, o2) -> {
            final boolean selected1 = this.sortingSelection.contains(o1);
            final boolean selected2 = this.sortingSelection.contains(o2);

            if (selected1 && !selected2) {
                return -1;
            }
            if (!selected1 && selected2) {
                return 1;
            }

            return getItemCaptionGenerator().apply(o1)
                    .compareToIgnoreCase(getItemCaptionGenerator().apply(o2));
        });
    }

    return consumer;
}
 
Example #4
Source File: AttributesLocationCompanion.java    From cuba with Apache License 2.0 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public void initGridDragAndDrop(DataGrid<CategoryAttribute> dataGrid,
                                List<CategoryAttribute> dataContainer,
                                boolean isAttributesSourceDataGrid) {

    DataProvider<CategoryAttribute, SerializablePredicate<CategoryAttribute>> dataProvider =  new ListDataProvider<>(dataContainer);

    if (isAttributesSourceDataGrid) {
        attributesSourceDataContainer = dataContainer;
        attributesSourceDataProvider = dataProvider;
        attributesSourceGrid = dataGrid.unwrap(CubaGrid.class);
    }

    dataGrid.withUnwrapped(CubaGrid.class, grid -> {
        grid.setDataProvider(dataProvider);

        GridDragSource<CategoryAttribute> gridDragSource = new GridDragSource<>(grid);
        gridDragSource.addGridDragStartListener(this::onGridDragStart);

        GridDropTarget<CategoryAttribute> gridDropTarget = new GridDropTarget<>(grid, DropMode.BETWEEN);
        gridDropTarget.addGridDropListener(e -> onGridDrop(e, isAttributesSourceDataGrid));
    });
}
 
Example #5
Source File: ComboBoxMultiselect.java    From vaadin-combobox-multiselect with Apache License 2.0 6 votes vote down vote up
@Override
protected <F> SerializableConsumer<F> internalSetDataProvider(final DataProvider<T, F> dataProvider, final F initialFilter) {
    final SerializableConsumer<F> consumer = super.internalSetDataProvider(dataProvider, initialFilter);

    if (getDataProvider() instanceof ListDataProvider) {
        final ListDataProvider<T> listDataProvider = ((ListDataProvider<T>) getDataProvider());
        listDataProvider.setSortComparator((o1, o2) -> {
            final boolean selected1 = this.sortingSelection.contains(o1);
            final boolean selected2 = this.sortingSelection.contains(o2);

            if (selected1 && !selected2) {
                return -1;
            }
            if (!selected1 && selected2) {
                return 1;
            }

            return getItemCaptionGenerator().apply(o1)
                    .compareToIgnoreCase(getItemCaptionGenerator().apply(o2));
        });
    }

    return consumer;
}
 
Example #6
Source File: ComboBoxMultiselect.java    From vaadin-combobox-multiselect with Apache License 2.0 6 votes vote down vote up
@Override
public <C> void setDataProvider(final DataProvider<T, C> dataProvider, final SerializableFunction<String, C> filterConverter) {
    Objects.requireNonNull(dataProvider, "dataProvider cannot be null");
    Objects.requireNonNull(filterConverter, "filterConverter cannot be null");

    final SerializableFunction<String, C> convertOrNull = filterText -> {
        if (filterText == null || filterText.isEmpty()) {
            return null;
        }

        return filterConverter.apply(filterText);
    };

    final SerializableConsumer<C> providerFilterSlot = internalSetDataProvider(dataProvider, convertOrNull.apply(this.currentFilterText));

    this.filterSlot = filter -> providerFilterSlot.accept(convertOrNull.apply(filter));
}
 
Example #7
Source File: PagedDataProviderTest.java    From GridExtensionPack with Apache License 2.0 5 votes vote down vote up
@Before
public void initialize() {
	Stream<String> stream = IntStream.range(0, 300).boxed().map(i -> "Item " + i);
	dp = DataProvider.fromStream(stream);
	pagedDP = new PagedDataProvider<>(dp);
	controls = pagedDP.getPagingControls();
}
 
Example #8
Source File: PagedDataProvider.java    From GridExtensionPack with Apache License 2.0 5 votes vote down vote up
public PagedDataProvider(DataProvider<T, F> dataProvider, int pageLength) {
	pagingControls = new PagingControls(this, pageLength);
	this.dataProvider = dataProvider;
	this.dataProvider.addDataProviderListener(event -> {
		if (event instanceof DataRefreshEvent) {
			fireEvent(event);
		} else {
			setBackendSize(null);
			refreshAll();
		}
	});
}
 
Example #9
Source File: CubaTree.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public void setDataProvider(DataProvider<T, ?> dataProvider) {
    if (!(dataProvider instanceof EnhancedTreeDataProvider)) {
        throw new IllegalArgumentException("DataProvider must implement " +
                "com.haulmont.cuba.web.widgets.tree.EnhancedTreeDataProvider");
    }

    super.setDataProvider(dataProvider);
}
 
Example #10
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 #11
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 #12
Source File: PagedDataProvider.java    From GridExtensionPack with Apache License 2.0 4 votes vote down vote up
public PagedDataProvider(DataProvider<T, F> dataProvider) {
	this(dataProvider, DEFAULT_PAGE_LENGTH);
}
 
Example #13
Source File: ComboBoxMultiselect.java    From vaadin-combobox-multiselect with Apache License 2.0 4 votes vote down vote up
@Override
public DataProvider<T, ?> getDataProvider() {
    return internalGetDataProvider();
}
 
Example #14
Source File: CubaMultiSelectionModel.java    From cuba with Apache License 2.0 4 votes vote down vote up
@Override
protected boolean shouldRemoveAddedItem(T item, DataProvider<T, ?> dataProvider, Set<T> removedItems) {
    return item == null
            || super.shouldRemoveAddedItem(item, dataProvider, removedItems);
}
 
Example #15
Source File: WebTreeDataGrid.java    From cuba with Apache License 2.0 4 votes vote down vote up
@Override
protected DataProvider<E, ?> createEmptyDataProvider() {
    return new TreeDataProvider<>(new TreeData<>());
}
 
Example #16
Source File: WebAbstractDataGrid.java    From cuba with Apache License 2.0 4 votes vote down vote up
protected DataProvider<E, ?> createEmptyDataProvider() {
    return new ListDataProvider<>(Collections.emptyList());
}
 
Example #17
Source File: WebTree.java    From cuba with Apache License 2.0 4 votes vote down vote up
protected DataProvider<E, ?> createEmptyDataProvider() {
    return new EmptyTreeDataProvider<>();
}
 
Example #18
Source File: ComboBoxMultiselect.java    From vaadin-combobox-multiselect with Apache License 2.0 4 votes vote down vote up
@Override
public DataProvider<T, ?> getDataProvider() {
    return internalGetDataProvider();
}
 
Example #19
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 #20
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);
}