Search in sources :

Example 1 with Project

use of com.vaadin.flow.component.combobox.test.entity.Project in project flow-components by vaadin.

the class ComboBoxView method storingCustomValues.

private void storingCustomValues() {
    Div message = createMessageDiv("custom-value-message");
    ComboBox<Project> comboBox = new ComboBox<>("Project");
    comboBox.setItems(this::fetchProjects, this::countProjects);
    comboBox.setItemLabelGenerator(Project::getName);
    comboBox.addValueChangeListener(valueChangeEvent -> {
        if (valueChangeEvent.getValue() == null) {
            message.setText("No project selected");
        } else {
            message.setText("Selected value: " + valueChangeEvent.getValue());
        }
    });
    comboBox.addCustomValueSetListener(event -> {
        Project project = projectData.addProject(event.getDetail());
        comboBox.setValue(project);
    });
    addCard("Storing custom values", comboBox, message);
}
Also used : Div(com.vaadin.flow.component.html.Div) Project(com.vaadin.flow.component.combobox.test.entity.Project) ComboBox(com.vaadin.flow.component.combobox.ComboBox)

Example 2 with Project

use of com.vaadin.flow.component.combobox.test.entity.Project in project flow-components by vaadin.

the class ProjectData method addProject.

public Project addProject(String name) {
    int id = PROJECT_LIST.size() + 1;
    Project newProject = new Project(id, name);
    PROJECT_LIST.add(newProject);
    return newProject;
}
Also used : Project(com.vaadin.flow.component.combobox.test.entity.Project)

Example 3 with Project

use of com.vaadin.flow.component.combobox.test.entity.Project in project flow-components by vaadin.

the class ProjectData method createProjectList.

private List<Project> createProjectList() {
    List<Project> projectList = new ArrayList<>();
    projectList.add(new Project(1, "Apollo"));
    projectList.add(new Project(2, "Aquarius"));
    projectList.add(new Project(3, "Polar"));
    return projectList;
}
Also used : Project(com.vaadin.flow.component.combobox.test.entity.Project) ArrayList(java.util.ArrayList)

Aggregations

Project (com.vaadin.flow.component.combobox.test.entity.Project)3 ComboBox (com.vaadin.flow.component.combobox.ComboBox)1 Div (com.vaadin.flow.component.html.Div)1 ArrayList (java.util.ArrayList)1