Search in sources :

Example 46 with Grid

use of com.vaadin.flow.component.grid.Grid in project furms by unity-idm.

the class ResourceCreditsView method createResourceCreditGrid.

private Grid<ResourceCreditViewModel> createResourceCreditGrid() {
    Grid<ResourceCreditViewModel> grid = new DenseGrid<>(ResourceCreditViewModel.class);
    grid.addComponentColumn(c -> new RouterLink(c.getName(), ResourceCreditFormView.class, c.getId())).setHeader(getTranslation("view.site-admin.resource-credits.grid.column.name")).setSortable(true).setFlexGrow(20).setComparator(x -> x.getName().toLowerCase());
    grid.addColumn(ResourceCreditViewModel::getId).setHeader(getTranslation("view.site-admin.resource-credits.grid.column.id")).setSortable(true).setFlexGrow(20).setComparator(x -> x.getName().toLowerCase());
    grid.addColumn(ResourceCreditViewModel::getResourceTypeName).setHeader(getTranslation("view.site-admin.resource-credits.grid.column.resourceType")).setSortable(true);
    grid.addColumn(ResourceCreditViewModel::getAmount).setHeader(getTranslation("view.site-admin.resource-credits.grid.column.credit")).setSortable(true).setComparator(comparing(model -> model.getAmount().amount));
    grid.addColumn(ResourceCreditViewModel::getDistributed).setHeader(getTranslation("view.site-admin.resource-credits.grid.column.distributed")).setSortable(true).setComparator(comparing(model -> model.getDistributed().amount));
    grid.addColumn(ResourceCreditViewModel::getRemaining).setHeader(getTranslation("view.site-admin.resource-credits.grid.column.remaining")).setSortable(true).setComparator(comparing(model -> model.getRemaining().amount));
    grid.addColumn(c -> c.getCreateTime().toLocalDate()).setHeader(getTranslation("view.site-admin.resource-credits.grid.column.created")).setSortable(true);
    grid.addColumn(c -> c.getStartTime().toLocalDate()).setHeader(getTranslation("view.site-admin.resource-credits.grid.column.validFrom")).setSortable(true);
    grid.addColumn(c -> c.getEndTime().toLocalDate()).setHeader(getTranslation("view.site-admin.resource-credits.grid.column.validTo")).setSortable(true);
    grid.addComponentColumn(model -> {
        double value = model.getConsumed().divide(model.getAmount().amount, 4, HALF_UP).doubleValue();
        return new FurmsProgressBar(value);
    }).setHeader(getTranslation("view.site-admin.resource-credits.grid.column.consumption")).setComparator(comparing(ResourceCreditViewModel::getConsumed));
    grid.addComponentColumn(this::createLastColumnContent).setHeader(getTranslation("view.site-admin.resource-credits.grid.column.actions")).setWidth("4em").setTextAlign(ColumnTextAlign.END);
    return grid;
}
Also used : VaadinExceptionHandler.handleExceptions(io.imunity.furms.ui.utils.VaadinExceptionHandler.handleExceptions) ResourceGetter.getCurrentResourceId(io.imunity.furms.ui.utils.ResourceGetter.getCurrentResourceId) Component(com.vaadin.flow.component.Component) HorizontalLayout(com.vaadin.flow.component.orderedlayout.HorizontalLayout) FurmsDialog(io.imunity.furms.ui.components.FurmsDialog) MenuButton(io.imunity.furms.ui.components.MenuButton) PageTitle(io.imunity.furms.ui.components.PageTitle) Route(com.vaadin.flow.router.Route) PLUS_CIRCLE(com.vaadin.flow.component.icon.VaadinIcon.PLUS_CIRCLE) DenseGrid(io.imunity.furms.ui.components.DenseGrid) FurmsViewComponent(io.imunity.furms.ui.components.FurmsViewComponent) Map(java.util.Map) RouterLink(com.vaadin.flow.router.RouterLink) UI(com.vaadin.flow.component.UI) Comparator.comparing(java.util.Comparator.comparing) SiteAdminMenu(io.imunity.furms.ui.views.site.SiteAdminMenu) ResourceCreditService(io.imunity.furms.api.resource_credits.ResourceCreditService) Grid(com.vaadin.flow.component.grid.Grid) UIContext(io.imunity.furms.ui.user_context.UIContext) TRASH(com.vaadin.flow.component.icon.VaadinIcon.TRASH) ResourceCreditHasAllocationException(io.imunity.furms.api.validation.exceptions.ResourceCreditHasAllocationException) EDIT(com.vaadin.flow.component.icon.VaadinIcon.EDIT) HALF_UP(java.math.RoundingMode.HALF_UP) GridActionMenu(io.imunity.furms.ui.components.GridActionMenu) GridActionsButtonLayout(io.imunity.furms.ui.components.GridActionsButtonLayout) ZoneId(java.time.ZoneId) Button(com.vaadin.flow.component.button.Button) FurmsProgressBar(io.imunity.furms.ui.components.FurmsProgressBar) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) ColumnTextAlign(com.vaadin.flow.component.grid.ColumnTextAlign) Dialog(com.vaadin.flow.component.dialog.Dialog) Collections(java.util.Collections) ViewHeaderLayout(io.imunity.furms.ui.components.ViewHeaderLayout) RouterLink(com.vaadin.flow.router.RouterLink) DenseGrid(io.imunity.furms.ui.components.DenseGrid) FurmsProgressBar(io.imunity.furms.ui.components.FurmsProgressBar)

