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 java.util.Iterator;
15 import org.eclipse.core.runtime.Assert;
17 import org.eclipse.jface.action.IAction;
18 import org.eclipse.jface.action.IMenuManager;
19 import org.eclipse.jface.action.MenuManager;
20 import org.eclipse.jface.action.Separator;
21 import org.eclipse.jface.viewers.ISelection;
22 import org.eclipse.jface.viewers.ISelectionChangedListener;
23 import org.eclipse.jface.viewers.ISelectionProvider;
24 import org.eclipse.jface.viewers.IStructuredSelection;
26 import org.eclipse.ui.IActionBars;
27 import org.eclipse.ui.IWorkbenchSite;
28 import org.eclipse.ui.IWorkingSet;
29 import org.eclipse.ui.actions.ActionGroup;
31 import org.eclipse.jdt.ui.IContextMenuConstants;
33 import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor;
34 import org.eclipse.jdt.internal.ui.search.SearchMessages;
35 import org.eclipse.jdt.internal.ui.search.SearchUtil;
38 * Action group that adds the search for read references actions to a
39 * context menu and the global menu bar.
42 * This class may be instantiated; it is not intended to be subclassed.
47 * @noextend This class is not intended to be subclassed by clients.
49 public class ReadReferencesSearchGroup extends ActionGroup {
51 private static final String MENU_TEXT= SearchMessages.group_readReferences;
53 public IWorkbenchSite fSite;
54 public JavaEditor fEditor;
55 private IActionBars fActionBars;
57 public String fGroupId;
59 public FindReadReferencesAction fFindReadReferencesAction;
60 public FindReadReferencesInProjectAction fFindReadReferencesInProjectAction;
61 public FindReadReferencesInHierarchyAction fFindReadReferencesInHierarchyAction;
62 public FindReadReferencesInWorkingSetAction fFindReadReferencesInWorkingSetAction;
65 * Creates a new <code>ReadReferencesSearchGroup</code>. The group requires
66 * that the selection provided by the site's selection provider is of type <code>
67 * org.eclipse.jface.viewers.IStructuredSelection</code>.
69 * @param site the view part that owns this action group
71 public ReadReferencesSearchGroup(IWorkbenchSite site) {
76 * Creates a new <code>ReadReferencesSearchGroup</code>. The group requires
77 * that the selection provided by the given selection provider is of type
78 * {@link IStructuredSelection}.
80 * @param site the site that will own the action group.
81 * @param specialSelectionProvider the selection provider used instead of the
82 * sites selection provider.
86 public ReadReferencesSearchGroup(IWorkbenchSite site, ISelectionProvider specialSelectionProvider) {
88 fGroupId= IContextMenuConstants.GROUP_SEARCH;
90 fFindReadReferencesAction= new FindReadReferencesAction(site);
91 fFindReadReferencesAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_WRITE_ACCESS_IN_WORKSPACE);
93 fFindReadReferencesInProjectAction= new FindReadReferencesInProjectAction(site);
94 fFindReadReferencesInProjectAction.generated_8196863578754530366(this, site, specialSelectionProvider);
98 * Note: This constructor is for internal use only. Clients should not call this constructor.
99 * @param editor the Java editor
101 * @noreference This constructor is not intended to be referenced by clients.
103 public ReadReferencesSearchGroup(JavaEditor editor) {
105 fEditor.generated_3714848810313080178(this); //$NON-NLS-1$
108 void registerAction(SelectionDispatchAction action, ISelectionProvider provider, ISelection selection, ISelectionProvider specialSelectionProvider) {
109 action.generated_7401468913292747534(provider, selection, specialSelectionProvider);
112 void addAction(IAction action, IMenuManager manager) {
113 if (action.isEnabled()) {
118 private void addWorkingSetAction(IWorkingSet[] workingSets, IMenuManager manager) {
121 action= new WorkingSetFindAction(fEditor, new FindReadReferencesInWorkingSetAction(fEditor, workingSets), SearchUtil.toString(workingSets));
123 action= new WorkingSetFindAction(fSite, new FindReadReferencesInWorkingSetAction(fSite, workingSets), SearchUtil.toString(workingSets));
124 action.generated_7671403876970365707(manager, this);
128 * Method declared on ActionGroup.
131 public void fillContextMenu(IMenuManager manager) {
132 MenuManager javaSearchMM= new MenuManager(MENU_TEXT, IContextMenuConstants.GROUP_SEARCH);
133 addAction(fFindReadReferencesAction, javaSearchMM);
134 addAction(fFindReadReferencesInProjectAction, javaSearchMM);
135 addAction(fFindReadReferencesInHierarchyAction, javaSearchMM);
137 javaSearchMM.add(new Separator());
139 Iterator<IWorkingSet[]> iter= SearchUtil.getLRUWorkingSets().sortedIterator();
140 while (iter.hasNext()) {
141 addWorkingSetAction(iter.next(), javaSearchMM);
143 addAction(fFindReadReferencesInWorkingSetAction, javaSearchMM);
145 if (!javaSearchMM.isEmpty())
146 manager.appendToGroup(fGroupId, javaSearchMM);
150 * Method declared on ActionGroup.
153 public void fillActionBars(IActionBars actionBars) {
154 Assert.isNotNull(actionBars);
155 super.fillActionBars(actionBars);
156 fActionBars= actionBars;
157 updateGlobalActionHandlers();
161 * Method declared on ActionGroup.
164 public void dispose() {
165 ISelectionProvider provider= fSite.getSelectionProvider();
166 if (provider != null) {
167 disposeAction(fFindReadReferencesAction, provider);
168 disposeAction(fFindReadReferencesInProjectAction, provider);
169 disposeAction(fFindReadReferencesInHierarchyAction, provider);
170 disposeAction(fFindReadReferencesInWorkingSetAction, provider);
172 fFindReadReferencesAction= null;
173 fFindReadReferencesInProjectAction= null;
174 fFindReadReferencesInHierarchyAction= null;
175 fFindReadReferencesInWorkingSetAction= null;
176 updateGlobalActionHandlers();
180 private void updateGlobalActionHandlers() {
181 if (fActionBars != null) {
182 fActionBars.setGlobalActionHandler(JdtActionConstants.FIND_READ_ACCESS_IN_WORKSPACE, fFindReadReferencesAction);
183 fActionBars.setGlobalActionHandler(JdtActionConstants.FIND_READ_ACCESS_IN_PROJECT, fFindReadReferencesInProjectAction);
184 fActionBars.setGlobalActionHandler(JdtActionConstants.FIND_READ_ACCESS_IN_HIERARCHY, fFindReadReferencesInHierarchyAction);
185 fActionBars.setGlobalActionHandler(JdtActionConstants.FIND_READ_ACCESS_IN_WORKING_SET, fFindReadReferencesInWorkingSetAction);
189 private void disposeAction(ISelectionChangedListener action, ISelectionProvider provider) {
191 provider.removeSelectionChangedListener(action);