Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: afd006b2d802e791cd8acb20bc033ff534d3febe (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
/*******************************************************************************
 *  Copyright (c) 2011, 2012 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:
 *     Sascha Becher <s.becher@qualitype.de> - bug 360894
 *******************************************************************************/
package org.eclipse.pde.internal.ui.editor.actions;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.viewers.*;
import org.eclipse.pde.internal.core.search.PluginSearchInput;
import org.eclipse.pde.internal.core.search.PluginSearchScope;
import org.eclipse.pde.internal.ui.PDEPluginImages;
import org.eclipse.pde.internal.ui.editor.plugin.FormFilteredTree;
import org.eclipse.pde.internal.ui.search.FindExtensionsByAttributeQuery;
import org.eclipse.pde.internal.ui.util.ExtensionsFilterUtil;
import org.eclipse.search.ui.ISearchQuery;
import org.eclipse.search.ui.NewSearchUI;

/**
 * Search in workspace plugins for occurences of either the current filter text or filter related attributes
 * using the ExtensionsPatternFilter search behaviour.
 * 
 * @author Sascha Becher
 */
public class SearchExtensionsAction extends Action {

	private FormFilteredTree fFilteredTree;
	private boolean fUseCurrentFilter;

	/**
	 * @param filteredTree the extensions section tree
	 * @param actionText description
	 * @param useCurrentFilter when <code>true</code> the search is performed with the current filtering applied to the tree, 
	 *        otherwise the filter text is generated from the current selection 
	 */
	public SearchExtensionsAction(FormFilteredTree filteredTree, String actionText, boolean useCurrentFilter) {
		setImageDescriptor(PDEPluginImages.DESC_SEARCH_EXTENSIONS);
		setDisabledImageDescriptor(PDEPluginImages.DESC_SEARCH_EXTENSIONS_DISABLED);
		setText(actionText);
		fFilteredTree = filteredTree;
		fUseCurrentFilter = useCurrentFilter;
	}

	public void run() {
		NewSearchUI.activateSearchResultView();
		NewSearchUI.runQueryInBackground(createSearchQuery());
	}

	protected ISearchQuery createSearchQuery() {
		PluginSearchInput input = new PluginSearchInput();
		input.setSearchElement(PluginSearchInput.ELEMENT_PLUGIN);
		input.setSearchLimit(PluginSearchInput.LIMIT_ALL);
		input.setSearchString(getFilterText());
		input.setSearchScope(new PluginSearchScope(PluginSearchScope.SCOPE_WORKSPACE, PluginSearchScope.EXTERNAL_SCOPE_ALL, null));
		input.setCaseSensitive(false);
		return new FindExtensionsByAttributeQuery(input);
	}

	private String getFilterText() {
		if (fFilteredTree != null) {
			if (fUseCurrentFilter && fFilteredTree.isFiltered()) {
				return fFilteredTree.getFilterControl().getText();
			}
			return ExtensionsFilterUtil.getFilterRelatedPattern(getSelection());
		}
		return new String();
	}

	private IStructuredSelection getSelection() {
		if (fFilteredTree != null && fFilteredTree.getViewer() != null) {
			ISelection selection = fFilteredTree.getViewer().getSelection();
			if (selection != null && selection instanceof IStructuredSelection) {
				return (IStructuredSelection) selection;
			}
		}
		return new StructuredSelection();
	}

}

Back to the top