1 11 12 package org.eclipse.jdt.internal.ui.search; 13 14 import org.eclipse.jface.viewers.TableViewer; 15 import org.eclipse.jface.viewers.TreeViewer; 16 import org.eclipse.jface.viewers.Viewer; 17 import org.eclipse.jface.viewers.ViewerComparator; 18 19 import org.eclipse.ui.IEditorPart; 20 import org.eclipse.ui.PartInitException; 21 import org.eclipse.ui.texteditor.ITextEditor; 22 23 import org.eclipse.search.ui.text.AbstractTextSearchViewPage; 24 import org.eclipse.search.ui.text.Match; 25 26 import org.eclipse.jdt.core.IJavaElement; 27 import org.eclipse.jdt.core.JavaModelException; 28 29 import org.eclipse.jdt.ui.JavaUI; 30 31 32 public class OccurrencesSearchResultPage extends AbstractTextSearchViewPage { 33 34 private TextSearchTableContentProvider fContentProvider; 35 36 public OccurrencesSearchResultPage() { 37 super(AbstractTextSearchViewPage.FLAG_LAYOUT_FLAT); 38 } 39 40 43 protected void showMatch(Match match, int currentOffset, int currentLength, boolean activate) throws PartInitException { 44 JavaElementLine element= (JavaElementLine) match.getElement(); 45 IJavaElement javaElement= element.getJavaElement(); 46 try { 47 IEditorPart editor= JavaUI.openInEditor(javaElement, activate, false); 48 if (editor instanceof ITextEditor) { 49 ITextEditor textEditor= (ITextEditor) editor; 50 textEditor.selectAndReveal(currentOffset, currentLength); 51 } 52 } catch (PartInitException e1) { 53 return; 54 } catch (JavaModelException e1) { 55 return; 56 } 57 58 } 59 60 63 protected void elementsChanged(Object [] objects) { 64 if (fContentProvider != null) 65 fContentProvider.elementsChanged(objects); 66 } 67 68 71 protected void clear() { 72 if (fContentProvider != null) 73 fContentProvider.clear(); 74 } 75 76 79 protected void configureTreeViewer(TreeViewer viewer) { 80 throw new IllegalStateException ("Doesn't support tree mode."); } 82 83 86 protected void configureTableViewer(TableViewer viewer) { 87 viewer.setComparator(new ViewerComparator() { 88 public int compare(Viewer v, Object e1, Object e2) { 89 JavaElementLine jel1= (JavaElementLine) e1; 90 JavaElementLine jel2= (JavaElementLine) e2; 91 return jel1.getLine() - jel2.getLine(); 92 } 93 }); 94 viewer.setLabelProvider(new OccurrencesSearchLabelProvider(this)); 95 fContentProvider= new TextSearchTableContentProvider(); 96 viewer.setContentProvider(fContentProvider); 97 } 98 99 } 100 | Popular Tags |