com.vaadin.server.SerializablePredicate Java Examples

The following examples show how to use com.vaadin.server.SerializablePredicate. 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: 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 #2
Source File: PagedDataProviderTest.java    From GridExtensionPack with Apache License 2.0 6 votes vote down vote up
@Test
public void testFilterProvidedByQuery() {
	controls.setPageLength(15);

	Query<String, SerializablePredicate<String>> noFilterQuery = new Query<>();
	Assert.assertEquals(controls.getPageLength(), pagedDP.size(noFilterQuery));
	Assert.assertEquals(controls.getPageLength(), pagedDP.fetch(noFilterQuery).count());

	Query<String, SerializablePredicate<String>> filterQuery = new Query<>(x -> x.startsWith("Item 2"));
	Assert.assertEquals(controls.getPageLength(), pagedDP.size(filterQuery));
	Assert.assertEquals(controls.getPageLength(), pagedDP.fetch(filterQuery).count());

	filterQuery = new Query<>(x -> x.startsWith("Item 3"));
	Assert.assertEquals(11, pagedDP.size(filterQuery));
	Assert.assertEquals(11, pagedDP.fetch(filterQuery).count());
}
 
Example #3
Source File: PagedDataProviderTest.java    From GridExtensionPack with Apache License 2.0 6 votes vote down vote up
@Test
public void testOffsetAndLimitProvidedByQuery() {
	Query<String, SerializablePredicate<String>> implicitLimitQuery = new Query<>();
	Assert.assertEquals(controls.getPageLength(), pagedDP.size(implicitLimitQuery));

	Query<String, SerializablePredicate<String>> explicitLimitQuery = new Query<>(
			1,
			controls.getPageLength() - 2,
			implicitLimitQuery.getSortOrders(),
			implicitLimitQuery.getInMemorySorting(),
			implicitLimitQuery.getFilter().orElse(null));
	Assert.assertEquals(controls.getPageLength(), pagedDP.size(explicitLimitQuery));
	Assert.assertEquals(controls.getPageLength()- 2, pagedDP.fetch(explicitLimitQuery).count());

	controls.nextPage();
	Assert.assertEquals(controls.getPageLength(), pagedDP.size(explicitLimitQuery));
	Assert.assertEquals(controls.getPageLength() - 2, pagedDP.fetch(explicitLimitQuery).count());
}
 
Example #4
Source File: PagedDataProviderTest.java    From GridExtensionPack with Apache License 2.0 6 votes vote down vote up
@Test
public void testLimitProvidedByQuery() {
	Query<String, SerializablePredicate<String>> implicitLimitQuery = new Query<>();
	Assert.assertEquals(controls.getPageLength(), pagedDP.size(implicitLimitQuery));

	Query<String, SerializablePredicate<String>> explicitLimitQuery = new Query<>(
			implicitLimitQuery.getOffset(),
			controls.getPageLength() - 1,
			implicitLimitQuery.getSortOrders(),
			implicitLimitQuery.getInMemorySorting(),
			implicitLimitQuery.getFilter().orElse(null));
	Assert.assertEquals(controls.getPageLength(), pagedDP.size(explicitLimitQuery));
	Assert.assertEquals(controls.getPageLength() - 1, pagedDP.fetch(explicitLimitQuery).count());

	controls.nextPage();
	Assert.assertEquals(controls.getPageLength(), pagedDP.size(explicitLimitQuery));
	Assert.assertEquals(controls.getPageLength() - 1, pagedDP.fetch(explicitLimitQuery).count());
}
 
Example #5
Source File: PagedDataProviderTest.java    From GridExtensionPack with Apache License 2.0 6 votes vote down vote up
@Test
public void testOffsetProvidedByQuery() {
	Query<String, SerializablePredicate<String>> zeroOffsetQuery = new Query<>();
	Assert.assertEquals(controls.getPageLength(), pagedDP.size(zeroOffsetQuery));

	Query<String, SerializablePredicate<String>> singleOffsetQuery = new Query<>(
			1,
			zeroOffsetQuery.getLimit(),
			zeroOffsetQuery.getSortOrders(),
			zeroOffsetQuery.getInMemorySorting(),
			zeroOffsetQuery.getFilter().orElse(null));
	Assert.assertEquals(controls.getPageLength(), pagedDP.size(singleOffsetQuery));
	Assert.assertEquals(controls.getPageLength() - 1, pagedDP.fetch(singleOffsetQuery).count());

	controls.nextPage();
	Assert.assertEquals(controls.getPageLength(), pagedDP.size(singleOffsetQuery));
	Assert.assertEquals(controls.getPageLength() - 1, pagedDP.fetch(singleOffsetQuery).count());
}
 
