Example usage for com.vaadin.ui ComboBox setItemIconGenerator

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

Introduction

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

Prototype

@Override
    public void setItemIconGenerator(IconGenerator<T> itemIconGenerator) 

Source Link

Usage

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

public ClippingView(Clipping clipping) {
    User user = UserUtils.getCurrent();/*from  w  w w.j  a  v a2s .  c  om*/

    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);
    }
}

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

public FooterBar() {
    setColumns(6);//  w ww .  j a v  a2  s .c o m
    setRows(1);
    addStyleName("menubar");
    setWidth("100%");
    setHeightUndefined();
    setColumnExpandRatio(4, 5);
    setSpacing(true);
    setMargin(true);

    Image logo = new Image();
    try {
        logo.setSource(new FileResource(FileUtils.getFile("images/logo_small.png").toFile()));
    } catch (FileNotFoundException ex) {
        Log.error("Could not find logo!", ex);
    }
    logo.setHeight("100%");
    addComponent(logo);
    setComponentAlignment(logo, Alignment.MIDDLE_CENTER);

    Button aboutUs = new Button();
    Language.set(Word.ABOUT_US, aboutUs);
    aboutUs.addClickListener((ce) -> {
        ClippingGorillaUI.getCurrent().setMainContent(AboutUsView.getCurrent());
    });
    aboutUs.setIcon(VaadinIcons.USERS);
    aboutUs.addStyleName(ValoTheme.BUTTON_BORDERLESS);
    addComponent(aboutUs);
    setComponentAlignment(aboutUs, Alignment.MIDDLE_CENTER);

    Button docs = new Button();
    Language.set(Word.DOCUMENTS, docs);
    docs.addClickListener(ce -> {
        ClippingGorillaUI.getCurrent().setMainContent(DocumentsView.getCurrent());
    });
    docs.setIcon(VaadinIcons.ARCHIVE);
    docs.addStyleName(ValoTheme.BUTTON_BORDERLESS);
    addComponent(docs);
    setComponentAlignment(docs, Alignment.MIDDLE_CENTER);

    Button impressum = new Button();
    Language.set(Word.IMPRESSUM, impressum);
    impressum.addClickListener(ce -> {
        ClippingGorillaUI.getCurrent().setMainContent(ImpressumView.getCurrent());
    });
    impressum.setIcon(VaadinIcons.SCALE);
    impressum.addStyleName(ValoTheme.BUTTON_BORDERLESS);
    addComponent(impressum);
    setComponentAlignment(impressum, Alignment.MIDDLE_CENTER);

    Label spacing = new Label();
    addComponent(spacing);
    setComponentAlignment(spacing, Alignment.MIDDLE_CENTER);

    ComboBox<Locale> languages = new ComboBox<>(null, Language.getAllLanguages().keySet());
    languages.setItemCaptionGenerator(loc -> loc.getDisplayLanguage(loc));
    if (!Language.getAllLanguages().containsKey(VaadinSession.getCurrent().getLocale())) {
        languages.setValue(Locale.ENGLISH);
    } else {
        languages.setValue(VaadinSession.getCurrent().getLocale());
    }
    languages.setEmptySelectionAllowed(false);
    languages.setItemIconGenerator(FooterBar::getIcon);
    languages.addValueChangeListener(
            (HasValue.ValueChangeEvent<Locale> loc) -> Language.setLanguage(loc.getValue()));
    languages.setTextInputAllowed(false);
    addComponent(languages);
    setComponentAlignment(languages, Alignment.MIDDLE_CENTER);

    SESSIONS.put(VaadinSession.getCurrent(), this);
}

From source file:dhbw.clippinggorilla.userinterface.windows.NewSourceWindow.java

/**
 * If no value present, choose a empty string
 *
 * @param title/*w  ww.java2  s.c o m*/
 * @param link
 * @param description
 * @param language
 * @param imageUrl
 * @return
 */
