1 11 package org.eclipse.pde.internal.ui.search; 12 13 import java.io.File ; 14 15 import org.eclipse.core.resources.IMarker; 16 import org.eclipse.core.resources.IResource; 17 import org.eclipse.core.runtime.CoreException; 18 import org.eclipse.core.runtime.IProgressMonitor; 19 import org.eclipse.pde.core.ISourceObject; 20 import org.eclipse.pde.core.plugin.*; 21 import org.eclipse.pde.core.plugin.IPluginObject; 22 import org.eclipse.pde.internal.core.search.IPluginSearchResultCollector; 23 import org.eclipse.pde.internal.core.search.PluginSearchOperation; 24 import org.eclipse.pde.internal.ui.*; 25 import org.eclipse.search.ui.IGroupByKeyComputer; 26 import org.eclipse.search.ui.ISearchResultView; 27 import org.eclipse.search.ui.SearchUI; 28 29 30 public class PluginSearchResultCollector 31 implements IPluginSearchResultCollector { 32 33 class GroupByKeyComputer implements IGroupByKeyComputer { 34 public Object computeGroupByKey(IMarker marker) { 35 return marker; 36 } 37 38 } 39 40 private static final String KEY_MATCH = "Search.singleMatch"; private static final String KEY_MATCHES = "Search.multipleMatches"; 43 private PluginSearchUIOperation operation; 44 private ISearchResultView resultView; 45 private IProgressMonitor monitor; 46 private int numMatches = 0; 47 48 private static final String pageID = 49 "org.eclipse.pde.internal.ui.search.SearchPage"; 51 52 public void setOperation(PluginSearchOperation operation) { 53 this.operation = (PluginSearchUIOperation) operation; 54 } 55 56 public PluginSearchOperation getOperation() { 57 return operation; 58 } 59 60 public void accept(IPluginObject match) { 61 try { 62 IResource resource = match.getModel().getUnderlyingResource(); 63 if (resource == null) { 64 resource = PDEPlugin.getWorkspace().getRoot(); 65 } 66 67 IMarker marker = resource.createMarker(SearchUI.SEARCH_MARKER); 68 if (match instanceof ISourceObject) { 69 marker.setAttribute( 70 IMarker.LINE_NUMBER, 71 ((ISourceObject) match).getStartLine()); 72 } 73 if (match.getModel().getUnderlyingResource()==null) 74 annotateExternalMarker(marker, match); 75 76 resultView.addMatch(null, match, resource, marker); 77 78 numMatches += 1; 79 80 String text = 81 (numMatches > 1) 82 ? PDEPlugin.getResourceString(KEY_MATCHES) 83 : PDEPlugin.getResourceString(KEY_MATCH); 84 85 monitor.subTask(numMatches + " " + text); 87 } catch (CoreException e) { 88 } 89 } 90 91 private void annotateExternalMarker(IMarker marker, IPluginObject match) throws CoreException { 92 IPluginModelBase model = match.getPluginModel(); 93 String path = model.getInstallLocation(); 94 String manifest = 95 model.isFragmentModel() 96 ? "fragment.xml" : "plugin.xml"; String fileName = path + File.separator + manifest; 99 marker.setAttribute(IPDEUIConstants.MARKER_SYSTEM_FILE_PATH, fileName); 100 } 101 102 public void done() { 103 if (resultView != null) 104 resultView.searchFinished(); 105 } 106 107 public void searchStarted() { 108 resultView = SearchUI.getSearchResultView(); 109 resultView.searchStarted( 110 new PluginSearchActionGroupFactory(), 111 operation.getSingularLabel(), 112 operation.getPluralLabel(), 113 null, 114 pageID, 115 new PluginSearchLabelProvider(), 116 new SearchGoToAction(), 117 new GroupByKeyComputer(), 118 operation); 119 } 120 121 public void setProgressMonitor(IProgressMonitor monitor) { 122 this.monitor = monitor; 123 } 124 125 } 126 | Popular Tags |