01: /*******************************************************************************
02: * Copyright (c) 2000, 2007 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.pde.internal.ui.search;
11:
12: import org.eclipse.core.resources.IFile;
13: import org.eclipse.jface.action.IAction;
14: import org.eclipse.jface.viewers.ISelection;
15: import org.eclipse.jface.viewers.IStructuredSelection;
16: import org.eclipse.pde.core.plugin.IPluginModelBase;
17: import org.eclipse.pde.core.plugin.PluginRegistry;
18: import org.eclipse.pde.internal.core.search.PluginSearchInput;
19: import org.eclipse.pde.internal.core.search.PluginSearchScope;
20: import org.eclipse.search.ui.ISearchQuery;
21: import org.eclipse.search.ui.NewSearchUI;
22: import org.eclipse.ui.IObjectActionDelegate;
23: import org.eclipse.ui.IWorkbenchPart;
24:
25: public class FindPluginReferencesAction implements
26: IObjectActionDelegate {
27: private String 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
67: .getProject());
68: if (model != null)
69: fSearchString = model.getPluginBase().getId();
70: }
71: }
72: }
73:
74: }
|