KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > search > PluginSearchResultCollector


1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.ui.search;
12
13 import java.io.File JavaDoc;
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 JavaDoc computeGroupByKey(IMarker marker) {
35             return marker;
36         }
37
38     }
39         
40     private static final String JavaDoc KEY_MATCH = "Search.singleMatch"; //$NON-NLS-1$
41
private static final String JavaDoc KEY_MATCHES = "Search.multipleMatches"; //$NON-NLS-1$
42

43     private PluginSearchUIOperation operation;
44     private ISearchResultView resultView;
45     private IProgressMonitor monitor;
46     private int numMatches = 0;
47     
48     private static final String JavaDoc pageID =
49         "org.eclipse.pde.internal.ui.search.SearchPage"; //$NON-NLS-1$
50

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 JavaDoc text =
81                 (numMatches > 1)
82                     ? PDEPlugin.getResourceString(KEY_MATCHES)
83                     : PDEPlugin.getResourceString(KEY_MATCH);
84
85             monitor.subTask(numMatches + " " + text); //$NON-NLS-1$
86

87         } catch (CoreException e) {
88         }
89     }
90     
91     private void annotateExternalMarker(IMarker marker, IPluginObject match) throws CoreException {
92         IPluginModelBase model = match.getPluginModel();
93         String JavaDoc path = model.getInstallLocation();
94         String JavaDoc manifest =
95                 model.isFragmentModel()
96             ? "fragment.xml" //$NON-NLS-1$
97
: "plugin.xml"; //$NON-NLS-1$
98
String JavaDoc 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