本文整理汇总了Java中com.vaadin.data.provider.ListDataProvider类的典型用法代码示例。如果您正苦于以下问题:Java ListDataProvider类的具体用法?Java ListDataProvider怎么用?Java ListDataProvider使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ListDataProvider类属于com.vaadin.data.provider包,在下文中一共展示了ListDataProvider类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test
import com.vaadin.data.provider.ListDataProvider; //导入依赖的package包/类
@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());
}
示例2: testItems
import com.vaadin.data.provider.ListDataProvider; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void testItems() {
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));
FNativeSelect<Person> select = new FNativeSelect<Person>().withCaption("My NativeSelect", true)
.withWidth(300, Unit.PIXELS)
.withItems(p1, p2, p3)
.withEmptySelectionAllowed(false)
.withEmptySelectionCaption("empty")
.withItemCaptionGenerator(p -> p.getName())
.withVisibleItemCount(5);
assertEquals("My NativeSelect", select.getCaption());
assertTrue(select.isCaptionAsHtml());
assertEquals(300, select.getWidth(), 0);
assertEquals(Unit.PIXELS, select.getWidthUnits());
assertFalse(select.isEmptySelectionAllowed());
assertEquals("empty", select.getEmptySelectionCaption());
assertEquals(5, select.getVisibleItemCount());
assertEquals(3, ((ListDataProvider<Person>) select.getDataProvider()).getItems().size());
}
示例3: testDataProvider
import com.vaadin.data.provider.ListDataProvider; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void testDataProvider() {
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));
List<Person> persons = Arrays.asList(p1, p2, p3);
ListDataProvider<Person> dataProvider = DataProvider.ofCollection(persons);
FNativeSelect<Person> select = new FNativeSelect<Person>().withCaption("My NativeSelect")
.withWidth(300, Unit.PIXELS)
.withDataProvider(dataProvider);
assertEquals("My NativeSelect", select.getCaption());
assertFalse(select.isCaptionAsHtml());
assertEquals(300, select.getWidth(), 0);
assertEquals(Unit.PIXELS, select.getWidthUnits());
assertEquals(3, ((ListDataProvider<Person>) select.getDataProvider()).getItems().size());
}
示例4: testDataProvider
import com.vaadin.data.provider.ListDataProvider; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void testDataProvider() {
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));
List<Person> persons = Arrays.asList(p1, p2, p3);
ListDataProvider<Person> dataProvider = DataProvider.ofCollection(persons);
FComboBox<Person> combBox = new FComboBox<Person>().withCaption("My ComboBox")
.withWidth(300, Unit.PIXELS)
.withDataProvider(
(item, filterText) -> item.toLowerCase().contains(filterText.toLowerCase()),
dataProvider);
assertEquals("My ComboBox", combBox.getCaption());
assertFalse(combBox.isCaptionAsHtml());
assertEquals(300, combBox.getWidth(), 0);
assertEquals(Unit.PIXELS, combBox.getWidthUnits());
assertEquals(3, ((ListDataProvider<Person>) combBox.getDataProvider()).getItems().size());
}
示例5: selectAll
import com.vaadin.data.provider.ListDataProvider; //导入依赖的package包/类
@Override
public void selectAll(final String filter) {
final ListDataProvider<T> listDataProvider = ((ListDataProvider) getDataProvider());
final Set<String> addedItems = listDataProvider.getItems()
.stream()
.filter(t -> {
final String caption = getItemCaptionGenerator().apply(t);
if (t == null) {
return false;
}
return caption.toLowerCase()
.contains(filter.toLowerCase());
})
.map(t -> itemToKey(t))
.collect(Collectors.toSet());
updateSelection(addedItems, new HashSet<>(), true);
}
示例6: clear
import com.vaadin.data.provider.ListDataProvider; //导入依赖的package包/类
@Override
public void clear(final String filter) {
final ListDataProvider<T> listDataProvider = ((ListDataProvider) getDataProvider());
final Set<String> removedItems = listDataProvider.getItems()
.stream()
.filter(t -> {
final String caption = getItemCaptionGenerator().apply(t);
if (t == null) {
return false;
}
return caption.toLowerCase()
.contains(filter.toLowerCase());
})
.map(t -> itemToKey(t))
.collect(Collectors.toSet());
updateSelection(new HashSet<>(), removedItems, true);
}
示例7: internalSetDataProvider
import com.vaadin.data.provider.ListDataProvider; //导入依赖的package包/类
@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;
}
示例8: GridWithGridListener
import com.vaadin.data.provider.ListDataProvider; //导入依赖的package包/类
public GridWithGridListener() {
setCaption("Grid with Grid specific listener");
setHeightByRows(3);
final GridContextMenu<String[]> gridContextMenu = new GridContextMenu<>(this);
addColumn(arr -> arr[0]).setCaption("Column 1(right-click here)");
addColumn(arr -> arr[1]).setCaption("Column 2(right-click here)");
final ListDataProvider<String[]> dataSource = new ListDataProvider<>(
Collections.singletonList(new String[]{"foo", "bar"}));
setDataProvider(dataSource);
gridContextMenu.addGridHeaderContextMenuListener(e -> {
gridContextMenu.removeItems();
gridContextMenu.addItem(getText(e), null);
});
gridContextMenu.addGridBodyContextMenuListener(e -> {
gridContextMenu.removeItems();
gridContextMenu.addItem(getText(e), null);
});
}
示例9: GridCellFilter
import com.vaadin.data.provider.ListDataProvider; //导入依赖的package包/类
/**
* keeps link to Grid and added HeaderRow<br>
* afterwards you need to set filter specification for each row<br>
* please take care that your Container implements Filterable!
*
* @param grid that should get added a HeaderRow that this component will manage
*/
public GridCellFilter(Grid<T> grid, Class<T> beanType) {
this.grid = grid;
filterHeaderRow = grid.appendHeaderRow();
cellFilters = new HashMap<>();
assignedFilters = new HashMap<>();
cellFilterChangedListeners = new ArrayList<>();
if (!(grid.getDataProvider() instanceof ListDataProvider)) {
throw new RuntimeException("works only with ListDataProvider");
} else {
dataProvider = (ListDataProvider<T>) grid.getDataProvider();
propertySet = BeanPropertySet.get(beanType);
}
}
示例10: refreshColumnSummary
import com.vaadin.data.provider.ListDataProvider; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private <ITEM, RENDERER_TYPE, PROPERTY_TYPE> void refreshColumnSummary(Grid<ITEM> grid,
ColumnDefinition definition) {
FooterCell footerCell = grid.getFooterRow(0).getCell(definition.getPropertyName());
footerCell.setStyleName(definition.getColumnAlignment().getAlignmentName());
if (definition.isStaticTextSummarizable()) {
String translatedStaticText = gridConfigurationProvider
.resolveTranslationKey(definition.getStaticTextSummarizerTranslationKey());
footerCell.setText(translatedStaticText);
} else {
Summarizer<PROPERTY_TYPE> summarizerFor = getSummarizerFor(definition);
if (ListDataProvider.class.isAssignableFrom(grid.getDataProvider().getClass())) {
ListDataProvider<ITEM> dataProvider = ListDataProvider.class.cast(grid.getDataProvider());
List<PROPERTY_TYPE> propertyValues = (List<PROPERTY_TYPE>) dataProvider.getItems().stream()
.map(item -> invokeRead(definition.getReadMethod(), item)).collect(Collectors.toList());
if (summarizerFor.canSummarize(definition, propertyValues)) {
String summaryText = summarizerFor.summarize(definition, propertyValues);
footerCell.setText(summaryText);
} else {
footerCell.setText("-");
}
}
}
}
示例11: testItems
import com.vaadin.data.provider.ListDataProvider; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void testItems() {
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));
FComboBox<Person> combBox = new FComboBox<Person>().withCaption("My ComboBox", true)
.withWidth(300, Unit.PIXELS)
.withItems(p1, p2, p3)
.withEmptySelectionAllowed(false)
.withEmptySelectionCaption("empty")
.withItemCaptionGenerator(p -> p.getName())
.withItemIconGenerator(p -> VaadinIcons.USER)
.withPageLength(5)
.withPlaceholder("select")
.withTextInputAllowed(false);
assertEquals("My ComboBox", combBox.getCaption());
assertTrue(combBox.isCaptionAsHtml());
assertEquals(300, combBox.getWidth(), 0);
assertEquals(Unit.PIXELS, combBox.getWidthUnits());
assertFalse(combBox.isEmptySelectionAllowed());
assertFalse(combBox.isTextInputAllowed());
assertEquals("empty", combBox.getEmptySelectionCaption());
assertEquals("select", combBox.getPlaceholder());
assertEquals(5, combBox.getPageLength());
assertEquals(3, ((ListDataProvider<Person>) combBox.getDataProvider()).getItems().size());
}
示例12: setItems
import com.vaadin.data.provider.ListDataProvider; //导入依赖的package包/类
/**
* {@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 items the 10 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<>()));
}
示例13: GridWithGenericListener
import com.vaadin.data.provider.ListDataProvider; //导入依赖的package包/类
public GridWithGenericListener() {
setCaption("Grid with generic listener");
ContextMenu contextMenu2 = new ContextMenu(this, true);
setHeightByRows(3);
addColumn(arr -> arr[0]).setCaption(FIRST_NAME);
addColumn(arr -> arr[1]).setCaption(LAST_NAME);
addColumn(arr -> arr[2]).setCaption(SHOE_SIZE);
ListDataProvider<String[]> ds = new ListDataProvider<>(Collections
.singletonList(new String[] { "John", "Doe", "57" }));
setDataProvider(ds);
contextMenu2.addContextMenuOpenListener(this::onGenericContextMenu);
}
示例14: createGridForGantt
import com.vaadin.data.provider.ListDataProvider; //导入依赖的package包/类
private Grid<Step> createGridForGantt() {
dataProvider = new ListDataProvider<>(new ArrayList<>(gantt.getSteps()));
Grid<Step> grid = new Grid<>(dataProvider);
grid.setWidth(400, Unit.PIXELS);
grid.setHeight(100, Unit.PERCENTAGE);
Column<Step, ?> c = grid.addColumn(Step::getCaption);
c.setSortable(false);
c.setResizable(false);
gantt.setVerticalScrollDelegateTarget(grid);
return grid;
}
示例15: init
import com.vaadin.data.provider.ListDataProvider; //导入依赖的package包/类
@Override
protected void init(VaadinRequest request) {
List<String> items = new ArrayList<>();
for (int i = 0; i < 100; i++) {
items.add("Item #" + (i + 1));
}
ListDataProvider<String> dataprovider = new ListDataProvider<>(items);
ListBuilder<String> listBuilder = new ListBuilder<>("ListBuilder Demo", dataprovider);
listBuilder.setLeftColumnCaption("Available options");
listBuilder.setRightColumnCaption("Current selection");
listBuilder.setRows(15);
listBuilder.setWidth(50, Unit.PERCENTAGE);
listBuilder.addSelectionListener(e -> {
System.err.println("getAddedSelection: " + e.getAddedSelection());
System.err.println("getRemovedSelection: " + e.getRemovedSelection());
System.err.println("getAllSelectedItems: " + e.getAllSelectedItems());
System.err.println("getFirstSelectedItem: " + e.getFirstSelectedItem());
System.err.println("getNewSelection: " + e.getNewSelection());
System.err.println("getOldSelection: " + e.getOldSelection());
Notification.show("Selected items: " + e.getValue(), Type.HUMANIZED_MESSAGE);
});
final VerticalLayout layout = new VerticalLayout();
layout.setStyleName("demoContentLayout");
layout.setSizeFull();
layout.setMargin(false);
layout.setSpacing(false);
layout.addComponent(listBuilder);
layout.setComponentAlignment(listBuilder, Alignment.MIDDLE_CENTER);
setContent(layout);
}