List of usage examples for com.vaadin.ui ComboBox setItemCaptionGenerator
@Override public void setItemCaptionGenerator(ItemCaptionGenerator<T> itemCaptionGenerator)
From source file:com.github.carljmosca.MainLayout.java
private void init() { setSizeFull();//from w w w . jav a2 s . c o m addStyleName("menylayout"); Responsive.makeResponsive(this); ComboBox<Person> cmbPerson = new ComboBox<>(); cmbPerson.setItems(personProcessor.findAll()); cmbPerson.setItemCaptionGenerator(c -> c.getTitle() + " " + c.getFirstName() + " " + c.getLastName()); cmbPerson.addValueChangeListener((HasValue.ValueChangeEvent<Person> event) -> { binder.setBean(cmbPerson.getValue()); }); title = new ComboBox("Title", Arrays.asList(titles)); firstName = new TextField("First"); middleName = new TextField("Middle"); lastName = new TextField("Last"); Button btnNew = new Button("New"); btnNew.addClickListener((Button.ClickEvent event) -> { person = new Person(); binder.setBean(person); }); Button btnSave = new Button("Save"); btnSave.addClickListener((Button.ClickEvent event) -> { personProcessor.addPerson(person); cmbPerson.setItems(personProcessor.findAll()); }); personLayout.setWidth(null); personLayout.setSpacing(true); personLayout.addStyleName("menu"); personLayout.addComponent(title); personLayout.addComponent(firstName); personLayout.addComponent(middleName); personLayout.addComponent(lastName); personLayout.addComponent(btnNew); addComponent(btnSave); addComponent(cmbPerson); addComponent(personLayout); //addComponent(buttonLayout); doBinding(); }
From source file:dhbw.clippinggorilla.userinterface.views.ClippingView.java
public ClippingView(Clipping clipping) { User user = UserUtils.getCurrent();//from w w w.j a va 2s . c o 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); } }
From source file:dhbw.clippinggorilla.userinterface.views.FooterBar.java
public FooterBar() { setColumns(6);//from www .j a v a 2 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 . j a v a 2s .co 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; }
From source file:org.jpos.qi.components.DateRangeComponent.java
License:Open Source License
private ComboBox createDateRanges() { ComboBox combo = new ComboBox(app.getMessage("or").toUpperCase()); combo.setStyleName(ValoTheme.COMBOBOX_SMALL); combo.setEmptySelectionAllowed(false); combo.setItems((Object[]) DateRange.ranges); combo.setItemCaptionGenerator(range -> app.getMessage((String) range)); combo.addValueChangeListener(event -> { if (event.getValue() != null) { datePickerFrom.setValue(null); datePickerTo.setValue(null); if (refreshBtn != null) refreshBtn.click();//from w w w.ja v a 2s . c o m } }); return combo; }
From source file:org.jpos.qi.eeuser.ConsumersView.java
License:Open Source License
private ComboBox<User> createUserBox() { ComboBox<User> box = new ComboBox(QIUtils.getCaptionFromId("user")); box.setItemCaptionGenerator(User::getNickAndId); UsersHelper usersHelper = new UsersHelper(); box.setDataProvider(usersHelper.getDataProvider()); box.setEmptySelectionAllowed(false); return box;/*from w ww . ja v a 2 s .c o m*/ }
From source file:org.jpos.qi.minigl.AccountsView.java
License:Open Source License
@Override protected Component buildAndBindCustomComponent(String propertyId) { if ("created".equalsIgnoreCase(propertyId)) { return buildAndBindDateField(propertyId); }//from w w w .ja v a2 s . co m if ("expiration".equalsIgnoreCase(propertyId)) { return buildAndBindDateField(propertyId); } if ("parent".equalsIgnoreCase(propertyId)) { ComboBox<Account> parentCombo = new ComboBox<>(getCaptionFromId(propertyId)); parentCombo.setDataProvider(((AccountsHelper) getHelper()).getParentDataProvider()); parentCombo.setItemCaptionGenerator(parent -> parent.getCode() + " - " + parent.getDescription()); formatField(propertyId, parentCombo).bind(propertyId); return parentCombo; } if ("type".equalsIgnoreCase(propertyId)) { ComboBox<Integer> typeCombo = new ComboBox<>(getCaptionFromId(propertyId)); typeCombo.setItems(Account.CHART, Account.DEBIT, Account.CREDIT); typeCombo.setItemCaptionGenerator(type -> getApp().getMessage("account." + type).toUpperCase()); formatField(propertyId, typeCombo).bind(propertyId); return typeCombo; } if ("entries".equalsIgnoreCase(propertyId)) { //todo: should bind? return createEntriesPanel(); } return null; }
From source file:org.jpos.qi.minigl.NewEntryForm.java
License:Open Source License
private ComboBox createLayersSelector() { ComboBox<Layer> box = new ComboBox(app.getMessage("layer")); box.setItemCaptionGenerator(l -> l.getId() + " - " + l.getName()); List layers = helper.getLayers(journal); if (layers != null) { Collections.sort(layers); box.setItems(layers);//from ww w. j av a 2s .co m if (layers.size() > 0) { box.setValue((Layer) layers.get(0)); } } box.setEmptySelectionAllowed(false); return box; }