private Component getSecondStage(Source s) {
    Label header = new Label(Language.get(Word.SOURCE));
    header.addStyleName(ValoTheme.LABEL_H1);

    FormLayout forms = new FormLayout();
    forms.setSizeFull();

    TextField textFieldId = new TextField(Language.get(Word.ID));
    textFieldId.setEnabled(false);
    textFieldId.setValue(s.getId());
    textFieldId.setWidth("750px");

    TextField textFieldName = new TextField(Language.get(Word.NAME));
    textFieldName.setValue(s.getName());
    textFieldName.setWidth("750px");

    TextField textFieldDescription = new TextField(Language.get(Word.DESCRIPTION));
    textFieldDescription.setValue(s.getDescription());
    textFieldDescription.setWidth("750px");

    TextField textFieldURL = new TextField(Language.get(Word.URL));
    if (s.getUrl() != null) {
        textFieldURL.setValue(s.getUrl().toExternalForm());
    }
    textFieldURL.setWidth("750px");

    ComboBox<Category> comboBoxCategories = new ComboBox<>(Language.get(Word.CATEGORY),
            EnumSet.allOf(Category.class));
    comboBoxCategories.setItemCaptionGenerator(c -> c.getName());
    comboBoxCategories.setItemIconGenerator(c -> c.getIcon());
    comboBoxCategories.setEmptySelectionAllowed(false);
    comboBoxCategories.setTextInputAllowed(false);
    comboBoxCategories.setWidth("375px");
    if (s.getCategory() != null) {
        comboBoxCategories.setSelectedItem(s.getCategory());
    }

    ComboBox<Locale> comboBoxLanguage = new ComboBox<>(Language.get(Word.LANGUAGE), getLanguages());
    comboBoxLanguage.setItemCaptionGenerator(l -> l.getDisplayLanguage(VaadinSession.getCurrent().getLocale()));
    comboBoxLanguage.setEmptySelectionAllowed(false);
    comboBoxLanguage.setWidth("375px");
    if (!s.getLanguage().isEmpty()) {
        Locale selected = new Locale(s.getLanguage());
        comboBoxLanguage.setSelectedItem(selected);
    }

    Locale loc = VaadinSession.getCurrent().getLocale();

    Map<String, Locale> countries = getCountries();
    List<Locale> locales = countries.values().parallelStream()
            .sorted((l1, l2) -> l1.getDisplayCountry(loc).compareTo(l2.getDisplayCountry(loc)))
            .collect(Collectors.toList());
    ComboBox<Locale> comboBoxCountry = new ComboBox<>(Language.get(Word.COUNTRY), locales);
    comboBoxCountry.setItemCaptionGenerator(l -> l.getDisplayCountry(VaadinSession.getCurrent().getLocale()));
    comboBoxCountry.setItemIconGenerator(l -> FamFamFlags.fromLocale(l));
    comboBoxCountry.setEmptySelectionAllowed(false);
    comboBoxCountry.setWidth("375px");
    if (!s.getCountry().isEmpty()) {
        comboBoxCountry.setSelectedItem(countries.getOrDefault(s.getCountry(), Locale.ROOT));
    }

    Image imageLogo = new Image(Language.get(Word.LOGO));

    TextField textFieldLogo = new TextField(Language.get(Word.LOGO_URL));
    if (s.getLogo() != null) {
        textFieldLogo.setValue(s.getLogo().toExternalForm());
        imageLogo.setSource(new ExternalResource(s.getLogo()));
    }
    textFieldLogo.addValueChangeListener(ce -> imageLogo.setSource(new ExternalResource(ce.getValue())));
    textFieldLogo.setWidth("750px");

    if (imageLogo.getHeight() > 125) {
        imageLogo.setHeight("125px");
    }

    forms.addComponents(textFieldId, textFieldName, textFieldDescription, textFieldURL, comboBoxCategories,
            comboBoxLanguage, comboBoxCountry, textFieldLogo, imageLogo);

    Runnable cancel = () -> close();
    Runnable next = () -> validateSecondStage(s, textFieldId.getValue(), textFieldName.getValue(),
            textFieldURL.getValue(), textFieldDescription.getValue(),
            comboBoxCategories.getSelectedItem().orElse(null),
            comboBoxLanguage.getSelectedItem().orElse(Locale.ROOT),
            comboBoxCountry.getSelectedItem().orElse(Locale.ROOT), textFieldLogo.getValue());

    VerticalLayout windowLayout = new VerticalLayout();
    windowLayout.addComponents(header, forms, getFooter(cancel, next));
    windowLayout.setComponentAlignment(header, Alignment.MIDDLE_CENTER);
    return windowLayout;
}