Example 47 with Grid

use of com.vaadin.flow.component.grid.Grid in project flow-components by vaadin.

the class SortingPage method createGrid.

private Grid<Person> createGrid(String gridId, String sortBtnId) {
    Grid<Person> grid = new Grid<>();
    grid.setMultiSort(true);
    grid.setId(gridId);
    grid.setItems(new Person("B", 20), new Person("A", 30));
    Column<Person> nameColumn = grid.addColumn(Person::getFirstName).setHeader(new Span("Name"));
    Column<Person> ageColumn = grid.addColumn(Person::getAge).setHeader("Age");
    // Needed to check that sorter is rendered in component header after
    // adding new header row
    grid.appendHeaderRow();
    List<GridSortOrder<Person>> sortByName = new GridSortOrderBuilder<Person>().thenAsc(nameColumn).build();
    grid.sort(sortByName);
    NativeButton button = new NativeButton(sortBtnId.equals("sort-hidden-by-age") ? "Sort hidden by age" : "Sort by age", e -> {
        List<GridSortOrder<Person>> sortByAge = new GridSortOrderBuilder<Person>().thenAsc(ageColumn).build();
        grid.sort(sortByAge);
    });
    button.setId(sortBtnId);
    NativeButton reOrder = new NativeButton("Re-order", e -> {
        grid.setColumnOrder(ageColumn, nameColumn);
    });
    reOrder.setId("reorder-button");
    NativeButton changeHeaderText = new NativeButton("Change header text", e -> {
        ageColumn.setHeader("Age (updated)");
    });
    changeHeaderText.setId("change-header-text");
    NativeButton changeHeaderTextComponent = new NativeButton("Change header text component", e -> {
        ageColumn.setHeader(new Span("Age (updated)"));
    });
    changeHeaderTextComponent.setId("change-header-text-component");
    NativeButton clearButton = new NativeButton("Clear items", e -> grid.setItems(new ArrayList<Person>()));
    clearButton.setId("clear-items");
    add(button, reOrder, changeHeaderText, changeHeaderTextComponent, clearButton);
    return grid;
}
Also used : NativeButton(com.vaadin.flow.component.html.NativeButton) GridSortOrder(com.vaadin.flow.component.grid.GridSortOrder) Grid(com.vaadin.flow.component.grid.Grid) ArrayList(java.util.ArrayList) Person(com.vaadin.flow.data.bean.Person) Span(com.vaadin.flow.component.html.Span) GridSortOrderBuilder(com.vaadin.flow.component.grid.GridSortOrderBuilder)

