--- OccurrencesSearchGroup.java	Wed Aug  5 22:53:21 2009
+++ ReadReferencesSearchGroup.java	Wed Aug  5 22:53:09 2009
@@ -10,77 +10,72 @@
  *******************************************************************************/
 package org.eclipse.jdt.ui.actions;
 
+import java.util.Iterator;
+
 import org.eclipse.core.runtime.Assert;
 
-import org.eclipse.jface.action.Action;
-import org.eclipse.jface.action.IMenuListener;
+import org.eclipse.jface.action.IAction;
 import org.eclipse.jface.action.IMenuManager;
 import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.action.Separator;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.ISelectionChangedListener;
 import org.eclipse.jface.viewers.ISelectionProvider;
 import org.eclipse.jface.viewers.IStructuredSelection;
 
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.ITextSelection;
-
 import org.eclipse.ui.IActionBars;
 import org.eclipse.ui.IWorkbenchSite;
-import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.IWorkingSet;
 import org.eclipse.ui.actions.ActionGroup;
-import org.eclipse.ui.keys.IBindingService;
 
 import org.eclipse.ui.texteditor.ITextEditorActionConstants;
 
-import org.eclipse.jdt.core.ITypeRoot;
-
 import org.eclipse.jdt.ui.IContextMenuConstants;
-import org.eclipse.jdt.ui.JavaUI;
 
-import org.eclipse.jdt.internal.ui.actions.SelectionConverter;
 import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor;
-import org.eclipse.jdt.internal.ui.javaeditor.JavaTextSelection;
 import org.eclipse.jdt.internal.ui.search.SearchMessages;
+import org.eclipse.jdt.internal.ui.search.SearchUtil;
 
 /**
- * Action group that adds the occurrences in file actions
- * to a context menu and the global menu bar.
+ * Action group that adds the search for read references actions to a
+ * context menu and the global menu bar.
  *
  * <p>
  * This class may be instantiated; it is not intended to be subclassed.
  * </p>
  *
- * @since 3.1
+ * @since 2.0
  *
  * @noextend This class is not intended to be subclassed by clients.
  */
