1 11 package org.eclipse.search.internal.ui.text; 12 13 import org.eclipse.jface.viewers.IStructuredContentProvider; 14 import org.eclipse.jface.viewers.TableViewer; 15 import org.eclipse.jface.viewers.Viewer; 16 17 import org.eclipse.search.ui.text.AbstractTextSearchResult; 18 19 public class FileTableContentProvider implements IStructuredContentProvider, IFileSearchContentProvider { 20 21 private final Object [] EMPTY_ARR= new Object [0]; 22 23 private FileSearchPage fPage; 24 private AbstractTextSearchResult fResult; 25 26 public FileTableContentProvider(FileSearchPage page) { 27 fPage= page; 28 } 29 30 public void dispose() { 31 } 33 34 public Object [] getElements(Object inputElement) { 35 if (inputElement instanceof FileSearchResult) { 36 int elementLimit= getElementLimit(); 37 Object [] elements= ((FileSearchResult)inputElement).getElements(); 38 if (elementLimit != -1 && elements.length > elementLimit) { 39 Object [] shownElements= new Object [elementLimit]; 40 System.arraycopy(elements, 0, shownElements, 0, elementLimit); 41 return shownElements; 42 } 43 return elements; 44 } 45 return EMPTY_ARR; 46 } 47 48 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { 49 if (newInput instanceof FileSearchResult) { 50 fResult= (FileSearchResult) newInput; 51 } 52 } 53 54 public void elementsChanged(Object [] updatedElements) { 55 TableViewer viewer= getViewer(); 56 int elementLimit= getElementLimit(); 57 boolean tableLimited= elementLimit != -1; 58 for (int i= 0; i < updatedElements.length; i++) { 59 if (fResult.getMatchCount(updatedElements[i]) > 0) { 60 if (viewer.testFindItem(updatedElements[i]) != null) 61 viewer.update(updatedElements[i], null); 62 else { 63 if (!tableLimited || viewer.getTable().getItemCount() < elementLimit) 64 viewer.add(updatedElements[i]); 65 } 66 } else 67 viewer.remove(updatedElements[i]); 68 } 69 } 70 71 private int getElementLimit() { 72 return fPage.getElementLimit().intValue(); 73 } 74 75 private TableViewer getViewer() { 76 return (TableViewer) fPage.getViewer(); 77 } 78 79 public void clear() { 80 getViewer().refresh(); 81 } 82 } 83 | Popular Tags |