Search in sources :

Example 1 with ItemCaptionGenerator

use of com.vaadin.ui.ItemCaptionGenerator in project Eclipse-Kuksa-Automotive-Edge-Extension by max-grzanna.

the class AppsListView method init.

@PostConstruct
public void init() {
    int currentpage = 1;
    int limit = 9;
    int total;
    Page<App> appsList = findByText(serachText.getValue(), comboBox.getValue(), currentpage - 1, limit);
    total = (int) appsList.getTotalElements();
    appslayout = AppGridView.crateAppGridView(appsList, 3);
    navHeaderLayout = new NavHeader().create(VIEW_NAME, VaadinSession.getCurrent().getAttribute("isCurrentUserAdmin").toString());
    mainlayout.addComponent(navHeaderLayout);
    ItemCaptionGenerator<String> icg = new ItemCaptionGenerator<String>() {

        @Override
        public String apply(String item) {
            return appCategoryService.findById(Long.parseLong(item)).getName();
        }
    };
    comboBox.setItemCaptionGenerator(icg);
    comboBox.setItems(appCategoryService.getAllId());
    comboBox.setPlaceholder("Select a category");
    comboBox.setEmptySelectionCaption("All");
    comboBox.setEmptySelectionAllowed(true);
    comboBox.addValueChangeListener(event -> {
        listApps(serachText.getValue(), event.getValue());
    });
    actions = new HorizontalLayout(comboBox, serachText);
    actions.setStyleName("v-actions");
    serachText.setPlaceholder("Search by App Name");
    // Listen changes made by the filter textbox, refresh data from backend
    serachText.addValueChangeListener(event -> {
        listApps(event.getValue(), comboBox.getValue());
    });
    mainlayout.addComponent(actions);
    mainlayout.addComponent(appslayout);
    paginationComponent = createPaginationComponent(total, currentpage, limit);
    mainlayout.addComponent(paginationComponent);
    setCompositionRoot(mainlayout);
}
Also used : App(org.eclipse.kuksa.appstore.model.App) NavHeader(org.eclipse.kuksa.appstore.ui.component.NavHeader) ItemCaptionGenerator(com.vaadin.ui.ItemCaptionGenerator) HorizontalLayout(com.vaadin.ui.HorizontalLayout) PostConstruct(javax.annotation.PostConstruct)

Aggregations

HorizontalLayout (com.vaadin.ui.HorizontalLayout)1 ItemCaptionGenerator (com.vaadin.ui.ItemCaptionGenerator)1 PostConstruct (javax.annotation.PostConstruct)1 App (org.eclipse.kuksa.appstore.model.App)1 NavHeader (org.eclipse.kuksa.appstore.ui.component.NavHeader)1