[127270] add support for project and working set search scopes
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/search/actions/FindReferencesAction.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/search/actions/FindReferencesAction.java
index 32d642a..ce0476d 100644
--- a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/search/actions/FindReferencesAction.java
+++ b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/search/actions/FindReferencesAction.java
@@ -29,63 +29,105 @@
import org.eclipse.xsd.XSDNamedComponent;
import org.eclipse.xsd.XSDSimpleTypeDefinition;
-public class FindReferencesAction extends FindAction
-{
- public FindReferencesAction(IEditorPart editor)
- {
- super(editor);
- }
-
- public void setActionDefinitionId(String string)
- {
-
- }
-
- public void run()
- {
- String pattern = "";
- if (editor != null)
- {
- IEditorInput input = editor.getEditorInput();
- if (input instanceof IFileEditorInput)
- {
- IFileEditorInput fileEditorInput = (IFileEditorInput)input;
- IFile file = fileEditorInput.getFile();
- ISelectionProvider provider = (ISelectionProvider)editor.getAdapter(ISelectionProvider.class);
- if (provider != null)
- {
- ISelection selection = provider.getSelection();
- if (selection != null && selection instanceof IStructuredSelection)
- {
- IStructuredSelection s = (IStructuredSelection)selection;
- Object o = s.getFirstElement();
- if (o != null && o instanceof XSDNamedComponent)
- {
- XSDNamedComponent c = (XSDNamedComponent)o;
- QualifiedName metaName = null;
- if (c instanceof XSDComplexTypeDefinition)
- {
- metaName = IXSDSearchConstants.COMPLEX_TYPE_META_NAME;
- }
- else if (c instanceof XSDSimpleTypeDefinition)
- {
- metaName = IXSDSearchConstants.SIMPLE_TYPE_META_NAME;
- }
- else if (c instanceof XSDElementDeclaration)
- {
- metaName = IXSDSearchConstants.ELEMENT_META_NAME;
- }
- QualifiedName elementQName = new QualifiedName(c.getTargetNamespace(), c.getName());
- System.out.println("name" + c.getTargetNamespace() + ":" + c.getName());
- SearchScope scope = new WorkspaceSearchScope();
- String scopeDescription = "Workspace";
- XSDSearchQuery searchQuery= new XSDSearchQuery(pattern, file, elementQName, metaName, XSDSearchQuery.LIMIT_TO_REFERENCES, scope, scopeDescription);
- NewSearchUI.activateSearchResultView();
- NewSearchUI.runQueryInBackground(searchQuery);
- }
- }
- }
- }
- }
- }
+public class FindReferencesAction extends FindAction{
+ public FindReferencesAction(IEditorPart editor)
+ {
+ super(editor);
+ }
+
+ public void setActionDefinitionId(String string)
+ {
+
+ }
+
+ /**
+ * To be used by subclass in its run()
+ * Returns the file where the selection of a component (from the user) occurs
+ * ie. Returns the file that the user is currently working on.
+ * @return The IFile representation of the current working file.
+ */
+ protected IFile getCurrentFile(){
+ if (editor != null){
+ IEditorInput input = editor.getEditorInput();
+ if (input instanceof IFileEditorInput){
+ IFileEditorInput fileEditorInput = (IFileEditorInput)input;
+ return fileEditorInput.getFile();
+ }
+ }
+ return null;
+ }
+
+ /**
+ * To be used by subclass in its run()
+ * Works with the Editor to return the selected XSD component which the user
+ * wants to do the search on.
+ * @return
+ * The XSDNamedComponent that the user points to (using cursor).
+ */
+ protected XSDNamedComponent getXSDNamedComponent(){
+ if (editor != null){
+ ISelectionProvider provider =
+ (ISelectionProvider) editor.getAdapter(ISelectionProvider.class);
+ if (provider != null)
+ {
+ ISelection selection = provider.getSelection();
+ if (selection != null && selection instanceof IStructuredSelection)
+ {
+ IStructuredSelection s = (IStructuredSelection) selection;
+ Object o = s.getFirstElement();
+ if (o != null && o instanceof XSDNamedComponent)
+ {
+ return (XSDNamedComponent) o;
+ }
+ }
+ }
+ }
+ //The expected component we get from the editor does not meet
+ // our expectation
+ return null;
+ }
+
+ /**
+ * To be used by subclass in its run()..
+ * Determines the metaName of the XSD component given to this method.
+ * @param component The component of which we want to determine the name
+ * @return
+ */
+ protected QualifiedName determineMetaName(XSDNamedComponent component){
+ QualifiedName metaName = null;
+ if (component instanceof XSDComplexTypeDefinition)
+ {
+ metaName = IXSDSearchConstants.COMPLEX_TYPE_META_NAME;
+ }
+ else if (component instanceof XSDSimpleTypeDefinition)
+ {
+ metaName = IXSDSearchConstants.SIMPLE_TYPE_META_NAME;
+ }
+ else if (component instanceof XSDElementDeclaration)
+ {
+ metaName = IXSDSearchConstants.ELEMENT_META_NAME;
+ }
+ return metaName;
+ }
+
+ public void run()
+ {
+ String pattern = "";
+
+ XSDNamedComponent component = getXSDNamedComponent();
+ IFile file = getCurrentFile();
+ if ( file != null && component != null){
+ QualifiedName metaName = determineMetaName(component);
+
+ QualifiedName elementQName =
+ new QualifiedName(component.getTargetNamespace(), component.getName());
+
+ SearchScope scope = new WorkspaceSearchScope();
+ String scopeDescription = "Workspace";
+ XSDSearchQuery searchQuery =
+ new XSDSearchQuery(pattern, file, elementQName, metaName, XSDSearchQuery.LIMIT_TO_REFERENCES, scope, scopeDescription);
+ NewSearchUI.activateSearchResultView();
+ NewSearchUI.runQueryInBackground(searchQuery);
+ }
+ }
}
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/search/actions/FindReferencesInProjectAction.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/search/actions/FindReferencesInProjectAction.java
new file mode 100644
index 0000000..34371e7
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/search/actions/FindReferencesInProjectAction.java
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *
+ *******************************************************************************/
+package org.eclipse.wst.xsd.ui.internal.search.actions;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.search.ui.NewSearchUI;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.wst.common.core.search.pattern.QualifiedName;
+import org.eclipse.wst.common.core.search.scope.ProjectSearchScope;
+import org.eclipse.wst.xsd.ui.internal.search.XSDSearchQuery;
+import org.eclipse.xsd.XSDNamedComponent;
+
+public class FindReferencesInProjectAction extends FindReferencesAction {
+
+ public FindReferencesInProjectAction(IEditorPart editor) {
+ super(editor);
+ }
+
+ public void run()
+ {
+ String pattern = "";
+
+ XSDNamedComponent component = getXSDNamedComponent();
+ IFile file = getCurrentFile();
+
+ if ( file != null && component != null){
+ QualifiedName metaName = determineMetaName(component);
+
+ QualifiedName elementQName =
+ new QualifiedName(component.getTargetNamespace(), component.getName());
+
+ IPath fullPath = (IPath) file.getFullPath();
+ ProjectSearchScope scope =
+ new ProjectSearchScope( fullPath);
+
+ String scopeDescription = "Workspace";
+ XSDSearchQuery searchQuery =
+ new XSDSearchQuery(pattern, file, elementQName, metaName, XSDSearchQuery.LIMIT_TO_REFERENCES, scope, scopeDescription);
+ NewSearchUI.activateSearchResultView();
+ NewSearchUI.runQueryInBackground(searchQuery);
+ }
+ }
+}
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/search/actions/FindReferencesInWorkingSetAction.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/search/actions/FindReferencesInWorkingSetAction.java
new file mode 100644
index 0000000..67b0b53
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/search/actions/FindReferencesInWorkingSetAction.java
@@ -0,0 +1,88 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *
+ *******************************************************************************/
+package org.eclipse.wst.xsd.ui.internal.search.actions;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.jface.window.Window;
+import org.eclipse.search.ui.NewSearchUI;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IWorkingSet;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.dialogs.IWorkingSetSelectionDialog;
+import org.eclipse.wst.common.core.search.pattern.QualifiedName;
+import org.eclipse.wst.common.core.search.scope.WorkingSetSearchScope;
+import org.eclipse.wst.xsd.ui.internal.XSDEditorPlugin;
+import org.eclipse.wst.xsd.ui.internal.search.XSDSearchQuery;
+import org.eclipse.xsd.XSDNamedComponent;
+
+public class FindReferencesInWorkingSetAction extends FindReferencesAction{
+
+ public FindReferencesInWorkingSetAction(IEditorPart editor) {
+ super(editor);
+ }
+
+ public void setActionDefinitionId(String string)
+ {
+
+ }
+
+ public void run(){
+ IWorkingSet[] workingSets = queryWorkingSets();
+ if ( workingSets == null || workingSets.length == 0)
+ // The user chooses nothing, no point to continue.
+ return;
+ String pattern = "";
+
+ XSDNamedComponent component = getXSDNamedComponent();
+ IFile file = getCurrentFile();
+ if ( file != null && component != null){
+ QualifiedName metaName = determineMetaName(component);
+
+ QualifiedName elementQName =
+ new QualifiedName(component.getTargetNamespace(), component.getName());
+
+ // Create a scope from the selected working sets
+ WorkingSetSearchScope scope = new WorkingSetSearchScope();
+ for (int i = 0; i < workingSets.length; i++){
+ IAdaptable[] elements = workingSets[i].getElements();
+ scope.addAWorkingSetToScope(elements);
+ }
+
+ String scopeDescription = "Workspace";
+ XSDSearchQuery searchQuery =
+ new XSDSearchQuery(pattern, file, elementQName, metaName, XSDSearchQuery.LIMIT_TO_REFERENCES, scope, scopeDescription);
+ NewSearchUI.activateSearchResultView();
+ NewSearchUI.runQueryInBackground(searchQuery);
+ }
+ }
+
+ /**
+ * Calls a dialog asking the user to choose the working Sets he wants
+ * to do the search on
+ * @return
+ */
+ public static IWorkingSet[] queryWorkingSets(){
+ Shell shell= XSDEditorPlugin.getShell();
+ if (shell == null)
+ return null;
+ IWorkingSetSelectionDialog dialog =
+ PlatformUI.getWorkbench().getWorkingSetManager().createWorkingSetSelectionDialog(shell, true);
+ if (dialog.open() == Window.OK) {
+ IWorkingSet[] workingSets= dialog.getSelection();
+ if (workingSets.length > 0)
+ return workingSets;
+ }
+ return null;
+ }
+}
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/search/actions/ReferencesSearchGroup.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/search/actions/ReferencesSearchGroup.java
index b11bf7d..b9e4bcc 100644
--- a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/search/actions/ReferencesSearchGroup.java
+++ b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/search/actions/ReferencesSearchGroup.java
@@ -23,16 +23,7 @@
import org.eclipse.ui.IWorkbenchSite;
import org.eclipse.ui.texteditor.ITextEditorActionConstants;
-/**
- * Action group that adds the search for 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 2.0
- */
+
public class ReferencesSearchGroup extends SearchGroup {
private static final String MENU_TEXT= "References...";//SearchMessages.group_references;
@@ -44,9 +35,8 @@
private String fGroupId;
private FindReferencesAction fFindReferencesAction;
- private FindReferencesAction fFindReferencesInProjectAction;
- //private FindReferencesAction fFindReferencesInHierarchyAction;
- private FindReferencesAction fFindReferencesInWorkingSetAction;
+ private FindReferencesInProjectAction fFindReferencesInProjectAction;
+ private FindReferencesInWorkingSetAction fFindReferencesInWorkingSetAction;
/**
@@ -64,17 +54,12 @@
fFindReferencesAction.setActionDefinitionId("SEARCH_REFERENCES_IN_WORKSPACE");
//fEditor.setAction("SearchReferencesInWorkspace", fFindReferencesAction); //$NON-NLS-1$
- fFindReferencesInProjectAction= new FindReferencesAction(fEditor);
+ fFindReferencesInProjectAction= new FindReferencesInProjectAction(fEditor);
fFindReferencesInProjectAction.setText("Project");
fFindReferencesInProjectAction.setActionDefinitionId("SEARCH_REFERENCES_IN_PROJECT");
//fEditor.setAction("SearchReferencesInProject", fFindReferencesInProjectAction); //$NON-NLS-1$
-/*
- fFindReferencesInHierarchyAction= new FindReferencesAction(fEditor);
- fFindReferencesInHierarchyAction.setText("Hierarchy");
- fFindReferencesInHierarchyAction.setActionDefinitionId("SEARCH_REFERENCES_IN_HIERARCHY");
- //fEditor.setAction("SearchReferencesInHierarchy", fFindReferencesInHierarchyAction); //$NON-NLS-1$
- */
- fFindReferencesInWorkingSetAction= new FindReferencesAction(fEditor);
+
+ fFindReferencesInWorkingSetAction= new FindReferencesInWorkingSetAction(fEditor);
fFindReferencesInWorkingSetAction.setText("Working Set...");
fFindReferencesInWorkingSetAction.setActionDefinitionId(".SEARCH_REFERENCES_IN_WORKING_SET");
//fEditor.setAction("SearchReferencesInWorkingSet", fFindReferencesInWorkingSetAction); //$NON-NLS-1$