I want to add in a SWT/JFace application a search functionality that filter a TableViewer as the user enter text in the search text field.
final Text filterText = new Text(parent, SWT.NONE);
filterText.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent arg0) {
//TODO how to update the viewer filter with the new text ?
}
});
TableViewer tableViewer = new TableViewer(...);
ViewerFilter filterViewer = new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
if (filterText.getText() == "") {
return true;
}
//do my stuff to know if element need to be filtered or not
return false;
}
};
tableViewer.addFilter(filterViewer);
Do I need to remove the filter and create a new one in the modify listener or is there a better solution?