Example usage for com.vaadin.ui ComboBox getDataProvider

List of usage examples for com.vaadin.ui ComboBox getDataProvider

Introduction

In this page you can find the example usage for com.vaadin.ui ComboBox getDataProvider.

Prototype

@Override
    public DataProvider<T, ?> getDataProvider() 

Source Link

Usage

From source file:dhbw.clippinggorilla.userinterface.views.ClippingView.java

public ClippingView(Clipping clipping) {
    User user = UserUtils.getCurrent();/*  w ww  .j av a  2  s.co m*/

    clippingArticlesLayout = new VerticalLayout();
    clippingArticlesLayout.setSpacing(true);
    clippingArticlesLayout.setMargin(false);
    clippingArticlesLayout.setSizeFull();

    HorizontalLayout clippingOptionsLayout = new HorizontalLayout();
    clippingOptionsLayout.setSpacing(true);
    clippingOptionsLayout.setMargin(false);
    clippingOptionsLayout.setWidth("100%");

    ComboBox<SortOptions> comboBoxSortOptions = new ComboBox<>(Language.get(Word.SORT_BY));
    Language.setCustom(Word.SORT_BY, s -> {
        comboBoxSortOptions.setCaption(s);
        comboBoxSortOptions.getDataProvider().refreshAll();
    });
    comboBoxSortOptions.setItems(EnumSet.allOf(SortOptions.class));
    comboBoxSortOptions.setItemCaptionGenerator(s -> s.getName());
    comboBoxSortOptions.setItemIconGenerator(s -> s.getIcon());
    comboBoxSortOptions.setValue(SortOptions.BYPROFILE);
    comboBoxSortOptions.setTextInputAllowed(false);
    comboBoxSortOptions.setEmptySelectionAllowed(false);
    comboBoxSortOptions.addStyleName("comboboxsort");
    comboBoxSortOptions.addValueChangeListener(e -> {
        switch (e.getValue()) {
        case BYDATE:
            createClippingViewByDate(clipping);
            break;
        case BYPROFILE:
            createClippingViewByProfile(clipping);
            break;
        case BYSOURCE:
            createClippingViewBySource(clipping);
            break;
        }
    });

    Button buttonRegenerateClipping = new Button(VaadinIcons.REFRESH);
    buttonRegenerateClipping.addStyleName(ValoTheme.BUTTON_PRIMARY);
    buttonRegenerateClipping.addClickListener(ce -> {
        user.setLastClipping(ClippingUtils.generateClipping(user, false));
        ClippingGorillaUI.getCurrent().setMainContent(ClippingView.getCurrent());
    });

    clippingOptionsLayout.addComponents(comboBoxSortOptions, buttonRegenerateClipping);
    clippingOptionsLayout.setExpandRatio(comboBoxSortOptions, 5);
    clippingOptionsLayout.setComponentAlignment(buttonRegenerateClipping, Alignment.BOTTOM_CENTER);

    addComponents(clippingOptionsLayout, clippingArticlesLayout);

    createClippingViewByProfile(clipping);
    if (clipping.getArticles().keySet().isEmpty() && clipping.getArticlesFromGroup().keySet().isEmpty()) {
        Label labelNoProfile = new Label();
        Language.setCustom(Word.NO_PROFILE_PRESENT, s -> labelNoProfile.setValue(s));
        labelNoProfile.addStyleName(ValoTheme.LABEL_H2);
        clippingArticlesLayout.addComponent(labelNoProfile);
    }
}