Created
April 13, 2018 08:51
-
-
Save alozta/1da0924710ae2f821dcdd90b7ac4098a to your computer and use it in GitHub Desktop.
Working example of filter for TwinColSelect in Vaadin 7.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| final BeanItemContainer<String> bean = new BeanItemContainer<>(String.class); //com.vaadin.data.util.BeanItemContainer<BEANTYPE> | |
| List<String> list = new ArrayList<>(); | |
| bean.addAll(list); | |
| this.twinColSelect.setContainerDataSource(list); //com.vaadin.ui.TwinColSelect | |
| filter.setTextChangeEventMode(TextChangeEventMode.LAZY); //com.vaadin.ui.TextField | |
| filter.addTextChangeListener(new TextChangeListener() { | |
| private static final long serialVersionUID = 1L; | |
| public void textChange(final TextChangeEvent event) { | |
| bean.removeAllContainerFilters(); | |
| bean.addContainerFilter(new Filter() { | |
| @Override | |
| public boolean passesFilter(Object itemId, Item item) throws UnsupportedOperationException { | |
| if (((String) itemId).toLowerCase().contains(event.getText().toLowerCase()) | |
| || ((Collection) twinColSelect.getValue()).contains(itemId)) | |
| return true; | |
| else | |
| return false; | |
| } | |
| @Override | |
| public boolean appliesToProperty(Object propertyId) { | |
| return true; | |
| } | |
| }); | |
| } | |
| }); |
Author
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
GitHub must have love (!) their tab indentation.