1 /*******************************************************************************
2 * Copyright (c) 2000, 2011 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
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package org.eclipse.jdt.ui.actions;
13 import org.eclipse.jface.viewers.ISelection;
14 import org.eclipse.jface.viewers.ISelectionProvider;
16 import org.eclipse.ui.IWorkbenchSite;
17 import org.eclipse.ui.PlatformUI;
19 import org.eclipse.jdt.core.IJavaElement;
20 import org.eclipse.jdt.core.JavaModelException;
21 import org.eclipse.jdt.core.search.IJavaSearchScope;
23 import org.eclipse.jdt.ui.search.ElementQuerySpecification;
24 import org.eclipse.jdt.ui.search.QuerySpecification;
26 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
27 import org.eclipse.jdt.internal.ui.JavaPluginImages;
28 import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor;
29 import org.eclipse.jdt.internal.ui.search.JavaSearchScopeFactory;
30 import org.eclipse.jdt.internal.ui.search.SearchMessages;
33 * Finds field read accesses of the selected element in the enclosing project.
34 * The action is applicable to selections representing a Java field.
37 * This class may be instantiated; it is not intended to be subclassed.
42 * @noextend This class is not intended to be subclassed by clients.
44 public class FindReadReferencesInProjectAction extends FindReadReferencesAction {
47 * Creates a new <code>FindReadReferencesInProjectAction</code>. The action
48 * requires that the selection provided by the site's selection provider is of type
49 * <code>IStructuredSelection</code>.
51 * @param site the site providing context information for this action
53 public FindReadReferencesInProjectAction(IWorkbenchSite site) {
58 * Note: This constructor is for internal use only. Clients should not call this constructor.
59 * @param editor the Java editor
61 * @noreference This constructor is not intended to be referenced by clients.
63 public FindReadReferencesInProjectAction(JavaEditor editor) {
69 setText(SearchMessages.Search_FindReadReferencesInProjectAction_label);
70 setToolTipText(SearchMessages.Search_FindReadReferencesInProjectAction_tooltip);
71 setImageDescriptor(JavaPluginImages.DESC_OBJS_SEARCH_REF);
72 PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.FIND_READ_REFERENCES_IN_PROJECT_ACTION);
76 QuerySpecification createQuery(IJavaElement element) throws JavaModelException {
77 JavaSearchScopeFactory factory= JavaSearchScopeFactory.getInstance();
78 JavaEditor editor= getEditor();
80 IJavaSearchScope scope;
82 boolean isInsideJRE= factory.isInsideJRE(element);
84 scope= factory.createJavaProjectSearchScope(editor.getEditorInput(), isInsideJRE);
85 description= factory.getProjectScopeDescription(editor.getEditorInput(), isInsideJRE);
87 scope= factory.createJavaProjectSearchScope(element.getJavaProject(), isInsideJRE);
88 description= factory.getProjectScopeDescription(element.getJavaProject(), isInsideJRE);
90 return new ElementQuerySpecification(element, getLimitTo(), scope, description);
93 public void generated_8196863578754530366(ReadReferencesSearchGroup readreferencessearchgroup, IWorkbenchSite site, ISelectionProvider specialSelectionProvider) {
94 setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_READ_ACCESS_IN_PROJECT);
96 readreferencessearchgroup.fFindReadReferencesInHierarchyAction= new FindReadReferencesInHierarchyAction(site);
97 readreferencessearchgroup.fFindReadReferencesInHierarchyAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_WRITE_ACCESS_IN_HIERARCHY);
99 readreferencessearchgroup.fFindReadReferencesInWorkingSetAction= new FindReadReferencesInWorkingSetAction(site);
100 readreferencessearchgroup.fFindReadReferencesInWorkingSetAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_WRITE_ACCESS_IN_WORKING_SET);
102 // register the actions as selection listeners
103 ISelectionProvider provider= specialSelectionProvider == null ? readreferencessearchgroup.fSite.getSelectionProvider() : specialSelectionProvider;
104 ISelection selection= provider.getSelection();
105 readreferencessearchgroup.registerAction(readreferencessearchgroup.fFindReadReferencesAction, provider, selection, specialSelectionProvider);
106 readreferencessearchgroup.registerAction(this, provider, selection, specialSelectionProvider);
107 readreferencessearchgroup.registerAction(readreferencessearchgroup.fFindReadReferencesInHierarchyAction, provider, selection, specialSelectionProvider);
108 readreferencessearchgroup.registerAction(readreferencessearchgroup.fFindReadReferencesInWorkingSetAction, provider, selection, specialSelectionProvider);