001: /*******************************************************************************
002: * Copyright (c) 2000, 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.jdt.ui.actions;
011:
012: import org.eclipse.ui.IWorkbenchSite;
013: import org.eclipse.ui.IWorkingSet;
014: import org.eclipse.ui.PlatformUI;
015:
016: import org.eclipse.jdt.core.IJavaElement;
017: import org.eclipse.jdt.core.JavaModelException;
018: import org.eclipse.jdt.core.search.IJavaSearchScope;
019:
020: import org.eclipse.jdt.ui.search.ElementQuerySpecification;
021: import org.eclipse.jdt.ui.search.QuerySpecification;
022:
023: import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
024: import org.eclipse.jdt.internal.ui.JavaPluginImages;
025: import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor;
026: import org.eclipse.jdt.internal.ui.search.JavaSearchScopeFactory;
027: import org.eclipse.jdt.internal.ui.search.SearchMessages;
028: import org.eclipse.jdt.internal.ui.search.SearchUtil;
029:
030: /**
031: * Finds declarations of the selected element in working sets.
032: * The action is applicable to selections representing a Java element.
033: *
034: * <p>
035: * This class may be instantiated; it is not intended to be subclassed.
036: * </p>
037: *
038: * @since 2.0
039: */
040: public class FindDeclarationsInWorkingSetAction extends
041: FindDeclarationsAction {
042:
043: private IWorkingSet[] fWorkingSet;
044:
045: /**
046: * Creates a new <code>FindDeclarationsInWorkingSetAction</code>. The action
047: * requires that the selection provided by the site's selection provider is of type
048: * <code>org.eclipse.jface.viewers.IStructuredSelection</code>. The user will be
049: * prompted to select the working sets.
050: *
051: * @param site the site providing context information for this action
052: */
053: public FindDeclarationsInWorkingSetAction(IWorkbenchSite site) {
054: this (site, null);
055: }
056:
057: /**
058: * Creates a new <code>FindDeclarationsInWorkingSetAction</code>. The action
059: * requires that the selection provided by the site's selection provider is of type
060: * <code>org.eclipse.jface.viewers.IStructuredSelection</code>.
061: *
062: * @param site the site providing context information for this action
063: * @param workingSets the working sets to be used in the search
064: */
065: public FindDeclarationsInWorkingSetAction(IWorkbenchSite site,
066: IWorkingSet[] workingSets) {
067: super (site);
068: fWorkingSet = workingSets;
069: }
070:
071: /**
072: * Note: This constructor is for internal use only. Clients should not call this constructor.
073: * @param editor the Java editor
074: */
075: public FindDeclarationsInWorkingSetAction(JavaEditor editor) {
076: this (editor, null);
077: }
078:
079: /**
080: * Note: This constructor is for internal use only. Clients should not call this constructor.
081: *
082: * @param editor the Java editor
083: * @param workingSets the working sets to be used in the search
084: */
085: public FindDeclarationsInWorkingSetAction(JavaEditor editor,
086: IWorkingSet[] workingSets) {
087: super (editor);
088: fWorkingSet = workingSets;
089: }
090:
091: void init() {
092: setText(SearchMessages.Search_FindDeclarationsInWorkingSetAction_label);
093: setToolTipText(SearchMessages.Search_FindDeclarationsInWorkingSetAction_tooltip);
094: setImageDescriptor(JavaPluginImages.DESC_OBJS_SEARCH_DECL);
095: PlatformUI
096: .getWorkbench()
097: .getHelpSystem()
098: .setHelp(
099: this ,
100: IJavaHelpContextIds.FIND_DECLARATIONS_IN_WORKING_SET_ACTION);
101: }
102:
103: QuerySpecification createQuery(IJavaElement element)
104: throws JavaModelException, InterruptedException {
105: JavaSearchScopeFactory factory = JavaSearchScopeFactory
106: .getInstance();
107:
108: IWorkingSet[] workingSets = fWorkingSet;
109: if (fWorkingSet == null) {
110: workingSets = factory.queryWorkingSets();
111: if (workingSets == null)
112: return null;
113: }
114: SearchUtil.updateLRUWorkingSets(workingSets);
115: IJavaSearchScope scope = factory.createJavaSearchScope(
116: workingSets, true);
117: String description = factory.getWorkingSetScopeDescription(
118: workingSets, true);
119: return new ElementQuerySpecification(element, getLimitTo(),
120: scope, description);
121: }
122:
123: }
|