KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.HashSet JavaDoc;
14
15 import org.eclipse.core.resources.*;
16 import org.eclipse.core.resources.IProject;
17 import org.eclipse.core.resources.IResource;
18 import org.eclipse.core.runtime.*;
19 import org.eclipse.jdt.core.IJavaElement;
20 import org.eclipse.jface.action.Action;
21 import org.eclipse.pde.core.plugin.IPluginExtensionPoint;
22 import org.eclipse.pde.internal.core.search.PluginSearchInput;
23 import org.eclipse.pde.internal.core.search.PluginSearchScope;
24 import org.eclipse.pde.internal.ui.PDEPlugin;
25 import org.eclipse.search.ui.ISearchResultViewEntry;
26 import org.eclipse.search.ui.SearchUI;
27
28 /**
29  * @author wassimm
30  *
31  * To change this generated comment edit the template variable "typecomment":
32  * Window>Preferences>Java>Templates.
33  * To enable and disable the creation of type comments go to
34  * Window>Preferences>Java>Code Generation.
35  */

36 public class ReferencesInPluginAction extends Action {
37     
38     private static final String JavaDoc KEY_REFERENCES = "DependencyExtent.references"; //$NON-NLS-1$
39

40     ISearchResultViewEntry entry;
41     
42     
43     public ReferencesInPluginAction(ISearchResultViewEntry entry) {
44         this.entry = entry;
45         setText(PDEPlugin.getResourceString(KEY_REFERENCES) + " " + entry.getResource().getName()); //$NON-NLS-1$
46
}
47     
48     public void run() {
49         try {
50             SearchUI.activateSearchResultView();
51             IWorkspaceRunnable operation = null;
52             Object JavaDoc object = entry.getGroupByKey();
53             if (object instanceof IJavaElement) {
54                 operation = new JavaSearchOperation((IJavaElement)object, (IProject)entry.getResource());
55             } else {
56                 operation =
57                     new PluginSearchUIOperation(
58                         getPluginSearchInput((IPluginExtensionPoint) object),
59                         new PluginSearchResultCollector());
60             }
61             PDEPlugin.getWorkspace().run(operation, null, IWorkspace.AVOID_UPDATE, new NullProgressMonitor());
62         } catch (CoreException e) {
63         }
64     }
65     
66     private PluginSearchInput getPluginSearchInput(IPluginExtensionPoint object) {
67         PluginSearchInput input = new PluginSearchInput();
68         input.setSearchElement(PluginSearchInput.ELEMENT_EXTENSION_POINT);
69         input.setSearchString(
70             ((IPluginExtensionPoint) object).getPluginBase().getId()
71                 + "." //$NON-NLS-1$
72
+ ((IPluginExtensionPoint) object).getId());
73         input.setSearchLimit(PluginSearchInput.LIMIT_REFERENCES);
74         HashSet JavaDoc set = new HashSet JavaDoc();
75         IResource resource = ((IProject)entry.getResource()).getFile("plugin.xml"); //$NON-NLS-1$
76
if (!resource.exists())
77             resource = ((IProject)entry.getResource()).getFile("fragment.xml"); //$NON-NLS-1$
78

79         set.add(resource);
80         input.setSearchScope(
81             new PluginSearchScope(
82                 PluginSearchScope.SCOPE_SELECTION,
83                 PluginSearchScope.EXTERNAL_SCOPE_NONE,
84                 set));
85         return input;
86     }
87
88
89 }
90
Popular Tags