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.
我想在SWT/JFace应用程序中添加一个搜索功能,当用户在搜索文本字段中输入文本时,该功能将筛选表查看器。
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 fitered 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 ?
我需要删除过滤器并在修改监听器中创建一个新的过滤器,还是有更好的解决方案?
2 个解决方案
#1
3
Basically, you need to have a way of passing the entered text to the filter, in your select method you should filter based on this text, and in your text widget's listener pass the text to the filter and call viewer.refresh()
on your table.
基本上,您需要有一种方法将输入的文本传递给筛选器,在您的select方法中,您应该基于该文本进行筛选,在文本小部件的侦听器中,将文本传递给筛选器并调用表上的viewer.refresh()。
This example should help you: http://www.vogella.com/tutorials/EclipseJFaceTableAdvanced/article.html#jfacetable_filter
这个例子应该可以帮助您:http://www.vogella.com/tutorials/EclipseJFaceTableAdvanced/article.html#jfacetable_filter
#2
0
org.eclipse.ui.dialogs.FilteredTree
is specifically available for that purpose. Why can't you use that?
org.eclipse.ui.dialogs。FilteredTree专门用于此目的。为什么你不能用那个?
#1
3
Basically, you need to have a way of passing the entered text to the filter, in your select method you should filter based on this text, and in your text widget's listener pass the text to the filter and call viewer.refresh()
on your table.
基本上,您需要有一种方法将输入的文本传递给筛选器,在您的select方法中,您应该基于该文本进行筛选,在文本小部件的侦听器中,将文本传递给筛选器并调用表上的viewer.refresh()。
This example should help you: http://www.vogella.com/tutorials/EclipseJFaceTableAdvanced/article.html#jfacetable_filter
这个例子应该可以帮助您:http://www.vogella.com/tutorials/EclipseJFaceTableAdvanced/article.html#jfacetable_filter
#2
0
org.eclipse.ui.dialogs.FilteredTree
is specifically available for that purpose. Why can't you use that?
org.eclipse.ui.dialogs。FilteredTree专门用于此目的。为什么你不能用那个?