Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
blob: 4c710efa1790a749fff475206c73c34fa272175f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
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.editor.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 = "Working Set";    
			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;
	}
}

Back to the top