KickJava   Java API By Example, From Geeks To Geeks.

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


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

11 package org.eclipse.pde.internal.ui.search;
12
13 import org.eclipse.core.resources.IFile;
14 import org.eclipse.jface.action.IAction;
15 import org.eclipse.jface.viewers.ISelection;
16 import org.eclipse.jface.viewers.IStructuredSelection;
17 import org.eclipse.pde.core.plugin.IPluginModelBase;
18 import org.eclipse.pde.core.plugin.PluginRegistry;
19 import org.eclipse.pde.internal.core.search.PluginSearchInput;
20 import org.eclipse.pde.internal.core.search.PluginSearchScope;
21 import org.eclipse.search.ui.ISearchQuery;
22 import org.eclipse.search.ui.NewSearchUI;
23 import org.eclipse.ui.IObjectActionDelegate;
24 import org.eclipse.ui.IWorkbenchPart;
25
26 public class FindPluginReferencesAction implements IObjectActionDelegate {
27     private String JavaDoc fSearchString = null;
28
29     /*
30      * (non-Javadoc)
31      * @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction, org.eclipse.ui.IWorkbenchPart)
32      */

33     public void setActivePart(IAction action, IWorkbenchPart targetPart) {
34     }
35
36     /*
37      * (non-Javadoc)
38      * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
39      */

40     public void run(IAction action) {
41         if (fSearchString != null) {
42             NewSearchUI.activateSearchResultView();
43             NewSearchUI.runQueryInBackground(createSearchQuery());
44         }
45     }
46     
47     private ISearchQuery createSearchQuery() {
48         PluginSearchInput input = new PluginSearchInput();
49         input.setSearchElement(PluginSearchInput.ELEMENT_PLUGIN);
50         input.setSearchLimit(PluginSearchInput.LIMIT_REFERENCES);
51         input.setSearchString(fSearchString);
52         input.setSearchScope(new PluginSearchScope());
53         return new PluginSearchQuery(input);
54     }
55
56     /*
57      * (non-Javadoc)
58      * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
59      */

60     public void selectionChanged(IAction action, ISelection selection) {
61         fSearchString = null;
62         if (selection instanceof IStructuredSelection) {
63             IStructuredSelection sSelection = (IStructuredSelection) selection;
64             if (sSelection.size() == 1) {
65                 IFile file = (IFile) sSelection.getFirstElement();
66                 IPluginModelBase model = PluginRegistry.findModel(file.getProject());
67                 if (model != null)
68                     fSearchString = model.getPluginBase().getId();
69             }
70         }
71     }
72
73 }
74
Popular Tags