-public class OccurrencesSearchGroup extends ActionGroup  {
+public class ReadReferencesSearchGroup extends ActionGroup  {
 
+	private static final String MENU_TEXT= SearchMessages.group_readReferences;
+
 	private IWorkbenchSite fSite;
 	private JavaEditor fEditor;
 	private IActionBars fActionBars;
 
 	private String fGroupId;
 
-	private FindOccurrencesInFileAction fOccurrencesInFileAction;
-	private FindExceptionOccurrencesAction fExceptionOccurrencesAction;
-	private FindImplementOccurrencesAction fFindImplementorOccurrencesAction;
-	private FindBreakContinueTargetOccurrencesAction fBreakContinueTargetOccurrencesAction;
-	private FindMethodExitOccurrencesAction fMethodExitOccurrencesAction;
+	private FindReadReferencesAction fFindReadReferencesAction;
+	private FindReadReferencesInProjectAction fFindReadReferencesInProjectAction;
+	private FindReadReferencesInHierarchyAction fFindReadReferencesInHierarchyAction;
+	private FindReadReferencesInWorkingSetAction fFindReadReferencesInWorkingSetAction;
 
 	/**
-	 * Creates a new <code>ImplementorsSearchGroup</code>. The group
-	 * requires that the selection provided by the site's selection provider
-	 * is of type <code>org.eclipse.jface.viewers.IStructuredSelection</code>.
+	 * Creates a new <code>ReadReferencesSearchGroup</code>. The group requires
+	 * that the selection provided by the site's selection provider is of type <code>
+	 * org.eclipse.jface.viewers.IStructuredSelection</code>.
 	 *
 	 * @param site the view part that owns this action group
 	 */
-	public OccurrencesSearchGroup(IWorkbenchSite site) {
+	public ReadReferencesSearchGroup(IWorkbenchSite site) {
 		this(site, null);
 	}
 
 	/**
-	 * Creates a new <code>OccurrencesSearchGroup</code>. The group requires
+	 * Creates a new <code>ReadReferencesSearchGroup</code>. The group requires
 	 * that the selection provided by the given selection provider is of type
 	 * {@link IStructuredSelection}.
 	 *
@@ -90,79 +85,57 @@
 	 *
 	 * @since 3.4
 	 */
-	public OccurrencesSearchGroup(IWorkbenchSite site, ISelectionProvider specialSelectionProvider) {
+	public ReadReferencesSearchGroup(IWorkbenchSite site, ISelectionProvider specialSelectionProvider) {
 		fSite= site;
 		fGroupId= IContextMenuConstants.GROUP_SEARCH;
 
-		fOccurrencesInFileAction= new FindOccurrencesInFileAction(site);
-		fOccurrencesInFileAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_OCCURRENCES_IN_FILE);
-		// Need to reset the label
-		fOccurrencesInFileAction.setText(SearchMessages.Search_FindOccurrencesInFile_shortLabel);
+		fFindReadReferencesAction= new FindReadReferencesAction(site);
+		fFindReadReferencesAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_WRITE_ACCESS_IN_WORKSPACE);
 
-		fExceptionOccurrencesAction= new FindExceptionOccurrencesAction(site);
-		fExceptionOccurrencesAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_EXCEPTION_OCCURRENCES_IN_FILE);
+		fFindReadReferencesInProjectAction= new FindReadReferencesInProjectAction(site);
+		fFindReadReferencesInProjectAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_READ_ACCESS_IN_PROJECT);
 
-		fFindImplementorOccurrencesAction= new FindImplementOccurrencesAction(site);
-		fFindImplementorOccurrencesAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_IMPLEMENT_OCCURRENCES_IN_FILE);
+		fFindReadReferencesInHierarchyAction= new FindReadReferencesInHierarchyAction(site);
+		fFindReadReferencesInHierarchyAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_WRITE_ACCESS_IN_HIERARCHY);
 
-		fBreakContinueTargetOccurrencesAction= new FindBreakContinueTargetOccurrencesAction(site);
-		fBreakContinueTargetOccurrencesAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_BREAK_CONTINUE_TARGET_OCCURRENCES);
+		fFindReadReferencesInWorkingSetAction= new FindReadReferencesInWorkingSetAction(site);
+		fFindReadReferencesInWorkingSetAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_WRITE_ACCESS_IN_WORKING_SET);
 
-		fMethodExitOccurrencesAction= new FindMethodExitOccurrencesAction(site);
-		fMethodExitOccurrencesAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_METHOD_EXIT_OCCURRENCES);
-
-
 		// register the actions as selection listeners
 		ISelectionProvider provider= specialSelectionProvider == null ? fSite.getSelectionProvider() : specialSelectionProvider;
 		ISelection selection= provider.getSelection();
-		registerAction(fOccurrencesInFileAction, provider, selection, specialSelectionProvider);
-		registerAction(fExceptionOccurrencesAction, provider, selection, specialSelectionProvider);
-		registerAction(fFindImplementorOccurrencesAction, provider, selection, specialSelectionProvider);
-		registerAction(fBreakContinueTargetOccurrencesAction, provider, selection, specialSelectionProvider);
-		registerAction(fMethodExitOccurrencesAction, provider, selection, specialSelectionProvider);
+		registerAction(fFindReadReferencesAction, provider, selection, specialSelectionProvider);
+		registerAction(fFindReadReferencesInProjectAction, provider, selection, specialSelectionProvider);
+		registerAction(fFindReadReferencesInHierarchyAction, provider, selection, specialSelectionProvider);
+		registerAction(fFindReadReferencesInWorkingSetAction, provider, selection, specialSelectionProvider);
 	}
 
 	/**
 	 * Note: This constructor is for internal use only. Clients should not call this constructor.
-	 *
 	 * @param editor the Java editor
 	 *
 	 * @noreference This constructor is not intended to be referenced by clients.
 	 */
