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.jface.action.IMenuManager; 20 import org.eclipse.jface.viewers.IStructuredSelection; 21 import org.eclipse.pde.core.ISourceObject; 22 import org.eclipse.pde.core.plugin.IPluginExtensionPoint; 23 import org.eclipse.pde.core.plugin.IPluginModelBase; 24 import org.eclipse.pde.core.plugin.IPluginObject; 25 import org.eclipse.pde.internal.ui.*; 26 import org.eclipse.search.ui.IActionGroupFactory; 27 import org.eclipse.search.ui.IGroupByKeyComputer; 28 import org.eclipse.search.ui.ISearchResultView; 29 import org.eclipse.search.ui.ISearchResultViewEntry; 30 import org.eclipse.search.ui.SearchUI; 31 import org.eclipse.ui.actions.ActionContext; 32 import org.eclipse.ui.actions.ActionGroup; 33 34 35 public class DependencyExtentSearchResultCollector { 36 37 private static final String PAGE_ID = "org.eclipse.pde.internal.ui.search.dependencyExtent"; 39 private static final String KEY_DEPENDENCY = "DependencyExtent.singular"; private static final String KEY_DEPENDENCIES = "DependencyExtent.plural"; private static final String KEY_FOUND = "DependencyExtent.found"; private static final String KEY_SEARCHING = "DependencyExtent.searching"; 44 private int numMatches = 0; 45 46 private ISearchResultView resultView; 47 private IProgressMonitor monitor; 48 private DependencyExtentSearchOperation operation; 49 50 class GroupByKeyComputer implements IGroupByKeyComputer { 51 public Object computeGroupByKey(IMarker marker) { 52 return marker; 53 } 54 55 } 56 57 class SearchActionGroupFactory implements IActionGroupFactory { 58 public ActionGroup createActionGroup(ISearchResultView searchView) { 59 return new SearchActionGroup(); 60 } 61 } 62 63 class SearchActionGroup extends PluginSearchActionGroup { 64 public void fillContextMenu(IMenuManager menu) { 65 super.fillContextMenu(menu); 66 ActionContext context = getContext(); 67 IStructuredSelection selection = 68 (IStructuredSelection) context.getSelection(); 69 if (selection.size() == 1) { 70 ISearchResultViewEntry entry = 71 (ISearchResultViewEntry) selection.getFirstElement(); 72 menu.add(new ReferencesInPluginAction(entry)); 73 } 74 } 75 } 76 77 78 public DependencyExtentSearchResultCollector(DependencyExtentSearchOperation op, IProgressMonitor monitor) { 79 this.operation = op; 80 this.monitor = monitor; 81 } 82 83 public void accept(Object match) { 84 try { 85 IResource resource = operation.getProject(); 86 87 IMarker marker = resource.createMarker(SearchUI.SEARCH_MARKER); 88 if (match instanceof IPluginExtensionPoint) { 89 if (match instanceof ISourceObject) { 90 marker.setAttribute( 91 IMarker.LINE_NUMBER, 92 ((ISourceObject) match).getStartLine()); 93 } 94 if (((IPluginExtensionPoint)match).getModel().getUnderlyingResource() == null) 95 annotateExternalMarker(marker, (IPluginExtensionPoint)match); 96 } 97 98 resultView.addMatch(null, match, resource, marker); 99 numMatches += 1; 100 101 String text = 102 (numMatches > 1) 103 ? PDEPlugin.getResourceString(KEY_DEPENDENCIES) 104 : PDEPlugin.getResourceString(KEY_DEPENDENCY); 105 106 monitor.setTaskName( 107 PDEPlugin.getResourceString(KEY_SEARCHING) 108 + " " + numMatches 110 + " " + text 112 + " " + PDEPlugin.getResourceString(KEY_FOUND)); 114 } catch (CoreException e) { 115 } 116 } 117 118 public void done() { 119 if (resultView != null) 120 resultView.searchFinished(); 121 } 122 123 private void annotateExternalMarker(IMarker marker, IPluginObject match) throws CoreException { 124 IPluginModelBase model = match.getPluginModel(); 125 String path = model.getInstallLocation(); 126 String manifest = 127 model.isFragmentModel() 128 ? "fragment.xml" : "plugin.xml"; String fileName = path + File.separator + manifest; 131 marker.setAttribute(IPDEUIConstants.MARKER_SYSTEM_FILE_PATH, fileName); 132 } 133 134 public void searchStarted() { 135 resultView = SearchUI.getSearchResultView(); 136 resultView.searchStarted( 137 new SearchActionGroupFactory(), 138 operation.getSingularLabel(), 139 operation.getPluralLabel(), 140 null, 141 PAGE_ID, 142 new DependencyExtentLabelProvider(), 143 new SearchGoToAction(), 144 new GroupByKeyComputer(), 145 operation); 146 } 147 148 } 149 | Popular Tags |