Java 类com.vaadin.server.SerializablePredicate 实例源码

项目:vaadin-fluent-api    文件:FRadioButtonGroupTest.java   
@SuppressWarnings("unchecked")
@Test
public void test() {
    Person p1 = new Person(1, "John", LocalDate.of(1990, Month.JANUARY, 2));
    Person p2 = new Person(1, "George", LocalDate.of(1991, Month.JUNE, 19));
    Person p3 = new Person(1, "Tim", LocalDate.of(1995, Month.APRIL, 7));
    SerializablePredicate<Person> predicate = this::isBeforeJan1992;

    FRadioButtonGroup<Person> radio = new FRadioButtonGroup<Person>().withCaption("My ComboBox", true)
                                                                     .withWidth(300, Unit.PIXELS)
                                                                     .withItems(p1, p2, p3)
                                                                     .withItemCaptionGenerator(p -> p.getName())
                                                                     .withItemIconGenerator(p -> VaadinIcons.USER)
                                                                     .withItemEnabledProvider(predicate);

    assertEquals("My ComboBox", radio.getCaption());
    assertTrue(radio.isCaptionAsHtml());
    assertEquals(300, radio.getWidth(), 0);
    assertEquals(Unit.PIXELS, radio.getWidthUnits());
    assertEquals(3, ((ListDataProvider<Person>) radio.getDataProvider()).getItems().size());
    assertEquals(predicate, radio.getItemEnabledProvider());
}
项目:GridExtensionPack    文件:PagedDataProviderTest.java   
@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());
}
项目:GridExtensionPack    文件:PagedDataProviderTest.java   
@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());
}
项目:GridExtensionPack    文件:PagedDataProviderTest.java   
@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());
}
项目:GridExtensionPack    文件:PagedDataProviderTest.java   
@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());
}
项目:vaadin-grid-util    文件:GridCellFilter.java   
private void refreshFilters() {
    dataProvider.clearFilters();
    SerializablePredicate<T> filter = null;
    for (Entry<String, SerializablePredicate> entry :
            assignedFilters.entrySet()) {
        final String columnId = entry.getKey();
        SerializablePredicate<T> singleFilter = InMemoryDataProviderHelpers.createValueProviderFilter(propertySet.getProperty(columnId)
                .get()
                .getGetter(), 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);
    }
}
项目:GridExtensionPack    文件:PagedDataProviderTest.java   
@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());
}
项目:GridExtensionPack    文件:PagedDataProviderTest.java   
@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());
}
项目:easybinder    文件:BinderAdapter.java   
@Override
public Binder<BEAN> withValidator(SerializablePredicate<BEAN> predicate, String message) {
    throw new UnsupportedOperationException("Not supported");
}
项目:easybinder    文件:BinderAdapter.java   
@Override
public Binder<BEAN> withValidator(SerializablePredicate<BEAN> predicate,
        ErrorMessageProvider errorMessageProvider) {
    throw new UnsupportedOperationException("Not supported");
}
项目:holon-vaadin    文件:SingleSelectField.java   
@SuppressWarnings("unchecked")
public void setItemEnabledProvider(SerializablePredicate<T> itemEnabledProvider) {
    if (getInternalField() instanceof RadioButtonGroup) {
        ((RadioButtonGroup<T>) getInternalField()).setItemEnabledProvider(itemEnabledProvider);
    }
}
项目:holon-vaadin    文件:MultiSelectField.java   
@SuppressWarnings("unchecked")
public void setItemEnabledProvider(SerializablePredicate<T> itemEnabledProvider) {
    if (getInternalField() instanceof CheckBoxGroup) {
        ((CheckBoxGroup<T>) getInternalField()).setItemEnabledProvider(itemEnabledProvider);
    }
}
项目:GridExtensionPack    文件:DemoContentLayout.java   
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);
    }
}
项目:easybinder    文件:BasicBinderValidationStatus.java   
/**
 * Notifies validation status handlers for bindings that pass given filter. The
 * filter should return {@code true} for each {@link BindingValidationStatus}
 * that should be delegated to the status handler in the binding.
 *
 * @see #notifyBindingValidationStatusHandlers()
 *
 * @param filter
 *            the filter to select bindings to run status handling for
 */
@SuppressWarnings("unchecked")
public void notifyBindingValidationStatusHandlers(SerializablePredicate<BindingValidationStatus<?>> filter) {
    bindingStatuses.stream().filter(filter)
            .forEach(s -> ((BasicBinder.EasyBinding<BEAN, ?, ?>) s.getBinding()).getValidationStatusHandler()
                    .statusChange(s));
}
项目:vaadin-fluent-api    文件:FluentCheckBoxGroup.java   
/**
 * @see AbstractMultiSelect#setItemEnabledProvider(SerializablePredicate)
 *
 * @param itemEnabledProvider
 *            the item enabled provider to set, not {@code null}
 * @return this for method chaining
 */
@SuppressWarnings("unchecked")
public default THIS withItemEnabledProvider(SerializablePredicate<VALUE> itemEnabledProvider) {
    ((CheckBoxGroup<VALUE>) this).setItemEnabledProvider(itemEnabledProvider);
    return (THIS) this;
}
项目:vaadin-fluent-api    文件:FluentRadioButtonGroup.java   
/**
 * Sets the item enabled predicate for this radiobutton group. The predicate
 * is applied to each item to determine whether the item should be enabled
 * (true) or disabled (false). Disabled items are displayed as grayed out
 * and the user cannot select them. The default predicate always returns
 * true (all the items are enabled).
 *
 * @param itemEnabledProvider
 *            the item enable predicate, not null
 * @return this for method chaining
 * @see RadioButtonGroup#setItemEnabledProvider(SerializablePredicate)
 */
@SuppressWarnings("unchecked")
public default THIS withItemEnabledProvider(SerializablePredicate<ITEM> itemEnabledProvider) {
    ((RadioButtonGroup<ITEM>) this).setItemEnabledProvider(itemEnabledProvider);
    return (THIS) this;
}
项目:vaadin-grid-util    文件:GridCellFilter.java   
/**
 * 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();
}