/** * {@inheritDoc} * <p> * Filtering will use a case insensitive match to show all items where the * filter text is a substring of the caption displayed for that item. */ @Override public void setItems(Collection<T> items) { ListDataProvider<T> listDataProvider = DataProvider.ofCollection(items); setDataProvider(listDataProvider); }
/** * Sets the data items of this listing and a simple string filter with which * the item string and the text the user has input are compared. * <p> * Note that unlike {@link #setItems(Collection)}, no automatic case * conversion is performed before the comparison. * * @param captionFilter * filter to check if an item is shown when user typed some text * into the ComboBox * @param items * the data items to display * @since 8.0 */ public void setItems(CaptionFilter captionFilter, Collection<T> items) { ListDataProvider<T> listDataProvider = DataProvider.ofCollection(items); setDataProvider(captionFilter, listDataProvider); }
/** * Sets a list data provider as the data provider of this combo box. * Filtering will use a case insensitive match to show all items where the * filter text is a substring of the caption displayed for that item. * <p> * Note that this is a shorthand that calls * {@link #setDataProvider(DataProvider)} with a wrapper of the provided * list data provider. This means that {@link #getDataProvider()} will * return the wrapper instead of the original list data provider. * * @param listDataProvider * the list data provider to use, not <code>null</code> * @since 8.0 */ public void setDataProvider(ListDataProvider<T> listDataProvider) { // Cannot use the case insensitive contains shorthand from // ListDataProvider since it wouldn't react to locale changes CaptionFilter defaultCaptionFilter = (itemText, filterText) -> itemText .toLowerCase(getLocale()) .contains(filterText.toLowerCase(getLocale())); setDataProvider(defaultCaptionFilter, listDataProvider); }
/** * Sets a list data provider with an item caption filter as the data * provider of this combo box. The caption filter is used to compare the * displayed caption of each item to the filter text entered by the user. * * @param captionFilter * filter to check if an item is shown when user typed some text * into the ComboBox * @param listDataProvider * the list data provider to use, not <code>null</code> * @since 8.0 */ public void setDataProvider(CaptionFilter captionFilter, ListDataProvider<T> listDataProvider) { Objects.requireNonNull(listDataProvider, "List data provider cannot be null"); // Must do getItemCaptionGenerator() for each operation since it might // not be the same as when this method was invoked setDataProvider(listDataProvider, filterText -> item -> captionFilter .test(getItemCaptionGenerator().apply(item), filterText)); }
/** * Sets a CallbackDataProvider using the given fetch items callback and a * size callback. * <p> * This method is a shorthand for making a {@link CallbackDataProvider} that * handles a partial {@link com.vaadin.data.provider.Query Query} object. * * @param fetchItems * a callback for fetching items * @param sizeCallback * a callback for getting the count of items * * @see CallbackDataProvider * @see #setDataProvider(DataProvider) */ public void setDataProvider(FetchItemsCallback<T> fetchItems, SerializableToIntFunction<String> sizeCallback) { setDataProvider(new CallbackDataProvider<>( q -> fetchItems.fetchItems(q.getFilter().orElse(""), q.getOffset(), q.getLimit()), q -> sizeCallback.applyAsInt(q.getFilter().orElse("")))); }
@SuppressWarnings({ "unchecked", "rawtypes" }) @Override public void setDataProvider(DataProvider<ITEM, ?> dataProvider, SerializableFunction<String, ?> filterConverter) { if (filterConverter != null && getInternalField() instanceof ComboBox) { ((ComboBox) getInternalField()).setDataProvider(dataProvider, filterConverter); } else { setDataProvider(dataProvider); } }
/** * We cannot set up the combo with data until the UI has finished building * * @param message not used */ @Handler public void afterViewChange(AfterViewChangeBusMessage message) { log.debug("Received AfterViewChangeBusMessage, completing set up for Combo"); combo.setItemCaptionGenerator(container); combo.setItemIconGenerator(container.getIconGenerator()); combo.setDataProvider(container.getDataProvider()); log.debug("Setting Locale selector to {}", currentLocale.getLocale()); combo.setValue(currentLocale.getLocale()); combo.addValueChangeListener(this); loaded = true; log.debug("Combo set up complete"); }
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; }
public FilterField( final ListDataProvider<T> dataProvider, final TableDefinition<T> tableDefinition) { super(); this.dataProvider = dataProvider; this.tableDefinition = tableDefinition; this.attributeField.setStyleName("filter-attribute"); this.attributeField.addValueChangeListener(this::onAttributeChange); this.attributeField.setDataProvider(new ListDataProvider<>(filterDefinitions)); this.attributeField.setTextInputAllowed(false); this.optionsField.setStyleName("filter-options"); this.optionsField.setDataProvider(optionsDataProvider); this.textField.setStyleName("filter-text"); this.tableDefinition.getFilterableColumns().map(ColumnDefinition::filterDefinition).forEach(filterDefinitions::add); if (hasFilterDefinitions()) { this.attributeField.setSelectedItem(this.filterDefinitions.get(0)); } this.optionsField.addValueChangeListener(this::onFilterOptionSelected); this.optionsField.addShortcutListener(new ClearFilterShortcutListener<>(this)); this.textField.addShortcutListener(new FilterShortcutListener<>(this)); this.textField.addShortcutListener(new ClearFilterShortcutListener<>(this)); }
@Override protected Component buildAndBindCustomComponent(String propertyId) { if ("created".equalsIgnoreCase(propertyId)){ return getFieldFactory().buildAndBindDateField(propertyId); } if ("expiration".equalsIgnoreCase(propertyId)){ return getFieldFactory().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; }