1 11 package org.eclipse.search.internal.ui.text; 12 13 import org.eclipse.core.resources.IFile; 14 15 import org.eclipse.jface.resource.ImageDescriptor; 16 17 import org.eclipse.ui.IEditorInput; 18 import org.eclipse.ui.IEditorPart; 19 import org.eclipse.ui.IFileEditorInput; 20 21 import org.eclipse.search.ui.ISearchQuery; 22 import org.eclipse.search.ui.text.AbstractTextSearchResult; 23 import org.eclipse.search.ui.text.IEditorMatchAdapter; 24 import org.eclipse.search.ui.text.IFileMatchAdapter; 25 import org.eclipse.search.ui.text.Match; 26 27 import org.eclipse.search.internal.ui.SearchPluginImages; 28 29 public class FileSearchResult extends AbstractTextSearchResult implements IEditorMatchAdapter, IFileMatchAdapter { 30 private final Match[] EMPTY_ARR= new Match[0]; 31 32 private FileSearchQuery fQuery; 33 34 public FileSearchResult(FileSearchQuery job) { 35 fQuery= job; 36 } 37 public ImageDescriptor getImageDescriptor() { 38 return SearchPluginImages.DESC_OBJ_TSEARCH_DPDN; 39 } 40 public String getLabel() { 41 return fQuery.getResultLabel(getMatchCount()); 42 } 43 public String getTooltip() { 44 return getLabel(); 45 } 46 47 public Match[] computeContainedMatches(AbstractTextSearchResult result, IFile file) { 48 return getMatches(file); 49 } 50 51 public IFile getFile(Object element) { 52 if (element instanceof IFile) 53 return (IFile)element; 54 return null; 55 } 56 57 public boolean isShownInEditor(Match match, IEditorPart editor) { 58 IEditorInput ei= editor.getEditorInput(); 59 if (ei instanceof IFileEditorInput) { 60 IFileEditorInput fi= (IFileEditorInput) ei; 61 return match.getElement().equals(fi.getFile()); 62 } 63 return false; 64 } 65 66 public Match[] computeContainedMatches(AbstractTextSearchResult result, IEditorPart editor) { 67 IEditorInput ei= editor.getEditorInput(); 68 if (ei instanceof IFileEditorInput) { 69 IFileEditorInput fi= (IFileEditorInput) ei; 70 return getMatches(fi.getFile()); 71 } 72 return EMPTY_ARR; 73 } 74 75 public ISearchQuery getQuery() { 76 return fQuery; 77 } 78 79 public IFileMatchAdapter getFileMatchAdapter() { 80 return this; 81 } 82 83 public IEditorMatchAdapter getEditorMatchAdapter() { 84 return this; 85 } 86 } 87 | Popular Tags |