1 11 12 package org.eclipse.jdt.internal.ui.refactoring.nls.search; 13 14 import org.eclipse.core.runtime.IAdaptable; 15 import org.eclipse.jdt.core.JavaModelException; 16 import org.eclipse.jdt.internal.ui.search.JavaSearchResultPage; 17 import org.eclipse.jdt.internal.ui.search.TextSearchTableContentProvider; 18 import org.eclipse.jface.viewers.TableViewer; 19 import org.eclipse.jface.viewers.TreeViewer; 20 import org.eclipse.jface.viewers.ViewerComparator; 21 22 import org.eclipse.search.ui.text.AbstractTextSearchViewPage; 23 import org.eclipse.search.ui.text.Match; 24 import org.eclipse.ui.IEditorPart; 25 import org.eclipse.ui.PartInitException; 26 import org.eclipse.ui.part.IShowInTargetList; 27 import org.eclipse.ui.texteditor.ITextEditor; 28 29 30 public class NLSSearchResultPage extends AbstractTextSearchViewPage implements IAdaptable { 31 32 private TextSearchTableContentProvider fContentProvider; 33 private NLSSearchEditorOpener fEditorOpener= new NLSSearchEditorOpener(); 34 35 public NLSSearchResultPage() { 36 super(AbstractTextSearchViewPage.FLAG_LAYOUT_FLAT); 37 } 38 39 43 protected void showMatch(Match match, int currentOffset, int currentLength, boolean activate) throws PartInitException { 44 try { 45 IEditorPart editor= fEditorOpener.openMatch(match); 46 if (editor != null && activate) 47 editor.getEditorSite().getPage().activate(editor); 48 if (editor instanceof ITextEditor) { 49 ITextEditor textEditor= (ITextEditor) editor; 50 textEditor.selectAndReveal(currentOffset, currentLength); 51 } 52 } catch (JavaModelException e1) { 53 throw new PartInitException(e1.getStatus()); 54 } 55 } 56 57 60 protected void elementsChanged(Object [] objects) { 61 if (fContentProvider != null) 62 fContentProvider.elementsChanged(objects); 63 } 64 65 68 protected void clear() { 69 if (fContentProvider != null) 70 fContentProvider.clear(); 71 } 72 73 76 protected void configureTreeViewer(TreeViewer viewer) { 77 throw new IllegalStateException ("Doesn't support tree mode."); } 79 80 83 protected void configureTableViewer(TableViewer viewer) { 84 viewer.setComparator(new ViewerComparator() { 85 public int category(Object element) { 86 if (element instanceof FileEntry) { 87 return 0; 88 } else { 89 return 1; 90 } 91 } 92 }); 93 viewer.setLabelProvider(new NLSSearchResultLabelProvider2(this)); 94 fContentProvider= new TextSearchTableContentProvider(); 95 viewer.setContentProvider(fContentProvider); 96 } 97 98 101 public Object getAdapter(Class adapter) { 102 if (IShowInTargetList.class.equals(adapter)) { 103 return JavaSearchResultPage.SHOW_IN_TARGET_LIST; 104 } 105 return null; 106 } 107 108 109 } 110 | Popular Tags |