KickJava   Java API By Example, From Geeks To Geeks.

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


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.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 JavaDoc PAGE_ID = "org.eclipse.pde.internal.ui.search.dependencyExtent"; //$NON-NLS-1$
38

39     private static final String JavaDoc KEY_DEPENDENCY = "DependencyExtent.singular"; //$NON-NLS-1$
40
private static final String JavaDoc KEY_DEPENDENCIES = "DependencyExtent.plural"; //$NON-NLS-1$
41
private static final String JavaDoc KEY_FOUND = "DependencyExtent.found"; //$NON-NLS-1$
42
private static final String JavaDoc KEY_SEARCHING = "DependencyExtent.searching"; //$NON-NLS-1$
43

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 JavaDoc 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 JavaDoc 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 JavaDoc text =
102                 (numMatches > 1)
103                     ? PDEPlugin.getResourceString(KEY_DEPENDENCIES)
104                     : PDEPlugin.getResourceString(KEY_DEPENDENCY);
105             
106             monitor.setTaskName(
107                 PDEPlugin.getResourceString(KEY_SEARCHING)
108                     + " " //$NON-NLS-1$
109
+ numMatches
110                     + " " //$NON-NLS-1$
111
+ text
112                     + " " //$NON-NLS-1$
113
+ 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 JavaDoc path = model.getInstallLocation();
126         String JavaDoc manifest =
127                 model.isFragmentModel()
128             ? "fragment.xml" //$NON-NLS-1$
129
: "plugin.xml"; //$NON-NLS-1$
130
String JavaDoc 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