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;
}
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;
}
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");
}
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);
}
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);
}
Aggregations