Patrick226
(Patrick Höhle)
March 28, 2017, 4:00pm
1
Hey guys,
has anyone an example how to use a Combobox with a Dataprovider, which uses the Input from combobox as Filtering?
I read this
https://vaadin.com/docs/-/part/framework/components/components-combobox.html#components.combobox.filtering
but i do not realy understand how to use
setItems(CaptionFilter, Collection)
a quick example would be realy nice.
Best regards
Patrick226
(Patrick Höhle)
March 28, 2017, 6:45pm
2
after more Try&Catch i have a first solution found my own way.
private ComboBox<EveItemDto> getFilterCombo() {
if(filtercombo == null){
filtercombo = new ComboBox<>("Search EVE Item");
filtercombo.setWidth(100, Unit.PERCENTAGE);
filtercombo.setEmptySelectionAllowed(true);
filtercombo.setEmptySelectionCaption("Search for an Item ...");
filtercombo.setItemCaptionGenerator(EveItemDto::getTypeName);
filtercombo.setItemIconGenerator((EveItemDto item) -> {
if(item.getIconFile() != null && !item.getIconFile().isEmpty()){
return new ThemeResource(item.getIconFile());
}
else{
return new ThemeResource(EMPTY_ICON);
}
});
filtercombo.setDataProvider((String filter, int offset, int limit) -> {
if(filter.isEmpty() == false){
return presenter.getFoundDatas().stream();
}
else{
return presenter.getEmptyList().stream();
}
}, (String value) -> {
if(value.isEmpty() == false){
return presenter.findEveItems(value);
}
else{
return presenter.getEmptyList().size();
}
});
}
return filtercombo;
}
But are there better ways? or is this correct?
How can i manipulate the limit value?
Nicklas2
(Nicklas Karlsson)
March 28, 2017, 8:56pm
3
Hmm. Java 8 lambdas are nice but perhaps a concrete filter class on the dataprovider would be more useful in this case? If you hold a reference to it, you can change the parameters that affects the filtering, I would think.
Patrick226
(Patrick Höhle)
March 29, 2017, 3:39pm
4
hey nicklas,
sound logical. i will give it a try. at all this was my first usable result