use of com.vaadin.flow.component.checkbox.Checkbox in project flow-components by vaadin.
the class GridViewEditorPage method createNotBufferedEditor.
private void createNotBufferedEditor() {
Div message = new Div();
message.setId("not-buffered-editor-msg");
Grid<Person> grid = new Grid<>();
List<Person> persons = getItems();
grid.setItems(persons);
Column<Person> nameColumn = grid.addColumn(Person::getFirstName).setHeader("Name");
Column<Person> subscriberColumn = grid.addColumn(Person::isSubscriber).setHeader("Subscriber");
Binder<Person> binder = new Binder<>(Person.class);
grid.getEditor().setBinder(binder);
TextField field = new TextField();
// Close the editor in case of backward between components
field.getElement().addEventListener("keydown", event -> grid.getEditor().closeEditor()).setFilter("event.key === 'Tab' && event.shiftKey");
binder.bind(field, "firstName");
nameColumn.setEditorComponent(field);
Checkbox checkbox = new Checkbox();
binder.bind(checkbox, "subscriber");
subscriberColumn.setEditorComponent(checkbox);
// Close the editor in case of forward navigation between
checkbox.getElement().addEventListener("keydown", event -> grid.getEditor().closeEditor()).setFilter("event.key === 'Tab' && !event.shiftKey");
grid.addItemDoubleClickListener(event -> {
grid.getEditor().editItem(event.getItem());
field.focus();
});
grid.addItemClickListener(event -> {
if (binder.getBean() != null) {
message.setText(binder.getBean().getFirstName() + ", " + binder.getBean().isSubscriber());
}
});
grid.setId("not-buffered-editor");
addCard("Grid Editor", "Editor in Not Buffered Mode", message, grid);
}
use of com.vaadin.flow.component.checkbox.Checkbox in project flow-components by vaadin.
the class GridViewSortingPage method createSorting.
private void createSorting() {
Div messageDiv = new Div();
Grid<Person> grid = new Grid<>();
grid.setItems(getItems());
grid.setSelectionMode(SelectionMode.NONE);
grid.addColumn(Person::getFirstName, "firstName").setHeader("Name");
grid.addColumn(Person::getAge, "age").setHeader("Age");
grid.addColumn(TemplateRenderer.<Person>of("<div>[[item.street]], number [[item.number]]<br><small>[[item.postalCode]]</small></div>").withProperty("street", person -> person.getAddress().getStreet()).withProperty("number", person -> person.getAddress().getNumber()).withProperty("postalCode", person -> person.getAddress().getPostalCode()), "street", "number").setHeader("Address");
Checkbox multiSort = new Checkbox("Multiple column sorting enabled");
multiSort.addValueChangeListener(event -> grid.setMultiSort(event.getValue()));
grid.addSortListener(event -> {
String currentSortOrder = grid.getDataCommunicator().getBackEndSorting().stream().map(querySortOrder -> String.format("{sort property: %s, direction: %s}", querySortOrder.getSorted(), querySortOrder.getDirection())).collect(Collectors.joining(", "));
messageDiv.setText(String.format("Current sort order: %s. Sort originates from the client: %s.", currentSortOrder, event.isFromClient()));
});
// you can set the sort order from server-side with the grid.sort method
NativeButton invertAllSortings = new NativeButton("Invert all sort directions", event -> {
List<GridSortOrder<Person>> orderList = grid.getSortOrder();
List<GridSortOrder<Person>> newOrderList = new ArrayList<>(orderList.size());
for (GridSortOrder<Person> sort : orderList) {
newOrderList.add(new GridSortOrder<>(sort.getSorted(), sort.getDirection().getOpposite()));
}
grid.sort(newOrderList);
});
NativeButton resetAllSortings = new NativeButton("Reset all sortings", event -> grid.sort(null));
grid.setId("grid-sortable-columns");
multiSort.setId("grid-multi-sort-toggle");
invertAllSortings.setId("grid-sortable-columns-invert-sortings");
resetAllSortings.setId("grid-sortable-columns-reset-sortings");
messageDiv.setId("grid-sortable-columns-message");
addCard("Sorting", "Grid with sortable columns", grid, multiSort, invertAllSortings, resetAllSortings, messageDiv);
}
use of com.vaadin.flow.component.checkbox.Checkbox in project flow-components by vaadin.
the class CheckboxDemoPage method addDisabledCheckbox.
private void addDisabledCheckbox() {
Div message = new Div();
message.setId("disabled-checkbox-message");
Checkbox disabledCheckbox = new Checkbox("Disabled Checkbox");
disabledCheckbox.setValue(true);
disabledCheckbox.setEnabled(false);
disabledCheckbox.addClickListener(evt -> message.setText("Checkbox " + evt.getSource().getLabel() + " was clicked, but the component is disabled and this shouldn't happen!"));
addCard("Disabled Checkbox", disabledCheckbox, message);
disabledCheckbox.setId("disabled-checkbox");
}
use of com.vaadin.flow.component.checkbox.Checkbox in project flow-components by vaadin.
the class CheckboxDemoPage method addIndeterminateCheckbox.
private void addIndeterminateCheckbox() {
Checkbox indeterminateCheckbox = new Checkbox("Indeterminate Checkbox");
indeterminateCheckbox.setIndeterminate(true);
NativeButton button = new NativeButton("Reset", event -> {
indeterminateCheckbox.setValue(false);
indeterminateCheckbox.setIndeterminate(true);
});
button.setId("reset-indeterminate");
addCard("Indeterminate Checkbox", indeterminateCheckbox, button);
indeterminateCheckbox.setId("indeterminate-checkbox");
}
use of com.vaadin.flow.component.checkbox.Checkbox in project flow-components by vaadin.
the class CheckboxDemoPage method addAccessibleCheckbox.
private void addAccessibleCheckbox() {
Checkbox accessibleCheckbox = new Checkbox("Accessible Checkbox");
accessibleCheckbox.setAriaLabel("Click me");
addCard("Checkbox with Custom Accessible Label", accessibleCheckbox);
accessibleCheckbox.setId("accessible-checkbox");
}
Aggregations