-	public OccurrencesSearchGroup(JavaEditor editor) {
+	public ReadReferencesSearchGroup(JavaEditor editor) {
 		fEditor= editor;
 		fSite= fEditor.getSite();
 		fGroupId= ITextEditorActionConstants.GROUP_FIND;
 
-		fOccurrencesInFileAction= new FindOccurrencesInFileAction(fEditor);
-		fOccurrencesInFileAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_OCCURRENCES_IN_FILE);
-		// Need to reset the label
-		fOccurrencesInFileAction.setText(SearchMessages.Search_FindOccurrencesInFile_shortLabel);
-		fEditor.setAction("SearchOccurrencesInFile", fOccurrencesInFileAction); //$NON-NLS-1$
+		fFindReadReferencesAction= new FindReadReferencesAction(fEditor);
+		fFindReadReferencesAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_WRITE_ACCESS_IN_WORKSPACE);
+		fEditor.setAction("SearchReadAccessInWorkspace", fFindReadReferencesAction); //$NON-NLS-1$
 
-		fExceptionOccurrencesAction= new FindExceptionOccurrencesAction(fEditor);
-		fExceptionOccurrencesAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_EXCEPTION_OCCURRENCES_IN_FILE);
-		fEditor.setAction("SearchExceptionOccurrences", fExceptionOccurrencesAction); //$NON-NLS-1$
+		fFindReadReferencesInProjectAction= new FindReadReferencesInProjectAction(fEditor);
+		fFindReadReferencesInProjectAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_READ_ACCESS_IN_PROJECT);
+		fEditor.setAction("SearchReadAccessInProject", fFindReadReferencesInProjectAction); //$NON-NLS-1$
 
-		fFindImplementorOccurrencesAction= new FindImplementOccurrencesAction(fEditor);
-		fFindImplementorOccurrencesAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_IMPLEMENT_OCCURRENCES_IN_FILE);
-		fEditor.setAction("SearchImplementOccurrences", fFindImplementorOccurrencesAction); //$NON-NLS-1$
+		fFindReadReferencesInHierarchyAction= new FindReadReferencesInHierarchyAction(fEditor);
+		fFindReadReferencesInHierarchyAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_WRITE_ACCESS_IN_HIERARCHY);
+		fEditor.setAction("SearchReadAccessInHierarchy", fFindReadReferencesInHierarchyAction); //$NON-NLS-1$
 
-		fBreakContinueTargetOccurrencesAction= new FindBreakContinueTargetOccurrencesAction(fEditor);
-		fBreakContinueTargetOccurrencesAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_BREAK_CONTINUE_TARGET_OCCURRENCES);
-		fEditor.setAction("BreakContinueTargetOccurrences", fBreakContinueTargetOccurrencesAction); //$NON-NLS-1$
-
-		fMethodExitOccurrencesAction= new FindMethodExitOccurrencesAction(fEditor);
-		fMethodExitOccurrencesAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_METHOD_EXIT_OCCURRENCES);
-		fEditor.setAction("ExitOccurrencesAction", fMethodExitOccurrencesAction); //$NON-NLS-1$
-
-//
-//		ISelectionProvider provider= fSite.getSelectionProvider();
-//		ISelection selection= provider.getSelection();
-//
-//		registerAction(fOccurrencesInFileAction, provider, selection);
-//		registerAction(fExceptionOccurrencesAction, provider, selection);
-//		registerAction(fFindImplementorOccurrencesAction, provider, selection);
+		fFindReadReferencesInWorkingSetAction= new FindReadReferencesInWorkingSetAction(fEditor);
+		fFindReadReferencesInWorkingSetAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_WRITE_ACCESS_IN_WORKING_SET);
+		fEditor.setAction("SearchReadAccessInWorkingSet", fFindReadReferencesInWorkingSetAction); //$NON-NLS-1$
 	}
 
 	private void registerAction(SelectionDispatchAction action, ISelectionProvider provider, ISelection selection, ISelectionProvider specialSelectionProvider) {
@@ -172,69 +145,42 @@
 			action.setSpecialSelectionProvider(specialSelectionProvider);
 	}
 
