Search in sources :

Example 1 with Grid

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);
}
Also used : lombok.val(lombok.val) Query(com.vaadin.flow.data.provider.Query) Grid(com.vaadin.flow.component.grid.Grid) ViewTest(com.aire.ux.test.ViewTest)

Example 2 with Grid

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;
}
Also used : lombok.val(lombok.val) ListDataProvider(com.vaadin.flow.data.provider.ListDataProvider) ComponentRenderer(com.vaadin.flow.data.renderer.ComponentRenderer) MenuBar(com.vaadin.flow.component.menubar.MenuBar) Component(com.vaadin.flow.component.Component) CssImport(com.vaadin.flow.component.dependency.CssImport) MenuBarVariant(com.vaadin.flow.component.menubar.MenuBarVariant) SerializableBiConsumer(com.vaadin.flow.function.SerializableBiConsumer) ValueProvider(com.vaadin.flow.function.ValueProvider) Route(com.vaadin.flow.router.Route) Inject(javax.inject.Inject) Overlays(io.sunshower.zephyr.ui.components.Overlays) ComponentValueChangeEvent(com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent) TextField(com.vaadin.flow.component.textfield.TextField) Notification(com.vaadin.flow.component.notification.Notification) ValueChangeMode(com.vaadin.flow.data.value.ValueChangeMode) Zephyr(io.zephyr.cli.Zephyr) Grid(com.vaadin.flow.component.grid.Grid) GridVariant(com.vaadin.flow.component.grid.GridVariant) NotificationVariant(com.vaadin.flow.component.notification.NotificationVariant) NonNull(lombok.NonNull) Position(com.vaadin.flow.component.notification.Notification.Position) lombok.val(lombok.val) VaadinIcon(com.vaadin.flow.component.icon.VaadinIcon) Breadcrumb(io.sunshower.zephyr.ui.controls.Breadcrumb) Collectors(java.util.stream.Collectors) ValueChangeListener(com.vaadin.flow.component.HasValue.ValueChangeListener) Button(com.vaadin.flow.component.button.Button) MainView(io.sunshower.zephyr.MainView) JsModule(com.vaadin.flow.component.dependency.JsModule) Span(com.vaadin.flow.component.html.Span) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) Module(io.zephyr.kernel.Module) ComponentRenderer(com.vaadin.flow.data.renderer.ComponentRenderer) Grid(com.vaadin.flow.component.grid.Grid) JsModule(com.vaadin.flow.component.dependency.JsModule) Module(io.zephyr.kernel.Module) ValueProvider(com.vaadin.flow.function.ValueProvider) Span(com.vaadin.flow.component.html.Span)

Example 3 with 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());
}
Also used : LinkedHashSet(java.util.LinkedHashSet) GridMultiSelectionModel(com.vaadin.flow.component.grid.GridMultiSelectionModel) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Grid(com.vaadin.flow.component.grid.Grid) Test(org.junit.Test)

Example 4 with Grid

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);
}
Also used : IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) List(java.util.List) Grid(com.vaadin.flow.component.grid.Grid) DataProvider(com.vaadin.flow.data.provider.DataProvider) Div(com.vaadin.flow.component.html.Div) NativeButton(com.vaadin.flow.component.html.NativeButton) H2(com.vaadin.flow.component.html.H2) Route(com.vaadin.flow.router.Route) NativeButton(com.vaadin.flow.component.html.NativeButton) Grid(com.vaadin.flow.component.grid.Grid) H2(com.vaadin.flow.component.html.H2)

Example 5 with Grid

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);
}
Also used : IntStream(java.util.stream.IntStream) ListDataProvider(com.vaadin.flow.data.provider.ListDataProvider) Grid(com.vaadin.flow.component.grid.Grid) Query(com.vaadin.flow.data.provider.Query) Collection(java.util.Collection) DecimalFormat(java.text.DecimalFormat) HashMap(java.util.HashMap) SelectionMode(com.vaadin.flow.component.grid.Grid.SelectionMode) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Route(com.vaadin.flow.router.Route) NumberRenderer(com.vaadin.flow.data.renderer.NumberRenderer) BigDecimal(java.math.BigDecimal) Column(com.vaadin.flow.component.grid.Grid.Column) HeaderRow(com.vaadin.flow.component.grid.HeaderRow) Locale(java.util.Locale) Map(java.util.Map) ColumnTextAlign(com.vaadin.flow.component.grid.ColumnTextAlign) TextField(com.vaadin.flow.component.textfield.TextField) DecimalFormat(java.text.DecimalFormat) Grid(com.vaadin.flow.component.grid.Grid) BigDecimal(java.math.BigDecimal) HeaderRow(com.vaadin.flow.component.grid.HeaderRow) TextField(com.vaadin.flow.component.textfield.TextField)

Aggregations

Grid (com.vaadin.flow.component.grid.Grid)73 Route (com.vaadin.flow.router.Route)41 Div (com.vaadin.flow.component.html.Div)38 List (java.util.List)26 NativeButton (com.vaadin.flow.component.html.NativeButton)22 Person (com.vaadin.flow.data.bean.Person)22 ComponentRenderer (com.vaadin.flow.data.renderer.ComponentRenderer)21 H2 (com.vaadin.flow.component.html.H2)17 Collections (java.util.Collections)16 Button (com.vaadin.flow.component.button.Button)15 HorizontalLayout (com.vaadin.flow.component.orderedlayout.HorizontalLayout)14 ArrayList (java.util.ArrayList)13 Collectors (java.util.stream.Collectors)13 Component (com.vaadin.flow.component.Component)12 ColumnTextAlign (com.vaadin.flow.component.grid.ColumnTextAlign)12 Column (com.vaadin.flow.component.grid.Grid.Column)12 Label (com.vaadin.flow.component.html.Label)12 Span (com.vaadin.flow.component.html.Span)11 TextField (com.vaadin.flow.component.textfield.TextField)10 DenseGrid (io.imunity.furms.ui.components.DenseGrid)10