use of com.vaadin.flow.component.grid.Grid in project aire-components by aire-ux.
the class ModuleGridTest method ensureModuleGridContainsDefaultPlugin.
@ViewTest
@SuppressWarnings({ "unchecked", "rawtypes" })
void ensureModuleGridContainsDefaultPlugin(@Context TestContext context, @Context Instantiator instantiator) {
val grid = instantiator.createComponent(ModuleGrid.class);
val $ = context.downTo(grid);
val g = $.selectFirst(Grid.class).get();
assertEquals(g.getDataProvider().size(new Query()), 1);
}
use of com.vaadin.flow.component.grid.Grid in project aire-components by aire-ux.
the class ModuleGrid method populateGrid.
private Grid<Module> populateGrid() {
val grid = new Grid<Module>();
grid.addThemeVariants(GridVariant.LUMO_NO_BORDER);
grid.addItemClickListener(event -> {
setSelectedModule(event.getItem());
});
grid.setMultiSort(true);
grid.setAllRowsVisible(true);
grid.setColumnReorderingAllowed(true);
grid.addComponentColumn((ValueProvider<Module, ModuleLifecycleButtonBar>) module -> new ModuleLifecycleButtonBar(getModuleLifecycleDelegate(), getZephyr(), module)).setResizable(true).setHeader("Lifecycle");
grid.addColumn((ValueProvider<Module, String>) module -> module.getCoordinate().getGroup()).setSortable(true).setResizable(true).setHeader("Group");
grid.addColumn((ValueProvider<Module, String>) module -> module.getCoordinate().getName()).setSortable(true).setResizable(true).setHeader("Name");
grid.addColumn((ValueProvider<Module, String>) module -> module.getCoordinate().getVersion().toString()).setHeader("Version");
grid.addColumn(new ComponentRenderer<>(Span::new, new StatusComponentUpdater())).setHeader("Status");
grid.setItems(new ListDataProvider<>(getZephyr().getPlugins()));
grid.getStyle().set("overflow-y", "auto");
return grid;
}
use of com.vaadin.flow.component.grid.Grid in project flow-components by vaadin.
the class GridSelectionTest method multiSelectionListeners.
@Test
public void multiSelectionListeners() {
Grid<String> grid = new Grid<>();
grid.setSelectionMode(SelectionMode.MULTI);
Set<String> oldSelection = new LinkedHashSet<>();
Set<String> selection = new LinkedHashSet<>(Arrays.asList("0", "1", "2"));
AtomicInteger selectionListenerCalled = new AtomicInteger();
grid.addSelectionListener(event -> {
selectionListenerCalled.incrementAndGet();
Assert.assertEquals(selection, event.getAllSelectedItems());
});
AtomicInteger valueChangeListenerCalled = new AtomicInteger();
grid.asMultiSelect().addValueChangeListener(event -> {
valueChangeListenerCalled.incrementAndGet();
Assert.assertEquals(oldSelection, event.getOldValue());
Assert.assertEquals(selection, event.getValue());
});
AtomicInteger multiSelectionListenerCalled = new AtomicInteger();
((GridMultiSelectionModel<String>) grid.getSelectionModel()).addMultiSelectionListener(event -> {
multiSelectionListenerCalled.incrementAndGet();
Assert.assertEquals(oldSelection, event.getOldSelection());
Assert.assertEquals(selection, event.getNewSelection());
Set<String> oldCopy = new LinkedHashSet<>(oldSelection);
Set<String> copy = new LinkedHashSet<>(selection);
oldCopy.removeAll(copy);
Assert.assertEquals(oldCopy, event.getRemovedSelection());
oldCopy = new LinkedHashSet<>(oldSelection);
copy.removeAll(oldCopy);
Assert.assertEquals(copy, event.getAddedSelection());
});
grid.asMultiSelect().setValue(selection);
oldSelection.addAll(selection);
selection.clear();
selection.addAll(Arrays.asList("10", "1", "5"));
grid.asMultiSelect().setValue(selection);
Assert.assertEquals(2, selectionListenerCalled.get());
Assert.assertEquals(2, valueChangeListenerCalled.get());
Assert.assertEquals(2, multiSelectionListenerCalled.get());
}
use of com.vaadin.flow.component.grid.Grid in project flow-components by vaadin.
the class GridUpdateDataProviderPage method createBasicGrid.
private void createBasicGrid() {
Grid<String> grid = new Grid<>();
grid.setId("basic-grid");
DataProvider<String, ?> orig = DataProvider.fromCallbacks(query -> IntStream.range(query.getOffset(), query.getOffset() + query.getLimit()).mapToObj(Integer::toString), query -> 10000);
DataProvider<String, ?> updated = DataProvider.ofItems("foo", "foob", "fooba", "foobar");
grid.setDataProvider(orig);
grid.addColumn(i -> i).setHeader("text");
grid.addColumn(i -> String.valueOf(i.length())).setHeader("length");
NativeButton updateProvider = new NativeButton("Use another provider", event -> swapDataProviders(grid, orig, updated));
updateProvider.setId("update-basic-provider");
add(new H2("Basic grid"), grid, updateProvider);
}
use of com.vaadin.flow.component.grid.Grid in project flow-components by vaadin.
the class GridViewBasicFeaturesPage method createBasicFeatures.
private void createBasicFeatures() {
final int baseYear = 2015;
final int numberOfYears = 5;
DecimalFormat dollarFormat = new DecimalFormat("$#,##0.00");
Grid<CompanyBudgetHistory> grid = new Grid<>();
ListDataProvider<CompanyBudgetHistory> list = CompanyBudgetHistory.getBudgetDataProvider(baseYear, numberOfYears);
grid.setDataProvider(list);
grid.setColumnReorderingAllowed(true);
Column<CompanyBudgetHistory> companyNameColumn = grid.addColumn(CompanyBudgetHistory::getCompany).setHeader("Company");
companyNameColumn.setWidth("200px");
grid.setSelectionMode(SelectionMode.SINGLE);
HeaderRow topHeader = grid.prependHeaderRow();
IntStream.range(baseYear, baseYear + numberOfYears).forEach(year -> {
BigDecimal firstHalfSum = list.fetch(new Query<>()).collect(Collectors.toList()).stream().map(budgetHistory -> budgetHistory.getFirstHalfOfYear(year)).reduce(BigDecimal.ZERO, BigDecimal::add);
BigDecimal secondHalfSum = list.fetch(new Query<>()).collect(Collectors.toList()).stream().map(budgetHistory -> budgetHistory.getSecondHalfOfYear(year)).reduce(BigDecimal.ZERO, BigDecimal::add);
Column<?> firstHalfColumn = grid.addColumn(new NumberRenderer<>(budgetHistory -> budgetHistory.getFirstHalfOfYear(year), dollarFormat)).setHeader("H1").setTextAlign(ColumnTextAlign.END).setFooter(dollarFormat.format(firstHalfSum)).setComparator((p1, p2) -> p1.getFirstHalfOfYear(year).compareTo(p2.getFirstHalfOfYear(year)));
Column<?> secondHalfColumn = grid.addColumn(new NumberRenderer<>(budgetHistory -> budgetHistory.getSecondHalfOfYear(year), dollarFormat)).setHeader("H2").setTextAlign(ColumnTextAlign.END).setFooter(dollarFormat.format(secondHalfSum)).setComparator((p1, p2) -> p1.getSecondHalfOfYear(year).compareTo(p2.getSecondHalfOfYear(year)));
topHeader.join(firstHalfColumn, secondHalfColumn).setText(year + "");
});
HeaderRow filteringHeader = grid.appendHeaderRow();
TextField filteringField = new TextField();
filteringField.addValueChangeListener(event -> {
list.setFilter(CompanyBudgetHistory::getCompany, company -> {
if (company == null) {
return false;
}
String companyLower = company.toLowerCase(Locale.ENGLISH);
String filterLower = event.getValue().toLowerCase(Locale.ENGLISH);
return companyLower.contains(filterLower);
});
});
filteringField.setPlaceholder("Filter");
filteringField.setWidth("100%");
filteringHeader.getCell(companyNameColumn).setComponent(filteringField);
grid.setId("grid-basic-feature");
addCard("Basic Features", "Grid Basic Features Demo", grid);
}
Aggregations