KickJava   Java API By Example, From Geeks To Geeks.

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


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 import java.util.HashMap JavaDoc;
13
14 import org.eclipse.core.resources.IMarker;
15 import org.eclipse.core.resources.IResource;
16 import org.eclipse.core.runtime.CoreException;
17 import org.eclipse.core.runtime.IProgressMonitor;
18 import org.eclipse.jdt.core.IJavaElement;
19 import org.eclipse.jdt.core.JavaCore;
20 import org.eclipse.jdt.core.search.IJavaSearchConstants;
21 import org.eclipse.jdt.core.search.IJavaSearchResultCollector;
22 import org.eclipse.search.ui.IActionGroupFactory;
23 import org.eclipse.search.ui.IGroupByKeyComputer;
24 import org.eclipse.search.ui.ISearchResultView;
25 import org.eclipse.search.ui.SearchUI;
26 import org.eclipse.ui.actions.ActionGroup;
27
28 class JavaSearchCollector implements IJavaSearchResultCollector {
29     private IProgressMonitor monitor;
30     private ISearchResultView resultView;
31     private JavaSearchOperation operation;
32     
33     class SearchActionGroupFactory implements IActionGroupFactory {
34         public ActionGroup createActionGroup(ISearchResultView searchView) {
35             return new SearchActionGroup();
36         }
37     }
38     
39     class SearchActionGroup extends ActionGroup {
40     }
41     
42     class GroupByKeyComputer implements IGroupByKeyComputer {
43         public Object JavaDoc computeGroupByKey(IMarker marker) {
44             return marker;
45         }
46     }
47     
48     public JavaSearchCollector(JavaSearchOperation op, IProgressMonitor monitor) {
49         this.operation = op;
50         this.monitor = monitor;
51     }
52     
53     public void aboutToStart() {
54         resultView = SearchUI.getSearchResultView();
55         resultView.searchStarted(
56             new SearchActionGroupFactory(),
57             operation.getSingularLabel(),
58             operation.getPluralLabel(),
59             null,
60             "org.eclipse.pde.internal.ui.search.javaSearch", //$NON-NLS-1$
61
new DependencyExtentLabelProvider(),
62             new SearchGoToAction(),
63             new GroupByKeyComputer(),
64             operation);
65     }
66     
67     public void accept(
68         IResource resource,
69         int start,
70         int end,
71         IJavaElement enclosingElement,
72         int accuracy)
73         throws CoreException {
74         if (accuracy == IJavaSearchConstants.EXACT_MATCH) {
75             HashMap JavaDoc attributes= new HashMap JavaDoc(3);
76             JavaCore.addJavaElementMarkerAttributes(attributes, enclosingElement);
77             attributes.put(IMarker.CHAR_START, new Integer JavaDoc(Math.max(start, 0)));
78             attributes.put(IMarker.CHAR_END, new Integer JavaDoc(Math.max(end, 0)));
79             IMarker marker = resource.createMarker(SearchUI.SEARCH_MARKER);
80             marker.setAttributes(attributes);
81             resultView.addMatch(enclosingElement.getElementName(),enclosingElement,resource, marker);
82         }
83     }
84
85     public void done() {
86         if (resultView != null)
87             resultView.searchFinished();
88     }
89
90     public IProgressMonitor getProgressMonitor() {
91         return monitor;
92     }
93
94 }
95
Popular Tags