-	/*
-	 * Method declared on ActionGroup.
-	 */
-	public void fillContextMenu(IMenuManager manager) {
-		String menuText= SearchMessages.group_occurrences;
-		String shortcut= getShortcutString();
-		if (shortcut != null) {
-			menuText= menuText + '\t' + shortcut;
+	private void addAction(IAction action, IMenuManager manager) {
+		if (action.isEnabled()) {
+			manager.add(action);
 		}
+	}
 
-		MenuManager javaSearchMM= new MenuManager(menuText, IContextMenuConstants.GROUP_SEARCH);
-		javaSearchMM.add(new Action() {
-		});
-		javaSearchMM.addMenuListener(new IMenuListener() {
-			public void menuAboutToShow(IMenuManager mm) {
-				mm.removeAll();
-				updateActionsInJavaEditor();
-				addAction(fOccurrencesInFileAction, mm);
-				addAction(fFindImplementorOccurrencesAction, mm);
-				addAction(fExceptionOccurrencesAction, mm);
-				addAction(fMethodExitOccurrencesAction, mm);
-				addAction(fBreakContinueTargetOccurrencesAction, mm);
-				if (mm.isEmpty()) {
-					mm.add(new Action(SearchMessages.group_occurrences_quickMenu_noEntriesAvailable) {
-						public boolean isEnabled() {
-							return false;
-						}
-					});
-				}
-			}
-
-			private void addAction(Action action, IMenuManager mm) {
-				if (action.isEnabled())
-					mm.add(action);
-			}
-		});
-		manager.appendToGroup(fGroupId, javaSearchMM);
+	private void addWorkingSetAction(IWorkingSet[] workingSets, IMenuManager manager) {
+		FindAction action;
+		if (fEditor != null)
+			action= new WorkingSetFindAction(fEditor, new FindReadReferencesInWorkingSetAction(fEditor, workingSets), SearchUtil.toString(workingSets));
+		else
+			action= new WorkingSetFindAction(fSite, new FindReadReferencesInWorkingSetAction(fSite, workingSets), SearchUtil.toString(workingSets));
+		action.update(getContext().getSelection());
+		addAction(action, manager);
 	}
 
-	private void updateActionsInJavaEditor() {
-		if (fEditor == null)
-			return;
 
-		ITypeRoot element= SelectionConverter.getInput(fEditor);
-		if (element == null)
-			return;
+	/* (non-Javadoc)
+	 * Method declared on ActionGroup.
+	 */
+	public void fillContextMenu(IMenuManager manager) {
+		MenuManager javaSearchMM= new MenuManager(MENU_TEXT, IContextMenuConstants.GROUP_SEARCH);
+		addAction(fFindReadReferencesAction, javaSearchMM);
+		addAction(fFindReadReferencesInProjectAction, javaSearchMM);
+		addAction(fFindReadReferencesInHierarchyAction, javaSearchMM);
 
-		ITextSelection textSelection= (ITextSelection) fEditor.getSelectionProvider().getSelection();
-		IDocument document= JavaUI.getDocumentProvider().getDocument(fEditor.getEditorInput());
-		JavaTextSelection javaSelection= new JavaTextSelection(element, document, textSelection.getOffset(), textSelection.getLength());
+		javaSearchMM.add(new Separator());
 
-		fExceptionOccurrencesAction.update(javaSelection);
-		fOccurrencesInFileAction.update(javaSelection);
-		fFindImplementorOccurrencesAction.update(javaSelection);
-		fBreakContinueTargetOccurrencesAction.update(javaSelection);
-		fMethodExitOccurrencesAction.update(javaSelection);
-	}
+		Iterator iter= SearchUtil.getLRUWorkingSets().sortedIterator();
+		while (iter.hasNext()) {
+			addWorkingSetAction((IWorkingSet[]) iter.next(), javaSearchMM);
+		}
+		addAction(fFindReadReferencesInWorkingSetAction, javaSearchMM);
 
-	private String getShortcutString() {
-		IBindingService bindingService= (IBindingService)PlatformUI.getWorkbench().getAdapter(IBindingService.class);
-		if (bindingService == null)
-			return null;
-		return bindingService.getBestActiveBindingFormattedFor(IJavaEditorActionDefinitionIds.SEARCH_OCCURRENCES_IN_FILE_QUICK_MENU);
+		if (!javaSearchMM.isEmpty())
+			manager.appendToGroup(fGroupId, javaSearchMM);
 	}
 
 	/*
@@ -253,29 +199,25 @@
 	public void dispose() {
 		ISelectionProvider provider= fSite.getSelectionProvider();
 		if (provider != null) {
-			disposeAction(fFindImplementorOccurrencesAction, provider);
-			disposeAction(fExceptionOccurrencesAction, provider);
-			disposeAction(fOccurrencesInFileAction, provider);
-			disposeAction(fMethodExitOccurrencesAction, provider);
-			disposeAction(fBreakContinueTargetOccurrencesAction, provider);
+			disposeAction(fFindReadReferencesAction, provider);
+			disposeAction(fFindReadReferencesInProjectAction, provider);
+			disposeAction(fFindReadReferencesInHierarchyAction, provider);
+			disposeAction(fFindReadReferencesInWorkingSetAction, provider);
 		}
-		super.dispose();
-		fFindImplementorOccurrencesAction= null;
-		fExceptionOccurrencesAction= null;
-		fOccurrencesInFileAction= null;
-		fMethodExitOccurrencesAction= null;
-		fBreakContinueTargetOccurrencesAction= null;
+		fFindReadReferencesAction= null;
+		fFindReadReferencesInProjectAction= null;
+		fFindReadReferencesInHierarchyAction= null;
+		fFindReadReferencesInWorkingSetAction= null;
 		updateGlobalActionHandlers();
+		super.dispose();
 	}
 
 	private void updateGlobalActionHandlers() {
 		if (fActionBars != null) {
-			fActionBars.setGlobalActionHandler(JdtActionConstants.FIND_OCCURRENCES_IN_FILE, fOccurrencesInFileAction);
-			fActionBars.setGlobalActionHandler(JdtActionConstants.FIND_EXCEPTION_OCCURRENCES, fExceptionOccurrencesAction);
-			fActionBars.setGlobalActionHandler(JdtActionConstants.FIND_IMPLEMENT_OCCURRENCES, fFindImplementorOccurrencesAction);
-			fActionBars.setGlobalActionHandler(JdtActionConstants.FIND_BREAK_CONTINUE_TARGET_OCCURRENCES, fBreakContinueTargetOccurrencesAction);
-			fActionBars.setGlobalActionHandler(JdtActionConstants.FIND_METHOD_EXIT_OCCURRENCES, fMethodExitOccurrencesAction);
-
+			fActionBars.setGlobalActionHandler(JdtActionConstants.FIND_READ_ACCESS_IN_WORKSPACE, fFindReadReferencesAction);
+			fActionBars.setGlobalActionHandler(JdtActionConstants.FIND_READ_ACCESS_IN_PROJECT, fFindReadReferencesInProjectAction);
+			fActionBars.setGlobalActionHandler(JdtActionConstants.FIND_READ_ACCESS_IN_HIERARCHY, fFindReadReferencesInHierarchyAction);
+			fActionBars.setGlobalActionHandler(JdtActionConstants.FIND_READ_ACCESS_IN_WORKING_SET, fFindReadReferencesInWorkingSetAction);
 		}
 	}
 
