1
/*******************************************************************************
2
* Copyright (c) 2007, 2009 Wind River Systems, Inc. and others.
3
* All rights reserved. This program and the accompanying materials
4
* are made available under the terms of the Eclipse Public License v1.0
5
* which accompanies this distribution, and is available at
6
* http://www.eclipse.org/legal/epl-v10.html
9
* Markus Schorn - initial API and implementation
10
*******************************************************************************/
11
package org.eclipse.cdt.internal.ui.search.actions;
13
import java.util.ArrayList;
14
import java.util.List;
16
import org.eclipse.core.runtime.IAdaptable;
17
import org.eclipse.jface.window.Window;
18
import org.eclipse.ui.IWorkbenchSite;
19
import org.eclipse.ui.IWorkingSet;
20
import org.eclipse.ui.IWorkingSetManager;
21
import org.eclipse.ui.PlatformUI;
22
import org.eclipse.ui.dialogs.IWorkingSetSelectionDialog;
24
import org.eclipse.cdt.core.model.ICElement;
26
import org.eclipse.cdt.internal.ui.editor.CEditor;
27
import org.eclipse.cdt.internal.ui.search.CSearchMessages;
28
import org.eclipse.cdt.internal.ui.search.CSearchUtil;
29
import org.eclipse.cdt.internal.ui.util.Messages;
31
public abstract class FindInWorkingSetAction extends FindAction {
33
private IWorkingSet[] fWorkingSets;
34
private String scopeDescription = ""; //$NON-NLS-1$
36
public FindInWorkingSetAction(CEditor editor, String label, String tooltip, IWorkingSet[] workingSets) {
39
setToolTipText(tooltip);
40
fWorkingSets = workingSets;
43
public FindInWorkingSetAction(IWorkbenchSite site, String label, String tooltip, IWorkingSet[] workingSets){
46
setToolTipText(tooltip);
47
fWorkingSets= workingSets;
51
final public void run() {
52
IWorkingSet[] initial= fWorkingSets;
53
if (fWorkingSets == null) {
54
fWorkingSets= askForWorkingSets();
56
if (fWorkingSets != null) {
57
scopeDescription = Messages.format(CSearchMessages.WorkingSetScope, CSearchUtil.toString(fWorkingSets));
60
fWorkingSets= initial;
64
final protected String getScopeDescription() {
65
return scopeDescription;
69
final protected ICElement[] getScope() {
70
if (fWorkingSets == null) {
71
return new ICElement[0];
73
List<ICElement> scope = new ArrayList<ICElement>();
74
for (int i = 0; i < fWorkingSets.length; ++i) {
75
IAdaptable[] elements = fWorkingSets[i].getElements();
76
for (int j = 0; j < elements.length; ++j) {
77
ICElement element = (ICElement)elements[j].getAdapter(ICElement.class);
83
return scope.toArray(new ICElement[scope.size()]);
86
private IWorkingSet[] askForWorkingSets() {
87
IWorkingSetManager wsm= PlatformUI.getWorkbench().getWorkingSetManager();
88
IWorkingSetSelectionDialog dlg=
89
wsm.createWorkingSetSelectionDialog(getSite().getShell(), true);
90
IWorkingSet[] mru= wsm.getRecentWorkingSets();
91
if (mru != null && mru.length > 0) {
92
dlg.setSelection(new IWorkingSet[] {mru[0]});
94
if (dlg.open() == Window.OK) {
95
mru= dlg.getSelection();
96
if (mru != null && mru.length == 1) {
97
wsm.addRecentWorkingSet(mru[0]);