1 11 package org.eclipse.pde.internal.ui.search; 12 13 import org.eclipse.jface.viewers.ILabelProvider; 14 import org.eclipse.jface.viewers.IStructuredContentProvider; 15 import org.eclipse.jface.viewers.TableViewer; 16 import org.eclipse.jface.viewers.TreeViewer; 17 import org.eclipse.jface.viewers.Viewer; 18 import org.eclipse.jface.viewers.ViewerComparator; 19 import org.eclipse.search.ui.text.AbstractTextSearchResult; 20 import org.eclipse.search.ui.text.AbstractTextSearchViewPage; 21 22 public abstract class AbstractSearchResultPage extends AbstractTextSearchViewPage { 23 24 class ContentProvider implements IStructuredContentProvider { 25 26 private TableViewer fTableViewer; 27 private AbstractTextSearchResult fSearchResult; 28 29 32 public Object [] getElements(Object inputElement) { 33 if (inputElement instanceof AbstractTextSearchResult) 34 return ((AbstractTextSearchResult) inputElement).getElements(); 35 return new Object [0]; 36 } 37 38 41 public void dispose() { 42 } 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 clear() { 53 fTableViewer.refresh(); 54 } 55 56 public void elementsChanged(Object [] updatedElements) { 57 for (int i= 0; i < updatedElements.length; i++) { 58 if (fSearchResult.getMatchCount(updatedElements[i]) > 0) { 59 if (fTableViewer.testFindItem(updatedElements[i]) != null) 60 fTableViewer.refresh(updatedElements[i]); 61 else 62 fTableViewer.add(updatedElements[i]); 63 } else { 64 fTableViewer.remove(updatedElements[i]); 65 } 66 } 67 } 68 } 69 70 private ContentProvider fContentProvider; 71 72 public AbstractSearchResultPage() { 73 super(AbstractTextSearchViewPage.FLAG_LAYOUT_FLAT); 74 } 75 76 77 80 protected void elementsChanged(Object [] objects) { 81 if (fContentProvider != null && fContentProvider.fSearchResult != null) 82 fContentProvider.elementsChanged(objects); 83 } 84 85 88 protected void clear() { 89 if (fContentProvider != null) 90 fContentProvider.clear(); 91 } 92 93 96 protected void configureTreeViewer(TreeViewer viewer) { 97 throw new IllegalStateException ("Doesn't support tree mode."); } 99 100 103 protected void configureTableViewer(TableViewer viewer) { 104 viewer.setComparator(createViewerComparator()); 105 viewer.setLabelProvider(createLabelProvider()); 106 fContentProvider= new ContentProvider(); 107 viewer.setContentProvider(fContentProvider); 108 } 109 110 protected abstract ILabelProvider createLabelProvider(); 111 112 protected abstract ViewerComparator createViewerComparator(); 113 114 115 } 116 | Popular Tags |