Example 48 with Grid

use of com.vaadin.flow.component.grid.Grid in project flow-components by vaadin.

the class GridContextMenuTest method setTarget_nullTarget_connectorIsRemovedFromPreviousTarget.

@Test
public void setTarget_nullTarget_connectorIsRemovedFromPreviousTarget() {
    Grid grid = Mockito.mock(Grid.class);
    Element element = Mockito.mock(Element.class);
    StateNode node = Mockito.mock(StateNode.class);
    Mockito.when(grid.getElement()).thenReturn(element);
    Mockito.when(element.getNode()).thenReturn(node);
    DomListenerRegistration registration = Mockito.mock(DomListenerRegistration.class);
    Mockito.when(element.addEventListener(Mockito.anyString(), Mockito.any())).thenReturn(registration);
    Mockito.when(registration.addEventData(Mockito.anyString())).thenReturn(registration);
    Mockito.when(grid.getUI()).thenReturn(Optional.empty());
    Registration attachRegistration = Mockito.mock(Registration.class);
    Mockito.when(grid.addAttachListener(Mockito.any())).thenReturn(attachRegistration);
    GridContextMenu gridContextMenu = new GridContextMenu<>();
    gridContextMenu.setTarget(grid);
    gridContextMenu.setTarget(null);
    Mockito.verify(registration).remove();
    Mockito.verify(element).callJsFunction("$contextMenuConnector.removeConnector");
}
Also used : Registration(com.vaadin.flow.shared.Registration) DomListenerRegistration(com.vaadin.flow.dom.DomListenerRegistration) Grid(com.vaadin.flow.component.grid.Grid) Element(com.vaadin.flow.dom.Element) StateNode(com.vaadin.flow.internal.StateNode) DomListenerRegistration(com.vaadin.flow.dom.DomListenerRegistration) Test(org.junit.Test)

Example 49 with Grid

use of com.vaadin.flow.component.grid.Grid in project flow-components by vaadin.

the class GridUpdateDataProviderPage method createBeanGrid.

private void createBeanGrid() {
    Grid<Pojo> grid = new Grid<>(Pojo.class);
    grid.setId("bean-grid");
    List<Pojo> orig = Arrays.asList(new Pojo(1, "foo"), new Pojo(2, "bar"));
    List<Pojo> updated = Arrays.asList(new Pojo(1, "FOOBAR"), new Pojo(2, "bar"));
    grid.setItems(orig);
    NativeButton updateProvider = new NativeButton("Use another list", event -> grid.setItems(updated));
    updateProvider.setId("update-bean-provider");
    add(new H2("Bean grid"), grid, updateProvider);
}
Also used : NativeButton(com.vaadin.flow.component.html.NativeButton) Grid(com.vaadin.flow.component.grid.Grid) H2(com.vaadin.flow.component.html.H2)

Example 50 with Grid

use of com.vaadin.flow.component.grid.Grid in project flow-components by vaadin.

the class GridViewClickListenersPage method createDoubleClickListener.

private void createDoubleClickListener() {
    Div message = new Div();
    message.setId("doubleclicked-item");
    Grid<Person> grid = new Grid<>();
    grid.setItems(getItems());
    grid.addColumn(Person::getFirstName).setHeader("Name");
    grid.addColumn(Person::getAge).setHeader("Age");
    grid.addItemDoubleClickListener(event -> message.setText("Double Clicked Item: " + event.getItem().getFirstName()));
    grid.setId("item-doubleclick-listener");
    message.addClickListener(event -> message.setText(""));
    addCard("Click Listeners", "Item Double Click Listener", message, grid);
}
Also used : Div(com.vaadin.flow.component.html.Div) Grid(com.vaadin.flow.component.grid.Grid) Person(com.vaadin.flow.data.bean.Person)

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