Example #6
Source File: GridCellFilter.java    From vaadin-grid-util with MIT License 5 votes vote down vote up
private void refreshFilters() {
    dataProvider.clearFilters();
    SerializablePredicate<T> filter = null;
    for (Entry<String, SerializablePredicate> entry :
            assignedFilters.entrySet()) {
        final String columnId = entry.getKey();

        ValueProvider<T, ?> provider = null;
        try {
            provider = propertySet.getProperty(columnId).get().getGetter();
        } catch (Exception e) {
            try {
                provider = grid.getColumn(columnId).getValueProvider();
            }catch (Exception ex){
                e.printStackTrace();
                ex.printStackTrace();
                throw e;
            }
        }

        SerializablePredicate<T> singleFilter = InMemoryDataProviderHelpers.createValueProviderFilter(provider, entry.getValue());
        if (filter == null) {
            filter = singleFilter;
        } else {
            SerializablePredicate<T> tempFilter = filter;
            filter = (item -> tempFilter.test(item) && singleFilter.test(item));
        }
    }
    if (filter != null) {
        dataProvider.setFilter(filter);
    }
}
 
Example #7
Source File: PagedDataProviderTest.java    From GridExtensionPack with Apache License 2.0 5 votes vote down vote up
@Test
public void testOffsetProvidedByQueryIsTwoPageLengths() {
	Query<String, SerializablePredicate<String>> zeroOffsetQuery = new Query<>();
	Assert.assertEquals(controls.getPageLength(), pagedDP.size(zeroOffsetQuery));

	Query<String, SerializablePredicate<String>> twoPageOffsetQuery = new Query<>(
			controls.getPageLength() * 2,
			zeroOffsetQuery.getLimit(),
			zeroOffsetQuery.getSortOrders(),
			zeroOffsetQuery.getInMemorySorting(),
			zeroOffsetQuery.getFilter().orElse(null));
	Assert.assertEquals(controls.getPageLength(), pagedDP.size(twoPageOffsetQuery));
	Assert.assertEquals(0, pagedDP.fetch(twoPageOffsetQuery).count());
}
 
Example #8
Source File: PagedDataProviderTest.java    From GridExtensionPack with Apache License 2.0 5 votes vote down vote up
@Test
public void testOffsetProvidedByQueryIsOnePageLength() {
	Query<String, SerializablePredicate<String>> zeroOffsetQuery = new Query<>();
	Assert.assertEquals(controls.getPageLength(), pagedDP.size(zeroOffsetQuery));

	Query<String, SerializablePredicate<String>> singlePageOffsetQuery = new Query<>(
			controls.getPageLength(),
			zeroOffsetQuery.getLimit(),
			zeroOffsetQuery.getSortOrders(),
			zeroOffsetQuery.getInMemorySorting(),
			zeroOffsetQuery.getFilter().orElse(null));
	Assert.assertEquals(controls.getPageLength(), pagedDP.size(singlePageOffsetQuery));
	Assert.assertEquals(0, pagedDP.fetch(singlePageOffsetQuery).count());
}
 
Example #9
Source File: DataGridDataProvider.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public Stream<T> fetch(Query<T, SerializablePredicate<T>> query) {
    if (dataGridItems.getState() == BindingState.INACTIVE) {
        return Stream.empty();
    }

    return dataGridItems.getItems()
            .skip(query.getOffset())
            .limit(query.getLimit());
}
 
Example #10
Source File: DataGridDataProvider.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public int size(Query<T, SerializablePredicate<T>> query) {
    // FIXME: gg, query?
    if (dataGridItems.getState() == BindingState.INACTIVE) {
        return 0;
    }

    return dataGridItems.size();
}
 
Example #11
Source File: HierarchicalDataGridDataProvider.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public Stream<T> fetchChildren(HierarchicalQuery<T, SerializablePredicate<T>> query) {
    if (dataGridItems.getState() == BindingState.INACTIVE) {
        return Stream.empty();
    }

    return getTreeDataGridSource().getChildren(query.getParent())
            .skip(query.getOffset())
            .limit(query.getLimit());
}
 
Example #12
Source File: HierarchicalDataGridDataProvider.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public int getChildCount(HierarchicalQuery<T, SerializablePredicate<T>> query) {
    if (getTreeDataGridSource().getState() == BindingState.INACTIVE) {
        return 0;
    }

    return getTreeDataGridSource().getChildCount(query.getParent());
}
 
Example #13
Source File: TreeDataProvider.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public Stream<T> fetchChildren(HierarchicalQuery<T, SerializablePredicate<T>> query) {
    if (treeItems.getState() == BindingState.INACTIVE) {
        return Stream.empty();
    }

    return treeItems.getChildren(query.getParent())
            .skip(query.getOffset())
            .limit(query.getLimit());
}
 
Example #14
Source File: TreeDataProvider.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public int getChildCount(HierarchicalQuery<T, SerializablePredicate<T>> query) {
    if (treeItems.getState() == BindingState.INACTIVE) {
        return 0;
    }

    return treeItems.getChildCount(query.getParent());
}
 
Example #15
Source File: TreeDataProvider.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public int size(Query<T, SerializablePredicate<T>> query) {
    // FIXME: gg, query?
    if (treeItems.getState() == BindingState.INACTIVE) {
        return 0;
    }

    return treeItems.size();
}
 
Example #16
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 #17
Source File: GridCellFilter.java    From vaadin-grid-util with MIT License 2 votes vote down vote up
/**
 * checks assignedFilters replace already handled one and add new one
 *
 * @param filter   container filter
 * @param columnId id of property
 */
public void replaceFilter(SerializablePredicate filter, String columnId) {
    assignedFilters.put(columnId, filter);
    refreshFilters();
}