--- FindReferencesInHierarchyAction.java	Wed Aug  5 23:13:09 2009
+++ FindReferencesInProjectAction.java	Wed Aug  5 23:13:30 2009
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
+ * Copyright (c) 2000, 2006 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -8,86 +8,99 @@
  * Contributors:
  *     IBM Corporation - initial API and implementation
  *******************************************************************************/
-package org.eclipse.jdt.ui.actions;
+package org.erlide.ui.search;
 
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IFileEditorInput;
 import org.eclipse.ui.IWorkbenchSite;
-import org.eclipse.ui.PlatformUI;
+import org.erlide.core.erlang.IErlElement;
+import org.erlide.ui.editors.erl.ErlangEditor;
 
-import org.eclipse.jdt.core.ICompilationUnit;
-import org.eclipse.jdt.core.IField;
-import org.eclipse.jdt.core.IJavaElement;
-import org.eclipse.jdt.core.ILocalVariable;
-import org.eclipse.jdt.core.IMethod;
-import org.eclipse.jdt.core.IType;
-import org.eclipse.jdt.core.ITypeParameter;
-import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.jdt.core.search.IJavaSearchScope;
-import org.eclipse.jdt.core.search.SearchEngine;
-
-import org.eclipse.jdt.ui.search.ElementQuerySpecification;
-import org.eclipse.jdt.ui.search.QuerySpecification;
-
-import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
-import org.eclipse.jdt.internal.ui.JavaPluginImages;
-import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor;
-import org.eclipse.jdt.internal.ui.search.JavaSearchScopeFactory;
-import org.eclipse.jdt.internal.ui.search.SearchMessages;
-
 /**
- * Finds references of the selected element in its hierarchy.
- * The action is applicable to selections representing a Java element.
- *
+ * Finds references to the selected element in the enclosing project of the
+ * selected element. The action is applicable to selections representing a Java
+ * element.
+ * 
  * <p>
  * This class may be instantiated; it is not intended to be subclassed.
  * </p>
- *
- * @since 2.0
- *
- * @noextend This class is not intended to be subclassed by clients.
+ * 
+ * @since 3.0
  */
-public class FindReferencesInHierarchyAction extends FindReferencesAction {
+public class FindReferencesInProjectAction extends FindReferencesAction {
 
 	/**
-	 * Creates a new <code>FindReferencesInHierarchyAction</code>. The action
-	 * requires that the selection provided by the site's selection provider is of type
-	 * <code>org.eclipse.jface.viewers.IStructuredSelection</code>.
-	 *
-	 * @param site the site providing context information for this action
+	 * Creates a new <code>FindReferencesInProjectAction</code>. The action
+	 * requires that the selection provided by the site's selection provider is
+	 * of type <code>IStructuredSelection</code>.
+	 * 
+	 * @param site
+	 *            the site providing context information for this action
 	 */
-	public FindReferencesInHierarchyAction(IWorkbenchSite site) {
+	public FindReferencesInProjectAction(final IWorkbenchSite site) {
 		super(site);
 	}
 
 	/**
-	 * 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.
+	 * Note: This constructor is for internal use only. Clients should not call
+	 * this constructor.
+	 * 
+	 * @param editor
+	 *            the Java editor
 	 */
-	public FindReferencesInHierarchyAction(JavaEditor editor) {
+	public FindReferencesInProjectAction(final ErlangEditor editor) {
 		super(editor);
 	}
 
-	Class[] getValidTypes() {
-		return new Class[] { ICompilationUnit.class, IType.class, IMethod.class, IField.class, ILocalVariable.class, ITypeParameter.class };
+	@Override
+	Class<?>[] getValidTypes() {
+		return new Class[] { IErlElement.class };
 	}
 
+	@Override
 	void init() {
-		setText(SearchMessages.Search_FindHierarchyReferencesAction_label);
-		setToolTipText(SearchMessages.Search_FindHierarchyReferencesAction_tooltip);
-		setImageDescriptor(JavaPluginImages.DESC_OBJS_SEARCH_REF);
-		PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.FIND_REFERENCES_IN_HIERARCHY_ACTION);
+		setText("Project");
+		setToolTipText("Find references in selected projects");
+		// FIXME setImageDescriptor(JavaPluginImages.DESC_OBJS_SEARCH_REF);
+		// FIXME PlatformUI.getWorkbench().getHelpSystem().setHelp(this,
+		// IJavaHelpContextIds.FIND_REFERENCES_IN_PROJECT_ACTION);
 	}
 
-	QuerySpecification createQuery(IJavaElement element) throws JavaModelException, InterruptedException {
-		IType type= getType(element);
-		if (type == null) {
-			return super.createQuery(element);
+	@Override
+	protected String[] getScope() {
+		final IEditorInput editorInput = getEditor().getEditorInput();
+		if (editorInput instanceof IFileEditorInput) {
+			final IFileEditorInput input = (IFileEditorInput) editorInput;
+			final IFile file = input.getFile();
+			final IProject project = file.getProject();
+			return SearchUtil.getProjectScope(project);
 		}
-		JavaSearchScopeFactory factory= JavaSearchScopeFactory.getInstance();
-		IJavaSearchScope scope= SearchEngine.createHierarchyScope(type);
-		String description= factory.getHierarchyScopeDescription(type);
-		return new ElementQuerySpecification(element, getLimitTo(), scope, description);
+		return null;
 	}
+
+	// QuerySpecification createQuery(IJavaElement element)
+	// throws JavaModelException {
+	// JavaSearchScopeFactory factory = JavaSearchScopeFactory.getInstance();
+	// JavaEditor editor = getEditor();
+	//
+	// IJavaSearchScope scope;
+	// String description;
+	// final boolean isInsideJRE = factory.isInsideJRE(element);
+	// if (editor != null) {
+	// scope = factory.createJavaProjectSearchScope(editor
+	// .getEditorInput(), isInsideJRE);
+	// description = factory.getProjectScopeDescription(editor
+	// .getEditorInput(), isInsideJRE);
+	// } else {
+	// scope = factory.createJavaProjectSearchScope(element
+	// .getJavaProject(), isInsideJRE);
+	// description = factory.getProjectScopeDescription(element
+	// .getJavaProject(), isInsideJRE);
+	// }
+	// return new ElementQuerySpecification(element, getLimitTo(), scope,
+	// description);
+	// }
 
 }
