1 11 package org.eclipse.pde.internal.ui.search.dependencies; 12 13 import java.util.HashSet ; 14 import java.util.Set ; 15 16 import org.eclipse.jdt.core.IJavaElement; 17 import org.eclipse.jdt.core.IParent; 18 import org.eclipse.jdt.core.JavaModelException; 19 import org.eclipse.jface.resource.ImageDescriptor; 20 import org.eclipse.pde.internal.ui.PDEPluginImages; 21 import org.eclipse.pde.internal.ui.PDEUIMessages; 22 import org.eclipse.pde.internal.ui.search.SearchResult; 23 import org.eclipse.search.ui.ISearchQuery; 24 import org.eclipse.search.ui.text.AbstractTextSearchResult; 25 import org.eclipse.search.ui.text.IEditorMatchAdapter; 26 import org.eclipse.search.ui.text.IFileMatchAdapter; 27 import org.eclipse.search.ui.text.Match; 28 import org.eclipse.ui.IEditorInput; 29 import org.eclipse.ui.IEditorPart; 30 31 32 public class DependencyExtentSearchResult extends SearchResult implements IEditorMatchAdapter { 33 34 37 public DependencyExtentSearchResult(ISearchQuery query) { 38 super(query); 39 } 40 41 44 public IEditorMatchAdapter getEditorMatchAdapter() { 45 return this; 46 } 47 48 51 public IFileMatchAdapter getFileMatchAdapter() { 52 return null; 53 } 54 55 58 public boolean isShownInEditor(Match match, IEditorPart editor) { 59 return true; 60 } 61 62 65 public Match[] computeContainedMatches(AbstractTextSearchResult result, IEditorPart editor) { 66 IEditorInput editorInput = editor.getEditorInput(); 67 IJavaElement element = (IJavaElement) editorInput.getAdapter(IJavaElement.class); 68 if (element != null) { 69 Set matches= new HashSet (); 70 collectMatches(matches, element); 71 return (Match[]) matches.toArray(new Match[matches.size()]); 72 } 73 return super.computeContainedMatches(result, editor); 74 75 } 76 77 private void collectMatches(Set matches, IJavaElement element) { 78 Match[] m= getMatches(element); 79 if (m.length != 0) { 80 for (int i= 0; i < m.length; i++) { 81 matches.add(m[i]); 82 } 83 } 84 if (element instanceof IParent) { 85 IParent parent= (IParent) element; 86 try { 87 IJavaElement[] children= parent.getChildren(); 88 for (int i= 0; i < children.length; i++) { 89 collectMatches(matches, children[i]); 90 } 91 } catch (JavaModelException e) { 92 } 94 } 95 } 96 97 98 101 public String getLabel() { 102 int count = getMatchCount(); 103 return fQuery.getLabel() + " - " + count + " " + (count == 1 ? PDEUIMessages.DependencyExtentSearchResult_dependency : PDEUIMessages.DependencyExtentSearchResult_dependencies); } 105 106 109 public String getTooltip() { 110 return null; 111 } 112 113 116 public ImageDescriptor getImageDescriptor() { 117 return PDEPluginImages.DESC_PSEARCH_OBJ; 118 } 119 120 123 public ISearchQuery getQuery() { 124 return fQuery; 125 } 126 127 } 128 | Popular Tags |