1 11 12 package org.eclipse.jdt.internal.ui.search; 13 14 import org.eclipse.jface.viewers.IStructuredContentProvider; 15 import org.eclipse.jface.viewers.TableViewer; 16 import org.eclipse.jface.viewers.Viewer; 17 import org.eclipse.search.ui.text.AbstractTextSearchResult; 18 19 23 public class TextSearchTableContentProvider implements IStructuredContentProvider { 24 protected final Object [] EMPTY_ARRAY= new Object [0]; 25 private AbstractTextSearchResult fSearchResult; 26 private TableViewer fTableViewer; 27 28 31 public Object [] getElements(Object inputElement) { 32 if (inputElement instanceof AbstractTextSearchResult) 33 return ((AbstractTextSearchResult) inputElement).getElements(); 34 return EMPTY_ARRAY; 35 } 36 37 40 public void dispose() { 41 } 43 44 47 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { 48 fTableViewer= (TableViewer) viewer; 49 fSearchResult= (AbstractTextSearchResult) newInput; 50 } 51 52 public void elementsChanged(Object [] updatedElements) { 53 int addCount= 0; 55 int removeCount= 0; 56 for (int i= 0; i < updatedElements.length; i++) { 57 if (fSearchResult.getMatchCount(updatedElements[i]) > 0) { 58 if (fTableViewer.testFindItem(updatedElements[i]) != null) 59 fTableViewer.refresh(updatedElements[i]); 60 else 61 fTableViewer.add(updatedElements[i]); 62 addCount++; 63 } else { 64 fTableViewer.remove(updatedElements[i]); 65 removeCount++; 66 } 67 } 68 } 69 70 public void clear() { 71 fTableViewer.refresh(); 73 } 74 } 75 | Popular Tags |