Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » ViewerFilter Minimize Flickering Where To Call Table.setRedraw(false)(Trying to minimize flickering user sees when you filter a large dataset on a TableViewer)
ViewerFilter Minimize Flickering Where To Call Table.setRedraw(false) [message #899680] Wed, 01 August 2012 15:07 Go to next message
Steve LaBarbera is currently offline Steve LaBarbera
Messages: 2
Registered: August 2012
Junior Member
I have a TableViewer and this viewer has a filter. When the tables data-set is large and I do a filter the table flickers and gets munged while the filter works. In the past I'd call table.setRedraw( false ); before work starts and after work is done call table.setRedraw( true);. I cannot seem to figure out where these be added for a filter call. It can't be in the select(Viewer viewer, Object parentElement, Object element) method as this gets called for every row. Any ideas how this would get implemented?

My implementation is real simple at this point:

/**
 * not implemented yet need to figure out where to hook into ui for user interaction
 * @author Steve
 *
 */
public class SentinelViewFilter extends ViewerFilter{

	private String regex;//the regex match to match the data set on.
	private String vulnTargetData;//the target data to filter through
	private SentinelLabelProvider labelProvider = new SentinelLabelProvider();//helper class grabs the vuln data necessary based on the target data specified
	private static SentinelViewFilter sentViewerFilter;

	public SentinelViewFilter()
	{
		sentViewerFilter = this;
	}
	
	/* (non-Javadoc)
	 * @see org.eclipse.jface.viewers.ViewerFilter#select(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
	 */
	@Override
	public boolean select(Viewer viewer, Object parentElement, Object element) {

		if(regex == null || regex.length() == 0)
		return true;
		
		WhiteHatVulnerability vulnerability = (WhiteHatVulnerability) element;
		String data = (String) labelProvider.getColumnData(vulnTargetData, vulnerability);
		if(data.matches(regex))
			return true;
		else
			return false;
	}
	
	/**
	 * @param regex
	 */
	public void setSearchString(String regex)
	{
		this.regex = regex;
	}
	
	/**
	 * @param vulnTargetData
	 */
	public void setVulnTargetData(String vulnTargetData)
	{
		this.vulnTargetData = vulnTargetData;
	}

	public static SentinelViewFilter getInstance()
	{
		if(sentViewerFilter == null)
			return new SentinelViewFilter();
		
		return sentViewerFilter;
	}
}


Then in my UI I have another widget thats a input box and a button.Once the button is clicked it filters . This is the listener for the button that adds the filter to the table viewer..

class SentinelFilterListener implements Listener {

		@Override
		public void handleEvent(Event event) {
				 if (event.widget ==  btnAddFilter)
				 {
					String regex =  text.getText();
					String colName = combo.getText();// combo.getSelectionIndex()
					sentViewFilter.setSearchString(regex);
					sentViewFilter.setVulnTargetData(colName);
					TableViewer viewer = view.getInstance().getViewer();
					viewer.setFilters(new ViewerFilter[]{sentViewFilter});
				 }
				 else if(event.widget == btnRemoveFilter)
				 {
					 TableViewer viewer = view.getInstance().getViewer();
					 viewer.resetFilters();
			     }
				 
				 
		      }		
		}

	}
Re: ViewerFilter Minimize Flickering Where To Call Table.setRedraw(false) [message #899753 is a reply to message #899680] Thu, 02 August 2012 04:30 Go to previous messageGo to next message
Jan Krakora is currently offline Jan Krakora
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
Hi, I don't see any flickering when using viewer filter.

Anyway, you would try to set the table virtual or put table.setRedraw(false) before viewer.setFilters(new ViewerFilter[]{sentViewFilter}) in the button's listener and table.setRedraw(false) after that.
Re: ViewerFilter Minimize Flickering Where To Call Table.setRedraw(false) [message #900918 is a reply to message #899753] Wed, 08 August 2012 23:56 Go to previous message
Steve LaBarbera is currently offline Steve LaBarbera
Messages: 2
Registered: August 2012
Junior Member
yeah that was the issue so simple. Can';t believe I missed that.
Previous Topic:Add a double click listener on a TableViewerColumn
Next Topic:Scrolling in the JFace Tree Viewer
Goto Forum:
  


Current Time: Sat Jul 26 13:13:20 EDT 2014

Powered by FUDForum. Page generated in 0.02001 seconds