use of com.vaadin.flow.component.combobox.ComboBox in project flow-components by vaadin.
the class ClientSideFilterPage method createInMemoryComboBox.
private void createInMemoryComboBox() {
ComboBox<String> inMemoryComboBox = new ComboBox<>("InMemory");
inMemoryComboBox.setId(IN_MEMORY_COMBO_BOX);
ComboBoxListDataView<String> listDataView = inMemoryComboBox.setItems(IntStream.range(0, inMemoryComboBox.getPageSize() * 2).mapToObj(i -> "Item " + i).collect(Collectors.toList()));
Span itemCountSpan = new Span("0");
itemCountSpan.setId(IN_MEMORY_COMBO_BOX_ITEM_COUNT_SPAN_ID);
this.add(itemCountSpan);
addListener(itemCountSpan, listDataView);
this.add(inMemoryComboBox);
}
use of com.vaadin.flow.component.combobox.ComboBox in project flow-components by vaadin.
the class DialogWithShortcutPage method createAndOpenDialog.
private Dialog createAndOpenDialog(boolean listenOnDialog, boolean preventDefault) {
int index = dialogCounter++;
final String dialogId = DIALOG_ID + index;
NativeButton myDialogButton = createDialogButton();
myDialogButton.setId(dialogId + "-button");
final ComboBox<String> comboBox = new ComboBox<>();
comboBox.setItems("foo", "bar", "xxx");
Dialog dialog = new Dialog(new Div(new Div(new Text("" + index)), myDialogButton, new Input(), comboBox));
NativeButton closeButton = new NativeButton("Close", buttonClickEvent -> dialog.close());
dialog.add(closeButton);
dialog.setDraggable(true);
dialog.open();
dialog.setId(dialogId);
final ShortcutRegistration registration = myDialogButton.addClickShortcut(SHORTCUT_KEY);
if (listenOnDialog) {
registration.listenOn(dialog);
}
registration.setBrowserDefaultAllowed(!preventDefault);
return dialog;
}
use of com.vaadin.flow.component.combobox.ComboBox in project flow-components by vaadin.
the class MainView method createEditorColumns.
protected void createEditorColumns() {
Div itemDisplayPanel = new Div();
Div subPropertyDisplayPanel = new Div();
subPropertyDisplayPanel.setId("prop-panel");
Div eventsPanel = new Div();
eventsPanel.setId("events-panel");
GridPro<Person> grid = new GridPro<>();
Button disableGrid = new Button("Disable Grid");
disableGrid.setId("disable-grid-id");
List<City> cityList = createCityItems();
List<Person> personList = createItems();
mapLists(personList, cityList);
grid.setItems(personList);
grid.addCellEditStartedListener(e -> eventsPanel.add(e.getItem().toString()));
grid.addColumn(Person::getAge).setHeader("Age");
grid.addEditColumn(Person::getName, "name").text((item, newValue) -> {
item.setName(newValue);
itemDisplayPanel.setText(item.toString());
subPropertyDisplayPanel.setText(newValue);
}).setHeader("Name").setWidth("300px");
ComboBox<Department> cb = new ComboBox<>();
cb.setItems(Department.values());
grid.addEditColumn(Person::getDepartment).custom(cb, (item, newValue) -> {
item.setDepartment(newValue);
itemDisplayPanel.setText(item.toString());
subPropertyDisplayPanel.setText(String.valueOf(newValue));
}).setHeader("Department").setWidth("300px");
ComponentRenderer<Span, Person> booleanRenderer = new ComponentRenderer<>(person -> new Span(person.isSubscriber() ? "Yes" : "No"));
grid.addEditColumn(Person::isSubscriber, booleanRenderer).checkbox((item, newValue) -> {
item.setSubscriber(newValue);
itemDisplayPanel.setText(item.toString());
subPropertyDisplayPanel.setText(newValue.toString());
}).setHeader("Subscriber").setWidth("300px");
ComboBox<City> cityCb = new ComboBox<>();
cityCb.setItems(cityList);
cityCb.setItemLabelGenerator(City::getName);
ComponentRenderer<Span, Person> cityRenderer = new ComponentRenderer<>(person -> {
if (person.getCity() != null) {
return new Span(person.getCity().getName());
} else {
return new Span("");
}
});
grid.addEditColumn(Person::getCity, cityRenderer).custom(cityCb, (item, newValue) -> {
item.setCity(newValue);
newValue.setPerson(item);
itemDisplayPanel.setText(item.toString());
subPropertyDisplayPanel.setText(newValue.toString());
}).setHeader("City").setWidth("300px");
Input customField = new Input();
grid.addEditColumn(Person::getEmail).custom(customField, (item, newValue) -> item.setEmail(newValue)).setHeader("Email").setWidth("300px");
disableGrid.addClickListener(click -> grid.setEnabled(false));
add(grid, itemDisplayPanel, subPropertyDisplayPanel, eventsPanel, disableGrid);
}
use of com.vaadin.flow.component.combobox.ComboBox in project vaadin-spinkit by mcollovati.
the class DemoUI method spinnersContainer.
private Component spinnersContainer() {
List<Spinner> spinners = Stream.of(SpinnerType.values()).filter(t -> !t.isAlias()).map(DemoUI::createSpinner).collect(Collectors.toList());
FlexibleGridLayout spinnersContainer = new FlexibleGridLayout().withColumns(Repeat.RepeatMode.AUTO_FILL, new Length("25%")).withPadding(true).withSpacing(true).withItems(spinners.stream().map(s -> spinnerWithName(s, Spinner::getType)).toArray(Component[]::new));
TextField color = new TextField("Color (--sk-color)", "#333");
color.addValueChangeListener(e -> spinners.forEach(s -> s.setColor(e.getValue())));
ComboBox<String> theme = new ComboBox<>("Css class", "", "green", "red");
theme.setPreventInvalidInput(true);
theme.addValueChangeListener(e -> spinners.forEach(s -> {
Optional.ofNullable(e.getOldValue()).ifPresent(css -> s.removeClassName("sk-demo-" + css));
s.addClassName("sk-demo-" + e.getValue());
}));
VerticalLayout commands = new VerticalLayout();
commands.setAlignItems(FlexComponent.Alignment.START);
commands.setMargin(false);
commands.setSpacing(true);
commands.add(color, theme);
commands.setSizeUndefined();
VHorizontalLayout layout = new VHorizontalLayout(commands, spinnersContainer);
layout.setSizeFull();
layout.setMargin(true);
layout.setSpacing(true);
layout.setFlexGrow(1, spinnersContainer);
return layout;
}
Aggregations